From 14dfa70520ddf06422df1d943c7bd955a23e46bc Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 15 Jan 2016 14:13:25 -0800 Subject: debug-rebuild-ref-tree: Copy HEAD into RefTree HEAD is not part of getRefs(ALL) and must be copied explicitly. This allows `jgit debug-rebuild-ref-tree --enable` to convert an existing repository to use RefTree with a local working tree: mkdir testRepo cd testRepo jgit init jgit debug-rebuild-ref-tree --enable touch a jgit add a jgit commit -m initial Change-Id: I46cbc2611b9ae683ef7319dc46af277925dfaee5 --- .../src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'org.eclipse.jgit.pgm/src/org/eclipse') diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java index 3c7ae9bf9f..fbd4672f28 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java @@ -43,9 +43,11 @@ package org.eclipse.jgit.pgm.debug; +import static org.eclipse.jgit.lib.Constants.HEAD; + +import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.eclipse.jgit.internal.storage.reftree.RefTree; import org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase; @@ -108,7 +110,7 @@ class RebuildRefTree extends TextBuiltin { oldTreeId = ObjectId.zeroId(); } - RefTree tree = rebuild(refDb.getRefs(RefDatabase.ALL)); + RefTree tree = rebuild(refDb); b.setTreeId(tree.writeTree(inserter)); b.setAuthor(new PersonIdent(db)); b.setCommitter(b.getAuthor()); @@ -139,12 +141,19 @@ class RebuildRefTree extends TextBuiltin { } } - private RefTree rebuild(Map refMap) { + private RefTree rebuild(RefDatabase refdb) throws IOException { RefTree tree = RefTree.newEmptyTree(); List cmds = new ArrayList<>(); - for (Ref r : refMap.values()) { + Ref head = refdb.exactRef(HEAD); + if (head != null) { + cmds.add(new org.eclipse.jgit.internal.storage.reftree.Command( + null, + head)); + } + + for (Ref r : refdb.getRefs(RefDatabase.ALL).values()) { if (r.getName().equals(txnCommitted) || r.getName().startsWith(txnNamespace)) { continue; -- cgit v1.2.3