Browse Source

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
stable-4.3
Shawn Pearce 9 years ago
parent
commit
14dfa70520
  1. 17
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java

17
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java

@ -43,9 +43,11 @@
package org.eclipse.jgit.pgm.debug; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.jgit.internal.storage.reftree.RefTree; import org.eclipse.jgit.internal.storage.reftree.RefTree;
import org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase; import org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase;
@ -108,7 +110,7 @@ class RebuildRefTree extends TextBuiltin {
oldTreeId = ObjectId.zeroId(); oldTreeId = ObjectId.zeroId();
} }
RefTree tree = rebuild(refDb.getRefs(RefDatabase.ALL)); RefTree tree = rebuild(refDb);
b.setTreeId(tree.writeTree(inserter)); b.setTreeId(tree.writeTree(inserter));
b.setAuthor(new PersonIdent(db)); b.setAuthor(new PersonIdent(db));
b.setCommitter(b.getAuthor()); 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(); RefTree tree = RefTree.newEmptyTree();
List<org.eclipse.jgit.internal.storage.reftree.Command> cmds List<org.eclipse.jgit.internal.storage.reftree.Command> cmds
= new ArrayList<>(); = 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) if (r.getName().equals(txnCommitted)
|| r.getName().startsWith(txnNamespace)) { || r.getName().startsWith(txnNamespace)) {
continue; continue;

Loading…
Cancel
Save