aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2016-01-15 14:13:25 -0800
committerShawn Pearce <spearce@spearce.org>2016-01-15 14:13:25 -0800
commit14dfa70520ddf06422df1d943c7bd955a23e46bc (patch)
treea613be6d58796e65599270c8526f3fc5a94657e4 /org.eclipse.jgit.pgm
parente1529ced42a0378fdfdf595ec7396247f705e395 (diff)
downloadjgit-14dfa70520ddf06422df1d943c7bd955a23e46bc.tar.gz
jgit-14dfa70520ddf06422df1d943c7bd955a23e46bc.zip
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
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java17
1 files changed, 13 insertions, 4 deletions
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<String, Ref> refMap) {
+ private RefTree rebuild(RefDatabase refdb) throws IOException {
RefTree tree = RefTree.newEmptyTree();
List<org.eclipse.jgit.internal.storage.reftree.Command> 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;