From: Charles O'Farrell <charleso@charleso.org>
To: git@vger.kernel.org
Cc: Charles O'Farrell <charleso@charleso.org>
Subject: [JGIT PATCH v2 3/3] Verbose branch command
Date: Wed, 20 Aug 2008 21:00:41 +1000 [thread overview]
Message-ID: <1219230041-7998-4-git-send-email-charleso@charleso.org> (raw)
In-Reply-To: <1219230041-7998-3-git-send-email-charleso@charleso.org>
Signed-off-by: Charles O'Farrell <charleso@charleso.org>
---
.../src/org/spearce/jgit/pgm/Branch.java | 34 +++++++++++++++----
1 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java
index 7958be4..8123f89 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java
@@ -52,6 +52,7 @@
import org.spearce.jgit.lib.RefComparator;
import org.spearce.jgit.lib.RefUpdate;
import org.spearce.jgit.lib.RefUpdate.Result;
+import org.spearce.jgit.revwalk.RevWalk;
@Command(common = true, usage = "List, create, or delete branches")
class Branch extends TextBuiltin {
@@ -76,15 +77,23 @@
private final Map<String, Ref> printRefs = new LinkedHashMap<String, Ref>();
+ /** Only set for verbose branch listing at-the-moment */
+ private RevWalk rw;
+
+ private int maxNameLength;
+
@Override
protected void run() throws Exception {
if (delete || deleteForce)
delete(deleteForce);
- else
+ else {
+ if (verbose)
+ rw = new RevWalk(db);
list();
+ }
}
- private void list() {
+ private void list() throws Exception {
Map<String, Ref> refs = db.getAllRefs();
Ref head = refs.get(Constants.HEAD);
// This can happen if HEAD is stillborn
@@ -95,7 +104,8 @@ private void list() {
addRefs(refs, Constants.HEADS_PREFIX + '/', !remote);
addRefs(refs, Constants.REMOTES_PREFIX + '/', remote);
for (final Entry<String, Ref> e : printRefs.entrySet()) {
- printHead(e.getKey(), current.equals(e.getValue().getName()));
+ final Ref ref = e.getValue();
+ printHead(e.getKey(), current.equals(ref.getName()), ref);
}
}
}
@@ -106,20 +116,30 @@ private void addRefs(final Map<String, Ref> allRefs, final String prefix,
for (final Ref ref : RefComparator.sort(allRefs.values())) {
final String name = ref.getName();
if (name.startsWith(prefix))
- addRef(name, ref);
+ addRef(name.substring(name.indexOf('/', 5) + 1), ref);
}
}
}
private void addRef(final String name, final Ref ref) {
printRefs.put(name, ref);
+ maxNameLength = Math.max(maxNameLength, name.length());
}
- private void printHead(String ref, boolean isCurrent) {
+ private void printHead(final String ref, final boolean isCurrent,
+ final Ref refObj) throws Exception {
out.print(isCurrent ? '*' : ' ');
out.print(' ');
- ref = ref.substring(ref.indexOf('/', 5) + 1);
- out.println(ref);
+ out.print(ref);
+ if (verbose) {
+ final int spaces = maxNameLength - ref.length() + 1;
+ out.print(String.format("%" + spaces + "s", ""));
+ final ObjectId objectId = refObj.getObjectId();
+ out.print(objectId.toString().substring(0, 7));
+ out.print(' ');
+ out.print(rw.parseCommit(objectId).getShortMessage());
+ }
+ out.println();
}
private void delete(boolean force) throws IOException {
--
1.6.0.2.g2ebc0
prev parent reply other threads:[~2008-08-20 11:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-20 11:00 [JGIT PATCH v2 0/3] Verbase branch command Charles O'Farrell
2008-08-20 11:00 ` [JGIT PATCH v2 1/3] Extract RefComparator to sort collection of Refs Charles O'Farrell
2008-08-20 11:00 ` [JGIT PATCH v2 2/3] Cleanup of Branch command ready for verbose mode Charles O'Farrell
2008-08-20 11:00 ` Charles O'Farrell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219230041-7998-4-git-send-email-charleso@charleso.org \
--to=charleso@charleso.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).