diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-01-23 11:11:06 -0800 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-01-23 11:11:12 -0800 |
commit | 3103abe4e2fe6792a1eb4908726002f6105d09f0 (patch) | |
tree | 1336aeaae86392c792d64d86f8bbf9824620b827 /org.eclipse.jgit.pgm/src | |
parent | 407fe631aec08ec4b0f24462b3fa2cee67a83914 (diff) | |
parent | 36f05a9c27e6961b10df0b65014ffc869f4f8686 (diff) | |
download | jgit-3103abe4e2fe6792a1eb4908726002f6105d09f0.tar.gz jgit-3103abe4e2fe6792a1eb4908726002f6105d09f0.zip |
Merge branch 'ref-abstract'
* ref-abstract:
Optimize RefAdvertiser performance by avoiding sorting
branch: Add -m option to rename a branch
Replace writeSymref with RefUpdate.link
Rewrite reference handling to be abstract and accurate
Create new RefList and RefMap utility types
Change-Id: If43aacf5aa4013edbd0a6e84d84c4f9e94de5be0
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
5 files changed, 64 insertions, 13 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java index 60dbe27acb..7a1dd16043 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java @@ -50,18 +50,19 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.kohsuke.args4j.Argument; -import org.kohsuke.args4j.ExampleMode; -import org.kohsuke.args4j.Option; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefComparator; +import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.pgm.opt.CmdLineParser; import org.eclipse.jgit.revwalk.RevWalk; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.ExampleMode; +import org.kohsuke.args4j.Option; @Command(common = true, usage = "List, create, or delete branches") class Branch extends TextBuiltin { @@ -81,6 +82,9 @@ class Branch extends TextBuiltin { @Option(name = "--create-force", aliases = { "-f" }, usage = "force create branch even exists") private boolean createForce = false; + @Option(name = "-m", usage = "move/rename a branch") + private boolean rename = false; + @Option(name = "--verbose", aliases = { "-v" }, usage = "be verbose") private boolean verbose = false; @@ -102,7 +106,36 @@ class Branch extends TextBuiltin { if (branches.size() > 2) throw die("Too many refs given\n" + new CmdLineParser(this).printExample(ExampleMode.ALL)); - if (branches.size() > 0) { + if (rename) { + String src, dst; + if (branches.size() == 1) { + final Ref head = db.getRef(Constants.HEAD); + if (head != null && head.isSymbolic()) + src = head.getLeaf().getName(); + else + throw die("Cannot rename detached HEAD"); + dst = branches.get(0); + } else { + src = branches.get(0); + final Ref old = db.getRef(src); + if (old == null) + throw die(String.format("%s does not exist", src)); + if (!old.getName().startsWith(Constants.R_HEADS)) + throw die(String.format("%s is not a branch", src)); + src = old.getName(); + dst = branches.get(1); + } + + if (!dst.startsWith(Constants.R_HEADS)) + dst = Constants.R_HEADS + dst; + if (!Repository.isValidRefName(dst)) + throw die(String.format("%s is not a valid ref name", dst)); + + RefRename r = db.renameRef(src, dst); + if (r.rename() != Result.RENAMED) + throw die(String.format("%s cannot be renamed", src)); + + } else if (branches.size() > 0) { String newHead = branches.get(0); String startBranch; if (branches.size() == 2) @@ -143,7 +176,7 @@ class Branch extends TextBuiltin { Ref head = refs.get(Constants.HEAD); // This can happen if HEAD is stillborn if (head != null) { - String current = head.getName(); + String current = head.getLeaf().getName(); if (current.equals(Constants.HEAD)) addRef("(no branch)", head); addRefs(refs, Constants.R_HEADS, !remote); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 10bb357e26..a6c50ff19a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009, Google Inc. + * Copyright (C) 2008-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -164,8 +164,11 @@ class Clone extends AbstractFetchCommand { private void doCheckout(final Ref branch) throws IOException { if (branch == null) throw die("cannot checkout; no HEAD advertised by remote"); - if (!Constants.HEAD.equals(branch.getName())) - db.writeSymref(Constants.HEAD, branch.getName()); + if (!Constants.HEAD.equals(branch.getName())) { + RefUpdate u = db.updateRef(Constants.HEAD); + u.disableRefLog(); + u.link(branch.getName()); + } final Commit commit = db.mapCommit(branch.getObjectId()); final RefUpdate u = db.updateRef(Constants.HEAD); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java index ecaf19bd12..4b5975669f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Log.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2010, Google Inc. * Copyright (C) 2006-2008, Robin Rosenberg <robin.rosenberg@dewire.com> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * and other copyright owners as documented in the project's IP log. @@ -92,7 +93,7 @@ class Log extends RevWalkTextBuiltin { if (list != null) { out.print(" ("); for (Iterator<Ref> i = list.iterator(); i.hasNext(); ) { - out.print(i.next().getOrigName()); + out.print(i.next().getName()); if (i.hasNext()) out.print(" "); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java index 7dbb21c5d5..d34f373db2 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2010, Google Inc. * Copyright (C) 2008, Jonas Fonseca <fonseca@diku.dk> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * and other copyright owners as documented in the project's IP log. @@ -44,21 +45,32 @@ package org.eclipse.jgit.pgm; -import java.util.TreeMap; +import java.util.Map; +import java.util.SortedMap; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.RefComparator; +import org.eclipse.jgit.util.RefMap; class ShowRef extends TextBuiltin { @Override protected void run() throws Exception { - for (final Ref r : new TreeMap<String, Ref>(db.getAllRefs()).values()) { + for (final Ref r : getSortedRefs()) { show(r.getObjectId(), r.getName()); if (r.getPeeledObjectId() != null) show(r.getPeeledObjectId(), r.getName() + "^{}"); } } + private Iterable<Ref> getSortedRefs() { + Map<String, Ref> all = db.getAllRefs(); + if (all instanceof RefMap + || (all instanceof SortedMap && ((SortedMap) all).comparator() == null)) + return all.values(); + return RefComparator.sort(all.values()); + } + private void show(final AnyObjectId id, final String name) { out.print(id.name()); out.print('\t'); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index 50b889849e..0a5f2a0c9a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -63,6 +63,7 @@ import org.eclipse.jgit.lib.Commit; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.LockFile; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.ObjectWriter; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.ProgressMonitor; @@ -303,7 +304,8 @@ class RebuildCommitGraph extends TextBuiltin { } throw new MissingObjectException(id, type); } - refs.put(name, new Ref(Ref.Storage.PACKED, name, id)); + refs.put(name, new ObjectIdRef.Unpeeled(Ref.Storage.PACKED, + name, id)); } } finally { br.close(); |