* Re: [PATCH (GIT-GUI) 0/3] Improve gui blame usability for large repositories
From: Alexander Gavrilov @ 2008-07-18 5:39 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
In-Reply-To: <20080717021623.GC16740@spearce.org>
Hello,
On Thursday 17 July 2008 06:16:23 Shawn O. Pearce wrote:
> Alexander Gavrilov <angavrilov@gmail.com> wrote:
> > Full copy detection can take quite some time on large repositories, which
> > substantially decreases perceived usability of the 'git gui blame' command.
> > This set of patches tries to overcome it by:
> >
> > 1) Allowing the user to disable '-C -C' and/or set the detection threshold.
> >
> > 2) Explicitly killing back-end processes, which don't produce any output
> > during copy detection, and thus normally won't receive SIGPIPE until
> > it is finished. Runaway processes are annoying.
> >
> > 3) To compensate for (1), adding a context menu item to manually invoke
> > blame -C -C -C on a group of lines.
>
> This series is nicely done. Works well on revision.c in git.git,
> where the blame can be costly to compute with full copy detection.
> And getting the incremental from the context menu also works well.
I also thought that it would be useful to be able to specify the line range explicitly,
but couldn't invent a good UI for it. Selecting lines with the mouse also causes a
commit to be selected and recolored in green, and popping up a dialog to request
line numbers seems too lame.
Alexander
^ permalink raw reply
* Re: Git bash - is this MSYS bash or something else?
From: Steffen Prohaska @ 2008-07-18 4:59 UTC (permalink / raw)
To: Lennart Borgman; +Cc: git
In-Reply-To: <487FE830.5000101@gmail.com>
On Jul 18, 2008, at 2:47 AM, Lennart Borgman (gmail) wrote:
> I wonder if the bash.exe that comes with GIT is MSYS bash or a
> rewrite?
It is the MSYS bash.
> Does it follow the usual MSYS bash rules?
What does this mean?
Steffen
^ permalink raw reply
* [PATCH] Enable git rev-list to parse --quiet
From: Nick Andrew @ 2008-07-18 4:05 UTC (permalink / raw)
To: git
Enable git rev-list to parse --quiet
git rev-list never sees the --quiet option because --quiet is
also an option for diff-files.
Example:
$ ./git rev-list --quiet ^HEAD~2 HEAD
1e102bf7c83281944ffd9202a7d35c514e4a5644
3bf0dd1f4e75ee1591169b687ce04dff00ae2e3e
$ echo $?
0
The fix scans the argument list to detect --quiet before passing it
to setup_revisions(). It also arranges to count the number of commits
or objects (whether sent to STDOUT or not) so --quiet can return an
appropriate exit code (1 if there were commits/objects, 0 otherwise).
After fix:
$ ./git rev-list --quiet ^HEAD~2 HEAD
$ echo $?
1
---
builtin-rev-list.c | 28 ++++++++++++++++++++++++----
1 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 8e1720c..e2e5e13 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -52,6 +52,11 @@ static const char rev_list_usage[] =
static struct rev_info revs;
+/* Count of number of commits or objects noticed (even if not output).
+ * Used by --quiet option to set an appropriate exit status.
+ */
+static int seen_count;
+
static int bisect_list;
static int show_timestamp;
static int hdr_termination;
@@ -167,12 +172,14 @@ static void finish_commit(struct commit *commit)
}
free(commit->buffer);
commit->buffer = NULL;
+ seen_count++;
}
static void finish_object(struct object_array_entry *p)
{
if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
+ seen_count++;
}
static void show_object(struct object_array_entry *p)
@@ -588,6 +595,17 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
init_revisions(&revs, prefix);
revs.abbrev = 0;
revs.commit_format = CMIT_FMT_UNSPECIFIED;
+
+ /* Parse options which are also recognised by git-diff-files */
+ for (i = 1 ; i < argc; i++) {
+ const char *arg = argv[i];
+
+ if (!strcmp(arg, "--quiet")) {
+ quiet = 1;
+ continue;
+ }
+ }
+
argc = setup_revisions(argc, argv, &revs, NULL);
for (i = 1 ; i < argc; i++) {
@@ -621,10 +639,6 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
read_revisions_from_stdin(&revs);
continue;
}
- if (!strcmp(arg, "--quiet")) {
- quiet = 1;
- continue;
- }
usage(rev_list_usage);
}
@@ -700,9 +714,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
}
}
+ seen_count = 0;
+
traverse_commit_list(&revs,
quiet ? finish_commit : show_commit,
quiet ? finish_object : show_object);
+ if (quiet) {
+ return seen_count ? 1 : 0;
+ }
+
return 0;
}
^ permalink raw reply related
* Re: git-remote SEGV on t5505 test.
From: Junio C Hamano @ 2008-07-18 4:25 UTC (permalink / raw)
To: SungHyun Nam; +Cc: git
In-Reply-To: <g5osl6$4g3$1@ger.gmane.org>
SungHyun Nam <namsh@posdata.co.kr> writes:
> And the 'skip_prefix()' returns NULL in this case.
> (The old skip_prefix() never returns NULL).
Thanks. Something like this?
builtin-remote.c | 51 +++++++++++++++++++--------------------------------
1 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 1491354..db12668 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -147,6 +147,15 @@ struct branch_info {
static struct path_list branch_list;
+static const char *abbrev_ref(const char *name, const char *prefix)
+{
+ const char *abbrev = skip_prefix(name, prefix);
+ if (abbrev)
+ return abbrev;
+ return name;
+}
+#define abbrev_branch(name) abbrev_ref((name), "refs/heads/")
+
static int config_read_branches(const char *key, const char *value, void *cb)
{
if (!prefixcmp(key, "branch.")) {
@@ -176,18 +185,12 @@ static int config_read_branches(const char *key, const char *value, void *cb)
info->remote = xstrdup(value);
} else {
char *space = strchr(value, ' ');
- const char *ptr = skip_prefix(value, "refs/heads/");
- if (ptr)
- value = ptr;
+ value = abbrev_branch(value);
while (space) {
char *merge;
merge = xstrndup(value, space - value);
path_list_append(merge, &info->merge);
- ptr = skip_prefix(space + 1, "refs/heads/");
- if (ptr)
- value = ptr;
- else
- value = space + 1;
+ value = abbrev_branch(space + 1);
space = strchr(value, ' ');
}
path_list_append(xstrdup(value), &info->merge);
@@ -219,12 +222,7 @@ static int handle_one_branch(const char *refname,
refspec.dst = (char *)refname;
if (!remote_find_tracking(states->remote, &refspec)) {
struct path_list_item *item;
- const char *name, *ptr;
- ptr = skip_prefix(refspec.src, "refs/heads/");
- if (ptr)
- name = ptr;
- else
- name = refspec.src;
+ const char *name = abbrev_branch(refspec.src);
/* symbolic refs pointing nowhere were handled already */
if ((flags & REF_ISSYMREF) ||
unsorted_path_list_has_path(&states->tracked,
@@ -253,7 +251,6 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
struct path_list *target = &states->tracked;
unsigned char sha1[20];
void *util = NULL;
- const char *ptr;
if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
target = &states->new;
@@ -262,10 +259,7 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
if (hashcmp(sha1, ref->new_sha1))
util = &states;
}
- ptr = skip_prefix(ref->name, "refs/heads/");
- if (!ptr)
- ptr = ref->name;
- path_list_append(ptr, target)->util = util;
+ path_list_append(abbrev_branch(ref->name), target)->util = util;
}
free_refs(fetch_map);
@@ -460,10 +454,8 @@ static int append_ref_to_tracked_list(const char *refname,
memset(&refspec, 0, sizeof(refspec));
refspec.dst = (char *)refname;
- if (!remote_find_tracking(states->remote, &refspec)) {
- path_list_append(skip_prefix(refspec.src, "refs/heads/"),
- &states->tracked);
- }
+ if (!remote_find_tracking(states->remote, &refspec))
+ path_list_append(abbrev_branch(refspec.src), &states->tracked);
return 0;
}
@@ -530,15 +522,10 @@ static int show(int argc, const char **argv)
"es" : "");
for (i = 0; i < states.remote->push_refspec_nr; i++) {
struct refspec *spec = states.remote->push + i;
- const char *p = "", *q = "";
- if (spec->src)
- p = skip_prefix(spec->src, "refs/heads/");
- if (spec->dst)
- q = skip_prefix(spec->dst, "refs/heads/");
printf(" %s%s%s%s", spec->force ? "+" : "",
- p ? p : spec->src,
- spec->dst ? ":" : "",
- q ? q : spec->dst);
+ abbrev_branch(spec->src),
+ spec->dst ? ":" : "",
+ spec->dst ? abbrev_branch(spec->dst) : "");
}
printf("\n");
}
@@ -588,7 +575,7 @@ static int prune(int argc, const char **argv)
result |= delete_ref(refname, NULL);
printf(" * [%s] %s\n", dry_run ? "would prune" : "pruned",
- skip_prefix(refname, "refs/remotes/"));
+ abbrev_ref(refname, "refs/remotes/"));
}
/* NEEDSWORK: free remote */
^ permalink raw reply related
* git gc annoyance
From: Mike Laster @ 2008-07-18 3:30 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 412 bytes --]
Whenever I run 'git gc' all of the files in .git/logs/refs/remotes/
tags get touched with the current timestamp.
I use unison to sync my working directories between home and work and
these files show up as changed unnecessarily. Since they are all zero-
byte files
clearly they haven't changed. It would be more efficient to not touch
the file if it already exists to leave the old timestamp in place.
[-- Attachment #2: git_gc_log.txt.gz --]
[-- Type: application/x-gzip, Size: 3819 bytes --]
[-- Attachment #3: Type: text/plain, Size: 1 bytes --]
^ permalink raw reply
* Re: [PATCH] gitk - work around stderr redirection on Cygwin
From: Mark Levedahl @ 2008-07-18 2:41 UTC (permalink / raw)
To: Eric Blake; +Cc: Junio C Hamano, paulus, git
In-Reply-To: <487EC2BB.5050503@byu.net>
Eric Blake wrote:
> Could you point me to the patch? I need to roll the Cygwin git
> release of
> 1.5.6.3 anyway (in part because cygwin has upgraded from perl 5.8 to
> 5.10). This sounds like something worth me including as a vendor patch,
> if it does not get folded into the main repo.
>
The patch is at the top of this thread:
http://article.gmane.org/gmane.comp.version-control.git/85023/match=gitk+work+around+stderr+redirection
(I'll send you a patch against Junio's tree privately as a backup).
Mark
^ permalink raw reply
* git-remote SEGV on t5505 test.
From: SungHyun Nam @ 2008-07-18 1:46 UTC (permalink / raw)
To: git
Hello,
The gdb backtrace said:
(gdb) bt
#0 0xff03455c in strlen () from /usr/lib/libc.so.1
#1 0xff087058 in _doprnt () from /usr/lib/libc.so.1
#2 0xff088c18 in printf () from /usr/lib/libc.so.1
#3 0x0007df20 in prune (argc=1556136, argv=0x139cd0) at
builtin-remote.c:590
The codes in builtin-remote.c:590,
printf(" * [%s] %s\n", dry_run ? "would prune" : "prune",
skip_prefix(refname, "refs/remotes/"));
And the 'skip_prefix()' returns NULL in this case.
(The old skip_prefix() never returns NULL).
It seems there is another place need to be checked:
builtin-remote.c:464 : can pass NULL to the strdup().
Regards,
namsh
^ permalink raw reply
* [JGIT PATCH 26/28] Convert tag program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-26-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Tag.java | 79 ++++++++------------
1 files changed, 32 insertions(+), 47 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Tag.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Tag.java
index d59616b..a7bd037 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Tag.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Tag.java
@@ -37,48 +37,35 @@
package org.spearce.jgit.pgm;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
+import org.spearce.jgit.errors.MissingObjectException;
import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.ObjectLoader;
import org.spearce.jgit.lib.PersonIdent;
class Tag extends TextBuiltin {
+ @Option(name = "-f", usage = "force replacing an existing tag")
+ private boolean force;
+
+ @Option(name = "-m", metaVar = "message", usage = "tag message")
+ private String message = "";
+
+ @Argument(index = 0, required = true, metaVar = "name")
+ private String tagName;
+
+ @Argument(index = 1, metaVar = "object")
+ private ObjectId object;
+
@Override
- public void execute(String[] args) throws Exception {
- String tagName = null;
- String message = null;
- String ref = "HEAD";
- boolean force = false;
- if (args.length == 0)
- usage();
- for (int i = 0; i < args.length; ++i) {
- if (args[i].equals("-f")) {
- force = true;
- continue;
- }
- if (args[i].equals("-m")) {
- if (i < args.length - 2)
- message = args[i++] + "\n";
- else
- usage();
- continue;
- }
- if (args[i].startsWith("-m")) {
- message = args[i].substring(2) + "\n";
- continue;
- }
- if (args[i].startsWith("-") && i == args.length - 1)
- usage();
- if (i == args.length - 2) {
- tagName = args[i];
- ref = args[i+1];
- ++i;
- continue;
- }
- if (i == args.length - 1) {
- tagName = args[i];
- continue;
- }
- usage();
+ protected void run() throws Exception {
+ if (object == null) {
+ object = db.resolve(Constants.HEAD);
+ if (object == null)
+ throw die("Cannot resolve " + Constants.HEAD);
}
+
if (!tagName.startsWith(Constants.TAGS_PREFIX + "/"))
tagName = Constants.TAGS_PREFIX + "/" + tagName;
if (!force && db.resolve(tagName) != null) {
@@ -86,19 +73,17 @@ class Tag extends TextBuiltin {
+ tagName.substring(Constants.TAGS_PREFIX.length() + 1)
+ "' exists");
}
+
+ final ObjectLoader ldr = db.openObject(object);
+ if (ldr == null)
+ throw new MissingObjectException(object, "any");
+
org.spearce.jgit.lib.Tag tag = new org.spearce.jgit.lib.Tag(db);
- tag.setObjId(db.resolve(ref));
- if (message != null) {
- message = message.replaceAll("\r", "");
- tag.setMessage(message);
- tag.setTagger(new PersonIdent(db));
- tag.setType("commit");
- }
+ tag.setObjId(object);
+ tag.setType(Constants.typeString(ldr.getType()));
+ tag.setTagger(new PersonIdent(db));
+ tag.setMessage(message.replaceAll("\r", ""));
tag.setTag(tagName.substring(Constants.TAGS_PREFIX.length() + 1));
tag.tag();
}
-
- private void usage() {
- throw die("Usage: [-m message] [-f] tag [head]");
- }
}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 28/28] Remove support for legacy style TextBuiltins
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-28-git-send-email-spearce@spearce.org>
Now that all builtins use the new automatic parsing support
we want to require that they override run() and do not try
to override execute().
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/TextBuiltin.java | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
index c4a55f4..9f90c16 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
@@ -113,7 +113,7 @@ public abstract class TextBuiltin {
* framework will catch the exception and print a message on
* standard error.
*/
- public void execute(String[] args) throws Exception {
+ public final void execute(String[] args) throws Exception {
parseArguments(args);
run();
}
@@ -166,9 +166,7 @@ public abstract class TextBuiltin {
* framework will catch the exception and print a message on
* standard error.
*/
- protected void run() throws Exception {
- throw die("Override either execute (legacy) or run (new style).");
- }
+ protected abstract void run() throws Exception;
/**
* @return the repository this command accesses.
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 27/28] Convert rev-list, log, glog programs to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-27-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/pgm/RevWalkTextBuiltin.java | 146 +++++++++++---------
1 files changed, 80 insertions(+), 66 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RevWalkTextBuiltin.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RevWalkTextBuiltin.java
index 2aba3c5..97fe7a4 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RevWalkTextBuiltin.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/RevWalkTextBuiltin.java
@@ -41,9 +41,14 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.pgm.opt.PathTreeFilterHandler;
import org.spearce.jgit.revwalk.ObjectWalk;
import org.spearce.jgit.revwalk.RevCommit;
+import org.spearce.jgit.revwalk.RevFlag;
import org.spearce.jgit.revwalk.RevObject;
import org.spearce.jgit.revwalk.RevSort;
import org.spearce.jgit.revwalk.RevWalk;
@@ -53,98 +58,105 @@ import org.spearce.jgit.revwalk.filter.CommitterRevFilter;
import org.spearce.jgit.revwalk.filter.MessageRevFilter;
import org.spearce.jgit.revwalk.filter.RevFilter;
import org.spearce.jgit.treewalk.filter.AndTreeFilter;
-import org.spearce.jgit.treewalk.filter.PathFilter;
-import org.spearce.jgit.treewalk.filter.PathFilterGroup;
import org.spearce.jgit.treewalk.filter.TreeFilter;
abstract class RevWalkTextBuiltin extends TextBuiltin {
RevWalk walk;
+ @Option(name = "--objects")
boolean objects = false;
+ @Option(name = "--parents")
boolean parents = false;
+ @Option(name = "--total-count")
boolean count = false;
char[] outbuffer = new char[Constants.OBJECT_ID_LENGTH * 2];
- @Override
- public final void execute(String[] args) throws Exception {
- final EnumSet<RevSort> sorting = EnumSet.noneOf(RevSort.class);
- final List<String> argList = new ArrayList<String>();
- final List<RevFilter> revLimiter = new ArrayList<RevFilter>();
- List<PathFilter> pathLimiter = null;
- for (final String a : args) {
- if (pathLimiter != null)
- pathLimiter.add(PathFilter.create(a));
- else if ("--".equals(a))
- pathLimiter = new ArrayList<PathFilter>();
- else if (a.startsWith("--author="))
- revLimiter.add(AuthorRevFilter.create(a.substring("--author="
- .length())));
- else if (a.startsWith("--committer="))
- revLimiter.add(CommitterRevFilter.create(a
- .substring("--committer=".length())));
- else if (a.startsWith("--grep="))
- revLimiter.add(MessageRevFilter.create(a.substring("--grep="
- .length())));
- else if ("--objects".equals(a))
- objects = true;
- else if ("--date-order".equals(a))
- sorting.add(RevSort.COMMIT_TIME_DESC);
- else if ("--topo-order".equals(a))
- sorting.add(RevSort.TOPO);
- else if ("--reverse".equals(a))
- sorting.add(RevSort.REVERSE);
- else if ("--boundary".equals(a))
- sorting.add(RevSort.BOUNDARY);
- else if ("--parents".equals(a))
- parents = true;
- else if ("--total-count".equals(a))
- count = true;
- else
- argList.add(a);
- }
+ private final EnumSet<RevSort> sorting = EnumSet.noneOf(RevSort.class);
+
+ private void enableRevSort(final RevSort type, final boolean on) {
+ if (on)
+ sorting.add(type);
+ else
+ sorting.remove(type);
+ }
+
+ @Option(name = "--date-order")
+ void enableDateOrder(final boolean on) {
+ enableRevSort(RevSort.COMMIT_TIME_DESC, on);
+ }
+
+ @Option(name = "--topo-order")
+ void enableTopoOrder(final boolean on) {
+ enableRevSort(RevSort.TOPO, on);
+ }
+
+ @Option(name = "--reverse")
+ void enableReverse(final boolean on) {
+ enableRevSort(RevSort.REVERSE, on);
+ }
+
+ @Option(name = "--boundary")
+ void enableBoundary(final boolean on) {
+ enableRevSort(RevSort.BOUNDARY, on);
+ }
+
+ @Argument(index = 0, metaVar = "commit-ish")
+ private final List<RevCommit> commits = new ArrayList<RevCommit>();
+
+ @Option(name = "--", metaVar = "path", multiValued = true, handler = PathTreeFilterHandler.class)
+ private TreeFilter pathFilter = TreeFilter.ALL;
+
+ private final List<RevFilter> revLimiter = new ArrayList<RevFilter>();
+ @Option(name = "--author")
+ void addAuthorRevFilter(final String who) {
+ revLimiter.add(AuthorRevFilter.create(who));
+ }
+
+ @Option(name = "--committer")
+ void addCommitterRevFilter(final String who) {
+ revLimiter.add(CommitterRevFilter.create(who));
+ }
+
+ @Option(name = "--grep")
+ void addCMessageRevFilter(final String msg) {
+ revLimiter.add(MessageRevFilter.create(msg));
+ }
+
+ @Override
+ protected void run() throws Exception {
walk = createWalk();
for (final RevSort s : sorting)
walk.sort(s, true);
- if (pathLimiter != null && !pathLimiter.isEmpty())
- walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup
- .create(pathLimiter), TreeFilter.ANY_DIFF));
+ if (pathFilter != TreeFilter.ALL)
+ walk.setTreeFilter(AndTreeFilter.create(pathFilter,
+ TreeFilter.ANY_DIFF));
if (revLimiter.size() == 1)
walk.setRevFilter(revLimiter.get(0));
else if (revLimiter.size() > 1)
walk.setRevFilter(AndRevFilter.create(revLimiter));
- final long start = System.currentTimeMillis();
- boolean have_revision = false;
- boolean not = false;
- for (String a : argList) {
- if ("--not".equals(a)) {
- not = true;
- continue;
- }
- boolean menot = false;
- if (a.startsWith("^")) {
- a = a.substring(1);
- menot = true;
- }
- final RevCommit c = walk.parseCommit(resolve(a));
- if (not ^ menot)
- walk.markUninteresting(c);
- else {
+ if (commits.isEmpty()) {
+ final ObjectId head = db.resolve(Constants.HEAD);
+ if (head == null)
+ throw die("Cannot resolve " + Constants.HEAD);
+ commits.add(walk.parseCommit(head));
+ }
+ for (final RevCommit c : commits) {
+ final RevCommit real = argWalk == walk ? c : walk.parseCommit(c);
+ if (c.has(RevFlag.UNINTERESTING))
+ walk.markUninteresting(real);
+ else
walk.markStart(c);
- have_revision = true;
- }
}
- if (!have_revision)
- walk.markStart(walk.parseCommit(resolve("HEAD")));
-
- int n = walkLoop();
+ final long start = System.currentTimeMillis();
+ final int n = walkLoop();
if (count) {
final long end = System.currentTimeMillis();
System.err.print(n);
@@ -158,7 +170,9 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
protected RevWalk createWalk() {
if (objects)
return new ObjectWalk(db);
- return new RevWalk(db);
+ if (argWalk == null)
+ argWalk = new RevWalk(db);
+ return argWalk;
}
protected int walkLoop() throws Exception {
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 24/28] Convert push program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-24-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Push.java | 95 +++++++++-----------
1 files changed, 44 insertions(+), 51 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java
index 5671cc5..df6c664 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java
@@ -37,9 +37,12 @@
package org.spearce.jgit.pgm;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.List;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.Ref;
import org.spearce.jgit.lib.TextProgressMonitor;
import org.spearce.jgit.transport.PushResult;
@@ -49,64 +52,54 @@ import org.spearce.jgit.transport.Transport;
import org.spearce.jgit.transport.RemoteRefUpdate.Status;
class Push extends TextBuiltin {
+ @Argument(index = 0, metaVar = "uri-ish")
+ private String remote = "origin";
+ @Argument(index = 1, metaVar = "refspec")
+ private final List<RefSpec> refSpecs = new ArrayList<RefSpec>();
+
+ @Option(name = "--all")
+ void addAll(final boolean ignored) {
+ refSpecs.add(Transport.REFSPEC_PUSH_ALL);
+ }
+
+ @Option(name = "--tags")
+ void addTags(final boolean ignored) {
+ refSpecs.add(Transport.REFSPEC_TAGS);
+ }
+
+ @Option(name = "--verbose", aliases = { "-v" })
private boolean verbose = false;
+ @Option(name = "--thin")
+ private boolean thin = Transport.DEFAULT_PUSH_THIN;
+
+ @Option(name = "--no-thin")
+ void nothin(final boolean ignored) {
+ thin = false;
+ }
+
+ @Option(name = "--force", aliases = { "-f" })
+ private boolean force;
+
+ @Option(name = "--receive-pack", metaVar = "path")
+ private String receivePack;
+
private boolean first = true;
@Override
- public void execute(String[] args) throws Exception {
- final LinkedList<RefSpec> refSpecs = new LinkedList<RefSpec>();
- Boolean thin = null;
- String exec = null;
- boolean forceAll = false;
-
- int argi = 0;
- for (; argi < args.length; argi++) {
- final String a = args[argi];
- if ("--thin".equals(a))
- thin = true;
- else if ("--no-thin".equals(a))
- thin = false;
- else if ("-f".equals(a) || "--force".equals(a))
- forceAll = true;
- else if (a.startsWith("--exec="))
- exec = a.substring("--exec=".length());
- else if (a.startsWith("--receive-pack="))
- exec = a.substring("--receive-pack=".length());
- else if ("--tags".equals(a))
- refSpecs.add(Transport.REFSPEC_TAGS);
- else if ("--all".equals(a))
- refSpecs.add(Transport.REFSPEC_PUSH_ALL);
- else if ("-v".equals(a))
- verbose = true;
- else if ("--".equals(a)) {
- argi++;
- break;
- } else if (a.startsWith("-"))
- die("usage: push [--all] [--tags] [--force] [--thin]\n"
- + "[--receive-pack=<git-receive-pack>] [<repository> [<refspec>]...]");
- else
- break;
+ protected void run() throws Exception {
+ if (force) {
+ final List<RefSpec> orig = new ArrayList<RefSpec>(refSpecs);
+ refSpecs.clear();
+ for (final RefSpec spec : orig)
+ refSpecs.add(spec.setForceUpdate(true));
}
- final String repository;
- if (argi == args.length)
- repository = "origin";
- else
- repository = args[argi++];
- final Transport transport = Transport.open(db, repository);
- if (thin != null)
- transport.setPushThin(thin);
- if (exec != null)
- transport.setOptionReceivePack(exec);
-
- for (; argi < args.length; argi++) {
- RefSpec spec = new RefSpec(args[argi]);
- if (forceAll)
- spec = spec.setForceUpdate(true);
- refSpecs.add(spec);
- }
+ final Transport transport = Transport.open(db, remote);
+ transport.setPushThin(thin);
+ if (receivePack != null)
+ transport.setOptionReceivePack(receivePack);
final Collection<RemoteRefUpdate> toPush = transport
.findRemoteRefUpdatesFor(refSpecs);
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 25/28] Convert show-ref program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-25-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/ShowRef.java | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/ShowRef.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/ShowRef.java
index 576e342..6dfba3e 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/ShowRef.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/ShowRef.java
@@ -44,7 +44,7 @@ import org.spearce.jgit.lib.Ref;
class ShowRef extends TextBuiltin {
@Override
- public void execute(String[] args) throws Exception {
+ protected void run() throws Exception {
for (final Ref r : new TreeMap<String, Ref>(db.getAllRefs()).values()) {
show(r.getObjectId(), r.getName());
if (r.getPeeledObjectId() != null)
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 23/28] Convert merge-base program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-23-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/MergeBase.java | 37 ++++++++++++--------
1 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/MergeBase.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/MergeBase.java
index c1648a0..c0ddd3b 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/MergeBase.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/MergeBase.java
@@ -37,27 +37,34 @@
package org.spearce.jgit.pgm;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.revwalk.RevCommit;
-import org.spearce.jgit.revwalk.RevWalk;
import org.spearce.jgit.revwalk.filter.RevFilter;
class MergeBase extends TextBuiltin {
- @Override
- public void execute(final String[] args) throws Exception {
- final RevWalk walk = new RevWalk(db);
- int max = 1;
- for (final String a : args) {
- if ("--".equals(a))
- break;
- else if ("--all".equals(a))
- max = Integer.MAX_VALUE;
- else
- walk.markStart(walk.parseCommit(resolve(a)));
- }
+ @Option(name = "--all", usage = "display all possible merge bases")
+ private boolean all;
- walk.setRevFilter(RevFilter.MERGE_BASE);
+ @Argument(index = 0, metaVar = "commit-ish", required = true)
+ void commit_0(final RevCommit c) {
+ commits.add(c);
+ }
+
+ @Argument(index = 1, metaVar = "commit-ish", required = true)
+ private final List<RevCommit> commits = new ArrayList<RevCommit>();
+
+ @Override
+ protected void run() throws Exception {
+ for (final RevCommit c : commits)
+ argWalk.markStart(c);
+ argWalk.setRevFilter(RevFilter.MERGE_BASE);
+ int max = all ? Integer.MAX_VALUE : 1;
while (max-- > 0) {
- final RevCommit b = walk.next();
+ final RevCommit b = argWalk.next();
if (b == null)
break;
out.println(b.getId());
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 22/28] Convert ls-tree program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-22-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/LsTree.java | 42 ++++++--------------
1 files changed, 12 insertions(+), 30 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java
index a0a7216..8d4937f 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsTree.java
@@ -37,40 +37,26 @@
package org.spearce.jgit.pgm;
-import java.io.File;
-
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.Constants;
import org.spearce.jgit.lib.FileMode;
-import org.spearce.jgit.treewalk.FileTreeIterator;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
import org.spearce.jgit.treewalk.TreeWalk;
class LsTree extends TextBuiltin {
- @Override
- public void execute(final String[] args) throws Exception {
- final TreeWalk walk = new TreeWalk(db);
- int argi = 0;
- for (; argi < args.length; argi++) {
- final String a = args[argi];
- if ("--".equals(a)) {
- argi++;
- break;
- } else if ("-r".equals(a))
- walk.setRecursive(true);
- else
- break;
- }
+ @Option(name = "--recursive", usage = "recurse into subtrees", aliases = { "-r" })
+ private boolean recursive;
- if (argi == args.length)
- throw die("usage: [-r] treename");
- else if (argi + 1 < args.length)
- throw die("too many arguments");
+ @Argument(index = 0, required = true, metaVar = "tree-ish")
+ private AbstractTreeIterator tree;
+ @Override
+ protected void run() throws Exception {
+ final TreeWalk walk = new TreeWalk(db);
walk.reset(); // drop the first empty tree, which we do not need here
- final String n = args[argi];
- if (is_WorkDir(n))
- walk.addTree(new FileTreeIterator(new File(n)));
- else
- walk.addTree(resolve(n));
+ walk.setRecursive(recursive);
+ walk.addTree(tree);
while (walk.next()) {
final FileMode mode = walk.getFileMode(0);
@@ -88,8 +74,4 @@ class LsTree extends TextBuiltin {
out.println();
}
}
-
- private boolean is_WorkDir(final String name) {
- return new File(name).isDirectory();
- }
}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 21/28] Convert ls-remote program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-21-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/LsRemote.java | 23 +++++--------------
1 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsRemote.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsRemote.java
index 921bcff..391a04d 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsRemote.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/LsRemote.java
@@ -37,30 +37,19 @@
package org.spearce.jgit.pgm;
+import org.kohsuke.args4j.Argument;
import org.spearce.jgit.lib.AnyObjectId;
import org.spearce.jgit.lib.Ref;
import org.spearce.jgit.transport.FetchConnection;
import org.spearce.jgit.transport.Transport;
class LsRemote extends TextBuiltin {
- @Override
- public void execute(final String[] args) throws Exception {
- int argi = 0;
- for (; argi < args.length; argi++) {
- final String a = args[argi];
- if ("--".equals(a)) {
- argi++;
- break;
- } else
- break;
- }
+ @Argument(index = 0, metaVar = "uri-ish", required = true)
+ private String remote;
- if (argi == args.length)
- throw die("usage: url");
- else if (argi + 1 < args.length)
- throw die("too many arguments");
-
- final Transport tn = Transport.open(db, args[argi]);
+ @Override
+ protected void run() throws Exception {
+ final Transport tn = Transport.open(db, remote);
final FetchConnection c = tn.openFetch();
try {
for (final Ref r : c.getRefs()) {
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 20/28] Convert index-pack program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-20-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/IndexPack.java | 35 +++++++-------------
1 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/IndexPack.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/IndexPack.java
index 5f4134d..5eacaa4 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/IndexPack.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/IndexPack.java
@@ -40,39 +40,28 @@ package org.spearce.jgit.pgm;
import java.io.BufferedInputStream;
import java.io.File;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.TextProgressMonitor;
class IndexPack extends TextBuiltin {
- @Override
- public void execute(final String[] args) throws Exception {
- boolean fixThin = false;
- int argi = 0;
- int version = 0;
- for (; argi < args.length; argi++) {
- final String a = args[argi];
- if ("--fix-thin".equals(a))
- fixThin = true;
- else if (a.startsWith("--index-version="))
- version = Integer.parseInt(a.substring(a.indexOf('=') + 1));
- else if ("--".equals(a)) {
- argi++;
- break;
- } else
- break;
- }
+ @Option(name = "--fix-thin", usage = "fix a thin pack to be complete")
+ private boolean fixThin;
+
+ @Option(name = "--index-version", usage = "index file format to create")
+ private int indexVersion;
- if (argi == args.length)
- throw die("usage: index-pack base");
- else if (argi + 1 < args.length)
- throw die("too many arguments");
+ @Argument(index = 0, required = true, metaVar = "base")
+ private File base;
- final File base = new File(args[argi]);
+ @Override
+ protected void run() throws Exception {
final BufferedInputStream in;
final org.spearce.jgit.transport.IndexPack ip;
in = new BufferedInputStream(System.in);
ip = new org.spearce.jgit.transport.IndexPack(db, in, base);
ip.setFixThin(fixThin);
- ip.setIndexVersion(version);
+ ip.setIndexVersion(indexVersion);
ip.index(new TextProgressMonitor());
}
}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 16/28] Convert jgit's Main to use args4j for basic parsing services
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-16-git-send-email-spearce@spearce.org>
We now use args4j for our global options parsing and for the
subcommand selection. The remaining arguments that are left
over after the subcommand are sent to the subcommand unmodified.
An additional CmdLineParser could be created by the subcommand to
handle its own argument parsing over the remaining options.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Main.java | 111 ++++++---------
.../src/org/spearce/jgit/pgm/TextBuiltin.java | 19 +++
.../spearce/jgit/pgm/opt/SubcommandHandler.java | 149 ++++++++++++++++++++
3 files changed, 214 insertions(+), 65 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/SubcommandHandler.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Main.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Main.java
index 68748bf..c069989 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Main.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Main.java
@@ -39,8 +39,13 @@
package org.spearce.jgit.pgm;
import java.io.File;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.ExampleMode;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.awtui.AwtAuthenticator;
import org.spearce.jgit.errors.TransportException;
import org.spearce.jgit.lib.Repository;
@@ -50,7 +55,20 @@ import org.spearce.jgit.util.HttpSupport;
/** Command line entry point. */
public class Main {
- private static boolean showStackTrace;
+ @Option(name = "--help", usage = "display this help text", aliases = { "-h" })
+ private boolean help;
+
+ @Option(name = "--show-stack-trace", usage = "display the Java stack trace on exceptions")
+ private boolean showStackTrace;
+
+ @Option(name = "--git-dir", metaVar = "GIT_DIR", usage = "set the git repository to operate on")
+ private File gitdir;
+
+ @Argument(index = 0, metaVar = "command", required = true, handler = SubcommandHandler.class)
+ private TextBuiltin subcommand;
+
+ @Argument(index = 1, metaVar = "ARG")
+ private List<String> arguments = new ArrayList<String>();
/**
* Execute the command line.
@@ -59,23 +77,24 @@ public class Main {
* arguments.
*/
public static void main(final String[] argv) {
+ final Main me = new Main();
try {
AwtAuthenticator.install();
HttpSupport.configureHttpProxy();
- execute(argv);
+ me.execute(argv);
} catch (Die err) {
System.err.println("fatal: " + err.getMessage());
- if (showStackTrace)
+ if (me.showStackTrace)
err.printStackTrace();
System.exit(128);
} catch (Exception err) {
- if (!showStackTrace && err.getCause() != null
+ if (!me.showStackTrace && err.getCause() != null
&& err instanceof TransportException)
System.err.println("fatal: " + err.getCause().getMessage());
if (err.getClass().getName().startsWith("org.spearce.jgit.errors.")) {
System.err.println("fatal: " + err.getMessage());
- if (showStackTrace)
+ if (me.showStackTrace)
err.printStackTrace();
System.exit(128);
}
@@ -84,24 +103,28 @@ public class Main {
}
}
- private static void execute(final String[] argv) throws Exception {
- int argi = 0;
+ private void execute(final String[] argv) throws Exception {
+ final CmdLineParser clp = new CmdLineParser(this);
+ try {
+ clp.parseArgument(argv);
+ } catch (CmdLineException err) {
+ if (argv.length > 0 && !help) {
+ System.err.println("fatal: " + err.getMessage());
+ System.exit(1);
+ }
+ }
- File gitdir = null;
- for (; argi < argv.length; argi++) {
- final String arg = argv[argi];
- if (arg.startsWith("--git-dir="))
- gitdir = new File(arg.substring("--git-dir=".length()));
- else if (arg.equals("--show-stack-trace"))
- showStackTrace = true;
- else if (arg.startsWith("--"))
- usage();
- else
- break;
+ if (argv.length == 0 || help) {
+ final String ex = clp.printExample(ExampleMode.ALL);
+ System.err.println("jgit" + ex + " command [ARG ...]");
+ if (help) {
+ System.err.println();
+ clp.printUsage(System.err);
+ System.err.println();
+ }
+ System.exit(1);
}
- if (argi == argv.length)
- usage();
if (gitdir == null)
gitdir = findGitDir();
if (gitdir == null || !gitdir.isDirectory()) {
@@ -109,10 +132,10 @@ public class Main {
System.exit(1);
}
- final TextBuiltin cmd = createCommand(argv[argi++]);
+ final TextBuiltin cmd = subcommand;
cmd.init(new Repository(gitdir));
try {
- cmd.execute(subarray(argv, argi));
+ cmd.execute(arguments.toArray(new String[arguments.size()]));
} finally {
if (cmd.out != null)
cmd.out.flush();
@@ -129,46 +152,4 @@ public class Main {
}
return null;
}
-
- private static String[] subarray(final String[] argv, final int i) {
- return Arrays.asList(argv).subList(i, argv.length).toArray(
- new String[0]);
- }
-
- private static TextBuiltin createCommand(final String name) {
- final StringBuilder s = new StringBuilder();
- s.append(mypackage());
- s.append('.');
- boolean upnext = true;
- for (int i = 0; i < name.length(); i++) {
- final char c = name.charAt(i);
- if (c == '-') {
- upnext = true;
- continue;
- }
- if (upnext)
- s.append(Character.toUpperCase(c));
- else
- s.append(c);
- upnext = false;
- }
- try {
- return (TextBuiltin) Class.forName(s.toString()).newInstance();
- } catch (Exception e) {
- System.err.println("error: " + name + " is not a jgit command.");
- System.exit(1);
- return null;
- }
- }
-
- private static String mypackage() {
- final String p = Main.class.getName();
- final int dot = p.lastIndexOf('.');
- return p.substring(0, dot);
- }
-
- private static void usage() {
- System.err.println("jgit [--git-dir=path] cmd ...");
- System.exit(1);
- }
}
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
index 05ad211..0f39f11 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
@@ -65,12 +65,24 @@ public abstract class TextBuiltin {
protected static final String REFS_TAGS = Constants.TAGS_PREFIX + "/";
+ private String commandName;
+
/** Stream to output to, typically this is standard output. */
protected PrintWriter out;
/** Git repository the command was invoked within. */
protected Repository db;
+ /**
+ * Set the name this command can be invoked as on the command line.
+ *
+ * @param name
+ * the name of the command.
+ */
+ public void setCommandName(final String name) {
+ commandName = name;
+ }
+
void init(final Repository repo) {
try {
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
@@ -93,6 +105,13 @@ public abstract class TextBuiltin {
*/
public abstract void execute(String[] args) throws Exception;
+ /**
+ * @return the repository this command accesses.
+ */
+ public Repository getRepository() {
+ return db;
+ }
+
protected ObjectId resolve(final String s) throws IOException {
final ObjectId r = db.resolve(s);
if (r == null)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/SubcommandHandler.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/SubcommandHandler.java
new file mode 100644
index 0000000..2318a03
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/SubcommandHandler.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.pgm.opt;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.spearce.jgit.pgm.Main;
+import org.spearce.jgit.pgm.TextBuiltin;
+
+/**
+ * Custom Argument handler for jgit command selection.
+ * <p>
+ * Translates a single argument string to a {@link TextBuiltin} instance which
+ * we can execute at runtime with the remaining arguments of the parser.
+ */
+public class SubcommandHandler extends OptionHandler<TextBuiltin> {
+ private static String mypackage() {
+ final String p = Main.class.getName();
+ final int dot = p.lastIndexOf('.');
+ return p.substring(0, dot);
+ }
+
+ /**
+ * Create a new handler for the command name.
+ * <p>
+ * This constructor is used only by args4j.
+ *
+ * @param parser
+ * @param option
+ * @param setter
+ */
+ public SubcommandHandler(final CmdLineParser parser,
+ final OptionDef option, final Setter<? super TextBuiltin> setter) {
+ super(parser, option, setter);
+ }
+
+ @Override
+ public int parseArguments(final Parameters params) throws CmdLineException {
+ final String name = params.getParameter(0);
+ final StringBuilder s = new StringBuilder();
+ s.append(mypackage());
+ s.append('.');
+ boolean upnext = true;
+ for (int i = 0; i < name.length(); i++) {
+ final char c = name.charAt(i);
+ if (c == '-') {
+ upnext = true;
+ continue;
+ }
+ if (upnext)
+ s.append(Character.toUpperCase(c));
+ else
+ s.append(c);
+ upnext = false;
+ }
+
+ final Class<?> clazz;
+ try {
+ clazz = Class.forName(s.toString());
+ } catch (ClassNotFoundException e) {
+ throw new CmdLineException(MessageFormat.format(
+ "{0} is not a jgit command", name));
+ }
+
+ if (!TextBuiltin.class.isAssignableFrom(clazz))
+ throw new CmdLineException(MessageFormat.format(
+ "{0} is not a jgit command", name));
+
+ final Constructor<?> cons;
+ try {
+ cons = clazz.getDeclaredConstructor();
+ } catch (SecurityException e) {
+ throw new CmdLineException("Cannot create " + name, e);
+ } catch (NoSuchMethodException e) {
+ throw new CmdLineException("Cannot create " + name, e);
+ }
+ cons.setAccessible(true);
+
+ final TextBuiltin cmd;
+ try {
+ cmd = (TextBuiltin) cons.newInstance();
+ } catch (InstantiationException e) {
+ throw new CmdLineException("Cannot create " + name, e);
+ } catch (IllegalAccessException e) {
+ throw new CmdLineException("Cannot create " + name, e);
+ } catch (InvocationTargetException e) {
+ throw new CmdLineException("Cannot create " + name, e);
+ }
+
+ cmd.setCommandName(name);
+ setter.addValue(cmd);
+
+ // Force option parsing to stop. Everything after us should
+ // be arguments known only to this command and must not be
+ // recognized by the current parser.
+ //
+ owner.stopOptionParsing();
+
+ return 1;
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return "command";
+ }
+}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 18/28] Convert diff-tree program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-18-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/DiffTree.java | 57 ++++++++------------
1 files changed, 23 insertions(+), 34 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/DiffTree.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/DiffTree.java
index 17858ba..b3f6738 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/DiffTree.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/DiffTree.java
@@ -40,50 +40,39 @@ package org.spearce.jgit.pgm;
import java.util.ArrayList;
import java.util.List;
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.FileMode;
+import org.spearce.jgit.pgm.opt.PathTreeFilterHandler;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
import org.spearce.jgit.treewalk.TreeWalk;
import org.spearce.jgit.treewalk.filter.AndTreeFilter;
-import org.spearce.jgit.treewalk.filter.OrTreeFilter;
-import org.spearce.jgit.treewalk.filter.PathFilter;
import org.spearce.jgit.treewalk.filter.TreeFilter;
class DiffTree extends TextBuiltin {
+ @Option(name = "--recursive", usage = "recurse into subtrees", aliases = { "-r" })
+ private boolean recursive;
+
+ @Argument(index = 0, metaVar = "tree-ish", required = true)
+ void tree_0(final AbstractTreeIterator c) {
+ trees.add(c);
+ }
+
+ @Argument(index = 1, metaVar = "tree-ish", required = true)
+ private final List<AbstractTreeIterator> trees = new ArrayList<AbstractTreeIterator>();
+
+ @Option(name = "--", metaVar = "path", multiValued = true, handler = PathTreeFilterHandler.class)
+ private TreeFilter pathFilter = TreeFilter.ALL;
+
@Override
- public void execute(String[] args) throws Exception {
+ protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db);
- final List<String> argList = new ArrayList<String>();
- List<TreeFilter> pathLimiter = null;
- for (final String a : args) {
- if (pathLimiter != null)
- pathLimiter.add(PathFilter.create(a));
- else if ("--".equals(a))
- pathLimiter = new ArrayList<TreeFilter>();
- else if ("-r".equals(a))
- walk.setRecursive(true);
- else
- argList.add(a);
- }
-
- final TreeFilter pathFilter;
- if (pathLimiter == null || pathLimiter.isEmpty())
- pathFilter = TreeFilter.ALL;
- else if (pathLimiter.size() == 1)
- pathFilter = pathLimiter.get(0);
- else
- pathFilter = OrTreeFilter.create(pathLimiter);
+ walk.reset();
+ walk.setRecursive(recursive);
+ for (final AbstractTreeIterator i : trees)
+ walk.addTree(i);
walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
- if (argList.size() == 0)
- argList.add("HEAD");
- if (argList.size() == 1) {
- final String a = argList.get(0);
- argList.clear();
- argList.add(a + "^^{tree}");
- argList.add(a + "^{tree}");
- }
- for (final String a : argList)
- walk.addTree(resolve(a));
-
final int nTree = walk.getTreeCount();
while (walk.next()) {
for (int i = 1; i < nTree; i++)
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 19/28] Convert fetch program to args4j
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-19-git-send-email-spearce@spearce.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Fetch.java | 27 ++++++-------------
1 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Fetch.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Fetch.java
index e5a0dce..194f669 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Fetch.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Fetch.java
@@ -37,9 +37,9 @@
package org.spearce.jgit.pgm;
-import java.util.ArrayList;
import java.util.List;
+import org.kohsuke.args4j.Argument;
import org.spearce.jgit.lib.RefUpdate;
import org.spearce.jgit.lib.TextProgressMonitor;
import org.spearce.jgit.transport.FetchResult;
@@ -48,26 +48,17 @@ import org.spearce.jgit.transport.TrackingRefUpdate;
import org.spearce.jgit.transport.Transport;
class Fetch extends TextBuiltin {
- @Override
- public void execute(String[] args) throws Exception {
- int argi = 0;
- for (; argi < args.length; argi++) {
- final String a = args[argi];
- if ("--".equals(a)) {
- argi++;
- break;
- } else
- break;
- }
- if (args.length == 0)
- args = new String[] { "origin" };
+ @Argument(index = 0, metaVar = "uri-ish")
+ private String remote = "origin";
- final Transport tn = Transport.open(db, args[argi++]);
+ @Argument(index = 1, metaVar = "refspec")
+ private List<RefSpec> toget;
+
+ @Override
+ protected void run() throws Exception {
+ final Transport tn = Transport.open(db, remote);
final FetchResult r;
try {
- final List<RefSpec> toget = new ArrayList<RefSpec>();
- for (; argi < args.length; argi++)
- toget.add(new RefSpec(args[argi]));
r = tn.fetch(new TextProgressMonitor(), toget);
if (r.getTrackingRefUpdates().isEmpty())
return;
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 12/28] Add option handler for RefSpec values
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-12-git-send-email-spearce@spearce.org>
Converts a string into a RefSpec. RefSpec values are popular
on the command line for transport programs like fetch and push.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/pgm/opt/RefSpecHandler.java | 78 ++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RefSpecHandler.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RefSpecHandler.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RefSpecHandler.java
new file mode 100644
index 0000000..959b215
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RefSpecHandler.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.pgm.opt;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.spearce.jgit.transport.RefSpec;
+
+/**
+ * Custom argument handler {@link RefSpec} from string values.
+ * <p>
+ * Assumes the parser has been initialized with a Repository.
+ */
+public class RefSpecHandler extends OptionHandler<RefSpec> {
+ /**
+ * Create a new handler for the command name.
+ * <p>
+ * This constructor is used only by args4j.
+ *
+ * @param parser
+ * @param option
+ * @param setter
+ */
+ public RefSpecHandler(final CmdLineParser parser, final OptionDef option,
+ final Setter<? super RefSpec> setter) {
+ super(parser, option, setter);
+ }
+
+ @Override
+ public int parseArguments(final Parameters params) throws CmdLineException {
+ setter.addValue(new RefSpec(params.getParameter(0)));
+ return 1;
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return "refspec";
+ }
+}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 17/28] Support automatic command line parsing for TextBuiltin subclasses
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-17-git-send-email-spearce@spearce.org>
By default the execute method will parse the supplied arguments
and then invoke run(). Newer style builtins will override the
run method, rather than the execute method, and take advantage of
the standard parsing support.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/TextBuiltin.java | 69 +++++++++++++++++++-
1 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
index 0f39f11..c4a55f4 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/TextBuiltin.java
@@ -43,9 +43,13 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.Constants;
import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.pgm.opt.CmdLineParser;
+import org.spearce.jgit.revwalk.RevWalk;
/**
* Abstract command which can be invoked from the command line.
@@ -67,12 +71,18 @@ public abstract class TextBuiltin {
private String commandName;
+ @Option(name = "--help", usage = "display this help text", aliases = { "-h" })
+ private boolean help;
+
/** Stream to output to, typically this is standard output. */
protected PrintWriter out;
/** Git repository the command was invoked within. */
protected Repository db;
+ /** RevWalk used during command line parsing, if it was required. */
+ protected RevWalk argWalk;
+
/**
* Set the name this command can be invoked as on the command line.
*
@@ -94,7 +104,7 @@ public abstract class TextBuiltin {
}
/**
- * Perform the action(s) of this command.
+ * Parse arguments and run this command.
*
* @param args
* command line arguments passed after the command name.
@@ -103,7 +113,62 @@ public abstract class TextBuiltin {
* framework will catch the exception and print a message on
* standard error.
*/
- public abstract void execute(String[] args) throws Exception;
+ public void execute(String[] args) throws Exception {
+ parseArguments(args);
+ run();
+ }
+
+ /**
+ * Parses the command line arguments prior to running.
+ * <p>
+ * This method should only be invoked by {@link #execute(String[])}, prior
+ * to calling {@link #run()}. The default implementation parses all
+ * arguments into this object's instance fields.
+ *
+ * @param args
+ * the arguments supplied on the command line, if any.
+ */
+ protected void parseArguments(final String[] args) {
+ final CmdLineParser clp = new CmdLineParser(this);
+ try {
+ clp.parseArgument(args);
+ } catch (CmdLineException err) {
+ if (!help) {
+ System.err.println("fatal: " + err.getMessage());
+ System.exit(1);
+ }
+ }
+
+ if (help) {
+ System.err.print("jgit ");
+ System.err.print(commandName);
+ clp.printSingleLineUsage(System.err);
+ System.err.println();
+
+ if (help) {
+ System.err.println();
+ clp.printUsage(System.err);
+ System.err.println();
+ }
+ System.exit(1);
+ }
+
+ argWalk = clp.getRevWalkGently();
+ }
+
+ /**
+ * Perform the actions of this command.
+ * <p>
+ * This method should only be invoked by {@link #execute(String[])}.
+ *
+ * @throws Exception
+ * an error occurred while processing the command. The main
+ * framework will catch the exception and print a message on
+ * standard error.
+ */
+ protected void run() throws Exception {
+ throw die("Override either execute (legacy) or run (new style).");
+ }
/**
* @return the repository this command accesses.
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 15/28] Register most of our OptionHandler implementations for automatic use
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-15-git-send-email-spearce@spearce.org>
Most of these types are common in our command line tools and we
will want to use them over and over again. So we can register
them in our class initializer and be certain they get associated
to an instance member automatically by type.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/pgm/opt/CmdLineParser.java | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/CmdLineParser.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/CmdLineParser.java
index 257d88f..62197e4 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/CmdLineParser.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/CmdLineParser.java
@@ -43,9 +43,14 @@ import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.IllegalAnnotationError;
import org.kohsuke.args4j.Option;
+import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.pgm.TextBuiltin;
+import org.spearce.jgit.revwalk.RevCommit;
+import org.spearce.jgit.revwalk.RevTree;
import org.spearce.jgit.revwalk.RevWalk;
+import org.spearce.jgit.transport.RefSpec;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
/**
* Extended command line parser which handles --foo=value arguments.
@@ -56,6 +61,15 @@ import org.spearce.jgit.revwalk.RevWalk;
* args4j style format prior to invoking args4j for parsing.
*/
public class CmdLineParser extends org.kohsuke.args4j.CmdLineParser {
+ static {
+ registerHandler(AbstractTreeIterator.class,
+ AbstractTreeIteratorHandler.class);
+ registerHandler(ObjectId.class, ObjectIdHandler.class);
+ registerHandler(RefSpec.class, RefSpecHandler.class);
+ registerHandler(RevCommit.class, RevCommitHandler.class);
+ registerHandler(RevTree.class, RevTreeHandler.class);
+ }
+
private final Repository db;
private RevWalk walk;
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 14/28] Add option handler for RevTree values
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-14-git-send-email-spearce@spearce.org>
Converts a String into a RevTree, including parsing the string
with SHA-1 revision syntax and dereferencing through annotated
tags as necessary.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/pgm/opt/RevTreeHandler.java | 109 ++++++++++++++++++++
1 files changed, 109 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevTreeHandler.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevTreeHandler.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevTreeHandler.java
new file mode 100644
index 0000000..eabc08a
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevTreeHandler.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.pgm.opt;
+
+import java.io.IOException;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.errors.MissingObjectException;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.revwalk.RevTree;
+
+/**
+ * Custom argument handler {@link RevTree} from string values.
+ * <p>
+ * Assumes the parser has been initialized with a Repository.
+ */
+public class RevTreeHandler extends OptionHandler<RevTree> {
+ private final org.spearce.jgit.pgm.opt.CmdLineParser clp;
+
+ /**
+ * Create a new handler for the command name.
+ * <p>
+ * This constructor is used only by args4j.
+ *
+ * @param parser
+ * @param option
+ * @param setter
+ */
+ public RevTreeHandler(final CmdLineParser parser, final OptionDef option,
+ final Setter<? super RevTree> setter) {
+ super(parser, option, setter);
+ clp = (org.spearce.jgit.pgm.opt.CmdLineParser) parser;
+ }
+
+ @Override
+ public int parseArguments(final Parameters params) throws CmdLineException {
+ final String name = params.getParameter(0);
+ final ObjectId id;
+ try {
+ id = clp.getRepository().resolve(name);
+ } catch (IOException e) {
+ throw new CmdLineException(e.getMessage());
+ }
+ if (id == null)
+ throw new CmdLineException(name + " is not a tree");
+
+ final RevTree c;
+ try {
+ c = clp.getRevWalk().parseTree(id);
+ } catch (ClassCastException e) {
+ throw new CmdLineException(name + " is not a tree");
+ } catch (MissingObjectException e) {
+ throw new CmdLineException(name + " is not a tree");
+ } catch (IncorrectObjectTypeException e) {
+ throw new CmdLineException(name + " is not a tree");
+ } catch (IOException e) {
+ throw new CmdLineException("cannot read " + name + ": "
+ + e.getMessage());
+ }
+ setter.addValue(c);
+ return 1;
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return "tree-ish";
+ }
+}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 13/28] Add option handler for RevCommit values
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-13-git-send-email-spearce@spearce.org>
Converts a String into a RevCommit, including parsing the string
with SHA-1 revision syntax and dereferencing through annotated
tags as necessary.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/pgm/opt/RevCommitHandler.java | 141 ++++++++++++++++++++
1 files changed, 141 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevCommitHandler.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevCommitHandler.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevCommitHandler.java
new file mode 100644
index 0000000..266e468
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/RevCommitHandler.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.pgm.opt;
+
+import java.io.IOException;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.errors.MissingObjectException;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.revwalk.RevCommit;
+import org.spearce.jgit.revwalk.RevFlag;
+
+/**
+ * Custom argument handler {@link RevCommit} from string values.
+ * <p>
+ * Assumes the parser has been initialized with a Repository.
+ */
+public class RevCommitHandler extends OptionHandler<RevCommit> {
+ private final org.spearce.jgit.pgm.opt.CmdLineParser clp;
+
+ /**
+ * Create a new handler for the command name.
+ * <p>
+ * This constructor is used only by args4j.
+ *
+ * @param parser
+ * @param option
+ * @param setter
+ */
+ public RevCommitHandler(final CmdLineParser parser, final OptionDef option,
+ final Setter<? super RevCommit> setter) {
+ super(parser, option, setter);
+ clp = (org.spearce.jgit.pgm.opt.CmdLineParser) parser;
+ }
+
+ @Override
+ public int parseArguments(final Parameters params) throws CmdLineException {
+ String name = params.getParameter(0);
+
+ boolean interesting = true;
+ if (name.startsWith("^")) {
+ name = name.substring(1);
+ interesting = false;
+ }
+
+ final int dot2 = name.indexOf("..");
+ if (dot2 != -1) {
+ if (!option.isMultiValued())
+ throw new CmdLineException("Only one " + option.metaVar()
+ + " expected in " + name + "." + "");
+
+ final String left = name.substring(0, dot2);
+ final String right = name.substring(dot2 + 2);
+ addOne(left, false);
+ addOne(right, true);
+ return 1;
+ }
+
+ addOne(name, interesting);
+ return 1;
+ }
+
+ private void addOne(final String name, final boolean interesting)
+ throws CmdLineException {
+ final ObjectId id;
+ try {
+ id = clp.getRepository().resolve(name);
+ } catch (IOException e) {
+ throw new CmdLineException(e.getMessage());
+ }
+ if (id == null)
+ throw new CmdLineException(name + " is not a commit");
+
+ final RevCommit c;
+ try {
+ c = clp.getRevWalk().parseCommit(id);
+ } catch (ClassCastException e) {
+ throw new CmdLineException(name + " is not a commit");
+ } catch (MissingObjectException e) {
+ throw new CmdLineException(name + " is not a commit");
+ } catch (IncorrectObjectTypeException e) {
+ throw new CmdLineException(name + " is not a commit");
+ } catch (IOException e) {
+ throw new CmdLineException("cannot read " + name + ": "
+ + e.getMessage());
+ }
+
+ if (interesting)
+ c.remove(RevFlag.UNINTERESTING);
+ else
+ c.add(RevFlag.UNINTERESTING);
+
+ setter.addValue(c);
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return "commit-ish";
+ }
+}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
* [JGIT PATCH 11/28] Add option handler for PathTreeFilter values
From: Shawn O. Pearce @ 2008-07-18 1:44 UTC (permalink / raw)
To: Robin Rosenberg, Marek Zawirski; +Cc: git
In-Reply-To: <1216345461-59382-11-git-send-email-spearce@spearce.org>
Converts one or more Strings, up to the end of the command line,
into a PathFilterGroup. The filter group can be used with a
TreeWalk to limit its results.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../jgit/pgm/opt/PathTreeFilterHandler.java | 102 ++++++++++++++++++++
1 files changed, 102 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/PathTreeFilterHandler.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/PathTreeFilterHandler.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/PathTreeFilterHandler.java
new file mode 100644
index 0000000..8a0b5a6
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/opt/PathTreeFilterHandler.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.pgm.opt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.Option;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+import org.spearce.jgit.treewalk.filter.PathFilter;
+import org.spearce.jgit.treewalk.filter.PathFilterGroup;
+import org.spearce.jgit.treewalk.filter.TreeFilter;
+
+/**
+ * Create a {@link TreeFilter} to patch math names.
+ * <p>
+ * This handler consumes all arguments to the end of the command line, and is
+ * meant to be used on an {@link Option} of name "--".
+ */
+public class PathTreeFilterHandler extends OptionHandler<TreeFilter> {
+ /**
+ * Create a new handler for the command name.
+ * <p>
+ * This constructor is used only by args4j.
+ *
+ * @param parser
+ * @param option
+ * @param setter
+ */
+ public PathTreeFilterHandler(final CmdLineParser parser,
+ final OptionDef option, final Setter<? super TreeFilter> setter) {
+ super(parser, option, setter);
+ }
+
+ @Override
+ public int parseArguments(final Parameters params) throws CmdLineException {
+ final List<PathFilter> filters = new ArrayList<PathFilter>();
+ for (int idx = 0;; idx++) {
+ final String path;
+ try {
+ path = params.getParameter(idx);
+ } catch (CmdLineException cle) {
+ break;
+ }
+ filters.add(PathFilter.create(path));
+ }
+
+ if (filters.size() == 0)
+ return 0;
+ if (filters.size() == 1) {
+ setter.addValue(filters.get(0));
+ return 1;
+ }
+ setter.addValue(PathFilterGroup.create(filters));
+ return filters.size();
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return "path ...";
+ }
+}
--
1.5.6.3.569.ga9185
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox