* [PATCH] git-reset: Let -q hush "locally modified" messages
From: Stephan Beyer @ 2008-07-25 20:49 UTC (permalink / raw)
To: Carlos Rica, Johannes Schindelin; +Cc: git, Stephan Beyer
git reset -q makes reset more quiet, but "locally modified" messages are
still shown. This patch makes them disappear, too.
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
---
Hi,
I don't know if this was actually a bug or a feature.
I considered this a bug, so here's a patch.
Regards,
Stephan
builtin-reset.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin-reset.c b/builtin-reset.c
index 4d246c3..c24c219 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -85,7 +85,7 @@ static void print_new_head_line(struct commit *commit)
printf("\n");
}
-static int update_index_refresh(int fd, struct lock_file *index_lock)
+static int update_index_refresh(int fd, struct lock_file *index_lock, int flags)
{
int result;
@@ -96,7 +96,8 @@ static int update_index_refresh(int fd, struct lock_file *index_lock)
if (read_cache() < 0)
return error("Could not read index");
- result = refresh_cache(REFRESH_SAY_CHANGED) ? 1 : 0;
+
+ result = refresh_cache(flags) ? 1 : 0;
if (write_cache(fd, active_cache, active_nr) ||
commit_locked_index(index_lock))
return error ("Could not refresh index");
@@ -128,7 +129,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
}
static int read_from_tree(const char *prefix, const char **argv,
- unsigned char *tree_sha1)
+ unsigned char *tree_sha1, int refresh_flags)
{
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
int index_fd, index_was_discarded = 0;
@@ -152,7 +153,7 @@ static int read_from_tree(const char *prefix, const char **argv,
if (!index_was_discarded)
/* The index is still clobbered from do_diff_cache() */
discard_cache();
- return update_index_refresh(index_fd, lock);
+ return update_index_refresh(index_fd, lock, refresh_flags);
}
static void prepend_reflog_action(const char *action, char *buf, size_t size)
@@ -246,7 +247,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
else if (reset_type != NONE)
die("Cannot do %s reset with paths.",
reset_type_names[reset_type]);
- return read_from_tree(prefix, argv + i, sha1);
+ return read_from_tree(prefix, argv + i, sha1,
+ quiet ? REFRESH_QUIET : REFRESH_SAY_CHANGED);
}
if (reset_type == NONE)
reset_type = MIXED; /* by default */
@@ -286,7 +288,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
case SOFT: /* Nothing else to do. */
break;
case MIXED: /* Report what has not been updated. */
- update_index_refresh(0, NULL);
+ update_index_refresh(0, NULL,
+ quiet ? REFRESH_QUIET : REFRESH_SAY_CHANGED);
break;
}
--
1.6.0.rc0.49.g3d2ce
^ permalink raw reply related
* Re: [PATCH] bash completion: Add completion for 'git help'
From: Shawn O. Pearce @ 2008-07-25 20:40 UTC (permalink / raw)
To: Lee Marlow; +Cc: git
In-Reply-To: <1216858043-53646-1-git-send-email-lee.marlow@gmail.com>
Lee Marlow <lee.marlow@gmail.com> wrote:
> Renamed cached __git_commandlist to __git_porcelain_commandlist
> and added __git_all_commandlist that only filters out *--* helpers.
> Completions for 'git help' will use the __git_all_commandlist, while
> __git_porcelain_commandlist is used for git command completion.
> Users who actually read man pages may want to see help for plumbing
> commands.
>
> Options added: --all --info --man --web
>
> Signed-off-by: Lee Marlow <lee.marlow@gmail.com>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
> This version fixes a small error in the __git_all_commands
...
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 2edb341..f3bdea4 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -349,10 +349,10 @@ __git_complete_revlist ()
> esac
> }
>
> -__git_commands ()
> +__git_all_commands ()
> {
> - if [ -n "$__git_commandlist" ]; then
> - echo "$__git_commandlist"
> + if [ -n "$__git_all_commandlist" ]; then
> + echo "$__git_all_commandlist"
> return
> fi
> local i IFS=" "$'\n'
> @@ -360,6 +360,24 @@ __git_commands ()
> do
> case $i in
> *--*) : helper pattern;;
> + *) echo $i;;
> + esac
> + done
> +}
> +__git_all_commandlist=
> +__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
> +
> +__git_porcelain_commands ()
> +{
> + if [ -n "$__git_porcelain_commandlist" ]; then
> + echo "$__git_porcelain_commandlist"
> + return
> + fi
> + local i IFS=" "$'\n'
> + for i in "help" $(__git_all_commands)
> + do
> + case $i in
> + *--*) : helper pattern;;
> applymbox) : ask gittus;;
> applypatch) : ask gittus;;
> archimport) : import;;
> @@ -427,8 +445,8 @@ __git_commands ()
> esac
> done
> }
> -__git_commandlist=
> -__git_commandlist="$(__git_commands 2>/dev/null)"
> +__git_porcelain_commandlist=
> +__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
>
> __git_aliases ()
> {
> @@ -767,6 +785,18 @@ _git_gc ()
> COMPREPLY=()
> }
>
> +_git_help ()
> +{
> + local cur="${COMP_WORDS[COMP_CWORD]}"
> + case "$cur" in
> + --*)
> + __gitcomp "--all --info --man --web"
> + return
> + ;;
> + esac
> + __gitcomp "$(__git_all_commands)"
> +}
> +
> _git_ls_remote ()
> {
> __gitcomp "$(__git_remotes)"
> @@ -1369,7 +1399,8 @@ _git ()
> case "$i" in
> --git-dir=*) __git_dir="${i#--git-dir=}" ;;
> --bare) __git_dir="." ;;
> - --version|--help|-p|--paginate) ;;
> + --version|-p|--paginate) ;;
> + --help) command="help"; break ;;
> *) command="$i"; break ;;
> esac
> c=$((++c))
> @@ -1389,7 +1420,7 @@ _git ()
> --help
> "
> ;;
> - *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
> + *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
> esac
> return
> fi
> @@ -1414,6 +1445,7 @@ _git ()
> fetch) _git_fetch ;;
> format-patch) _git_format_patch ;;
> gc) _git_gc ;;
> + help) _git_help ;;
> log) _git_log ;;
> ls-remote) _git_ls_remote ;;
> ls-tree) _git_ls_tree ;;
--
Shawn.
^ permalink raw reply
* Re: [PATCH] bash: offer only paths after '--' for 'git checkout'
From: Shawn O. Pearce @ 2008-07-25 20:34 UTC (permalink / raw)
To: SZEDER GGGbor; +Cc: git, Pierre Habouzit, gitster
In-Reply-To: <1216813762-23511-2-git-send-email-szeder@ira.uka.de>
SZEDER GGGbor <szeder@ira.uka.de> wrote:
> Commit d773c631 (bash: offer only paths after '--', 2008-07-08) did the
> same for several other git commands, but 'git checkout' went unnoticed.
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 2edb341..9b51fda 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -626,6 +626,8 @@ _git_bundle ()
>
> _git_checkout ()
> {
> + __git_has_doubledash && return
> +
> __gitcomp "$(__git_refs)"
> }
>
--
Shawn.
^ permalink raw reply
* Re: git rebase to move a batch of patches onto the current branch
From: Björn Steinbrink @ 2008-07-25 20:31 UTC (permalink / raw)
To: Avery Pennarun; +Cc: Git Mailing List
In-Reply-To: <32541b130807241257j7820a591if8ca01c66bbcd6b2@mail.gmail.com>
On 2008.07.24 15:57:03 -0400, Avery Pennarun wrote:
> Hi,
>
> I often find myself being on a branch and wanting to do the equivalent
> of a series of cherry-picks from another branch into the current one.
> Unfortunately, "git cherry-pick" only does one patch at a time (which
> is very tedious), and "git rebase", which is much less tedious to use,
> seems to specializing in applying your current branch on top of
> another branch, not the other way around.
>
> Currently I do something like this:
>
> git checkout -b tmp branch_with_interesting_stuff~5
> git rebase --onto mybranch branch_with_interesting_stuff~15
> git branch -d mybranch
> git branch -m tmp mybranch
>
> But it seems a little complex when what I *really* want to type is
> something like:
>
> git cherry-pick
> branch_with_interesting_stuff~15..branch_with_interesting_stuff~5
>
> and have it give me a rebase-style UI in case of conflicts, etc. And
> of course, even more bonus points if I can get "rebase -i"
> functionality.
For "rebase -i", this should do:
git checkout mybranch
git reset --hard interesting_stuff~5
git rebase -i --onto ORIG_HEAD interesting_stuff~5
Not as nice as the format-patch thing but at least it doesn't drop your
braches' reflog like your version, and it provides "rebase -i"
functionality.
Note that the ORIG_HEAD thing might require a recent git version, IIRC
there were some patches to make rebase correctly handle that.
Björn
^ permalink raw reply
* [JGIT PATCH 5/9 v2] Create a catalog of CommandRefs for lookup and enumeration
From: Shawn O. Pearce @ 2008-07-25 20:02 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-6-git-send-email-spearce@spearce.org>
The command catalog supports enumerating commands registered through
a services list, converting each entry into a CommandRef and making
that available to callers on demand. The CommandRef can be later used
to create a command instance or just to obtain documentation about it.
All current commands are listed in the service registration.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
All that was missing was the services file entry in the built JAR.
With this replacement for 5/9 the series should be fine.
make_jgit.sh | 1 +
.../services/org.spearce.jgit.pgm.TextBuiltin | 12 ++
.../src/org/spearce/jgit/pgm/CommandCatalog.java | 188 ++++++++++++++++++++
3 files changed, 201 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
diff --git a/make_jgit.sh b/make_jgit.sh
index bcb2df0..89df80c 100755
--- a/make_jgit.sh
+++ b/make_jgit.sh
@@ -71,6 +71,7 @@ sed s/@@use_self@@/1/ jgit.sh >$O+ &&
java org.spearce.jgit.pgm.build.JarLinkUtil \
`for p in $JARS ; do printf %s " -include $p" ;done` \
`for p in $PLUGINS; do printf %s " -include $p/bin2";done` \
+ -file META-INF/services/org.spearce.jgit.pgm.TextBuiltin=org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin \
-file META-INF/MANIFEST.MF=$T_MF \
>>$O+ &&
chmod 555 $O+ &&
diff --git a/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin b/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
new file mode 100644
index 0000000..69ef046
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
@@ -0,0 +1,12 @@
+org.spearce.jgit.pgm.DiffTree
+org.spearce.jgit.pgm.Fetch
+org.spearce.jgit.pgm.Glog
+org.spearce.jgit.pgm.IndexPack
+org.spearce.jgit.pgm.Log
+org.spearce.jgit.pgm.LsRemote
+org.spearce.jgit.pgm.LsTree
+org.spearce.jgit.pgm.MergeBase
+org.spearce.jgit.pgm.Push
+org.spearce.jgit.pgm.RevList
+org.spearce.jgit.pgm.ShowRev
+org.spearce.jgit.pgm.Tag
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
new file mode 100644
index 0000000..13c585c
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
@@ -0,0 +1,188 @@
+/*
+ * 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;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * List of all commands known by jgit's command line tools.
+ * <p>
+ * Commands are implementations of {@link TextBuiltin}, with an optional
+ * {@link Command} class annotation to insert additional documentation or
+ * override the default command name (which is guessed from the class name).
+ * <p>
+ * Commands may be registered by adding them to a services file in the same JAR
+ * (or classes directory) as the command implementation. The service file name
+ * is <code>META-INF/services/org.spearce.jgit.pgm.TextBuiltin</code> and it
+ * contains one concrete implementation class name per line.
+ * <p>
+ * Command registration is identical to Java 6's services, however the catalog
+ * uses a lightweight wrapper to delay creating a command instance as much as
+ * possible. This avoids initializing the AWT or SWT GUI toolkits even if the
+ * command's constructor might require them.
+ */
+public class CommandCatalog {
+ private static final CommandCatalog INSTANCE = new CommandCatalog();
+
+ /**
+ * Locate a single command by its user friendly name.
+ *
+ * @param name
+ * name of the command. Typically in dash-lower-case-form, which
+ * was derived from the DashLowerCaseForm class name.
+ * @return the command instance; null if no command exists by that name.
+ */
+ public static CommandRef get(final String name) {
+ return INSTANCE.commands.get(name);
+ }
+
+ /**
+ * @return all known commands, sorted by command name.
+ */
+ public static CommandRef[] all() {
+ return toSortedArray(INSTANCE.commands.values());
+ }
+
+ /**
+ * @return all common commands, sorted by command name.
+ */
+ public static CommandRef[] common() {
+ final ArrayList<CommandRef> common = new ArrayList<CommandRef>();
+ for (final CommandRef c : INSTANCE.commands.values())
+ if (c.isCommon())
+ common.add(c);
+ return toSortedArray(common);
+ }
+
+ private static CommandRef[] toSortedArray(final Collection<CommandRef> c) {
+ final CommandRef[] r = c.toArray(new CommandRef[c.size()]);
+ Arrays.sort(r, new Comparator<CommandRef>() {
+ public int compare(final CommandRef o1, final CommandRef o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ return r;
+ }
+
+ private final ClassLoader ldr;
+
+ private final Map<String, CommandRef> commands;
+
+ private CommandCatalog() {
+ ldr = Thread.currentThread().getContextClassLoader();
+ commands = new HashMap<String, CommandRef>();
+
+ final Enumeration<URL> catalogs = catalogs();
+ while (catalogs.hasMoreElements())
+ scan(catalogs.nextElement());
+ }
+
+ private Enumeration<URL> catalogs() {
+ try {
+ final String pfx = "META-INF/services/";
+ return ldr.getResources(pfx + TextBuiltin.class.getName());
+ } catch (IOException err) {
+ return new Vector<URL>().elements();
+ }
+ }
+
+ private void scan(final URL cUrl) {
+ final BufferedReader cIn;
+ try {
+ final InputStream in = cUrl.openStream();
+ cIn = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ } catch (IOException err) {
+ // If we cannot read from the service list, go to the next.
+ //
+ return;
+ }
+
+ try {
+ String line;
+ while ((line = cIn.readLine()) != null) {
+ if (line.length() > 0 && !line.startsWith("#"))
+ load(line);
+ }
+ } catch (IOException err) {
+ // If we failed during a read, ignore the error.
+ //
+ } finally {
+ try {
+ cIn.close();
+ } catch (IOException e) {
+ // Ignore the close error; we are only reading.
+ }
+ }
+ }
+
+ private void load(final String cn) {
+ final Class<? extends TextBuiltin> clazz;
+ try {
+ clazz = Class.forName(cn, false, ldr).asSubclass(TextBuiltin.class);
+ } catch (ClassNotFoundException notBuiltin) {
+ // Doesn't exist, even though the service entry is present.
+ //
+ return;
+ } catch (ClassCastException notBuiltin) {
+ // Isn't really a builtin, even though its listed as such.
+ //
+ return;
+ }
+
+ final CommandRef cr;
+ final Command a = clazz.getAnnotation(Command.class);
+ if (a != null)
+ cr = new CommandRef(clazz, a);
+ else
+ cr = new CommandRef(clazz);
+
+ commands.put(cr.getName(), cr);
+ }
+}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* Re: git rebase to move a batch of patches onto the current branch
From: Alex Riesen @ 2008-07-25 20:00 UTC (permalink / raw)
To: Stephan Beyer; +Cc: Daniel Barkalow, Avery Pennarun, Git Mailing List
In-Reply-To: <20080725192500.GB13539@leksak.fem-net>
Stephan Beyer, Fri, Jul 25, 2008 21:25:00 +0200:
> Daniel Barkalow wrote:
> > > On 7/24/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> > > > Avery Pennarun, Thu, Jul 24, 2008 22:16:06 +0200:
> > > > > On 7/24/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> > > >
> > > > > > gcp3 ()
> > > > > > {
> > > > > > git format-patch -k --stdout --full-index "$@" | git am -k -3 --binary
> > > > > > }
> > > > >
> > > > > But that'll give up when there are conflicts, right? git-rebase lets
> > > > > me fix them in a nice way.
> > > >
> > > > No, it same as in rebase. You'll fix them and do "git am --resolved".
> > > > See manpage of git am.
> > >
> > > Hmm, cool.
> > >
> > > So that command isn't too easy to come upon by accident. If I wanted
> > > to submit a patch to make this process a bit more obvious, would it
> > > make sense to simply have git-cherry-pick call that sequence when you
> > > give it more than one commit?
> >
> > Before terribly long, we'll have "git sequencer", which should be easy to
> > get to do the "rebase -i" thing with cherry-pick-style usage (somebody
> > would just need to write code to generate the correct series of pick
> > statements).
>
> For simple cases this code could be something like:
> git rev-list --reverse --cherry-pick --no-merges --first-parent <from>..<to> |
> sed 's/^/pick /' | git sequencer
>
> (At least this is what I use relatively often.)
>
> But as long as git sequencer is not in official git, this is not an
> option. :)
Besides, that's longer than format-patch + am for the same from..to
range.
^ permalink raw reply
* Re: [JGIT PATCH 0/9] List commonly used (or recognized) commands
From: Shawn O. Pearce @ 2008-07-25 19:52 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-1-git-send-email-spearce@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> wrote:
> This series adds support to jgit to list commonly used subcommands
> if the user just executes `jgit` with no subcommand requested:
>
> $ jgit
> jgit --git-dir GIT_DIR --help (-h) --show-stack-trace command [ARG ...]
>
> The most commonly used commands are:
> fetch Update remote refs from another repository
> log View commit history
> push Update remote repository from local refs
> tag Create a tag
Scratch that. This series is busted if you install jgit and actually
try to use it. No subcommands get registered. I suspect it is due
to the shell script+ZIP file we have in the CLASSPATH confusing the
JRE and making it impossible to read correctly.
--
Shawn.
^ permalink raw reply
* [PATCH 6/9 - v3] builtin-init-db.c: use parse_options()
From: Michele Ballabio @ 2008-07-25 19:53 UTC (permalink / raw)
To: dkr+ml.git; +Cc: git, gitster
In-Reply-To: <4889EF45.1040603@free.fr>
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
On Friday 25 July 2008, Olivier Marin wrote:
> Michele Ballabio a écrit :
> >
> >>> + PARSE_OPT_OPTARG, parse_opt_shared_cb, PERM_GROUP },
> >> Are you sure the default value is really used here?
> >
> > Yes. Perhaps I don't understand your question. Can you explain what you mean?
>
> If I read the code correctly in parse-options.c, with OPTION_CALLBACK, the
> default value is not "automatically" used. You can use it in your callback
> if you want, but because you don't, I think it's never used.
Oh, you're right, but git_config_perm() handles NULL just fine, so I can
remove it. Done in this patch, thanks.
> what I suggested is more something like:
>
> static int parse_opt_shared_cb(const struct option *opt, const char *arg,
> int unset)
> {
> *(int *)(opt->value) = unset ? -1 : git_config_perm("arg", arg);
> return 0;
> }
>
> int shared = -1;
>
> { OPTION_CALLBACK, 0, "shared", &shared,
> "permissions", "setup as shared repository",
> PARSE_OPT_OPTARG, parse_perm_callback },
>
> if (shared >= 0)
> shared_repository = shared;
>
> This way we do not change shared_repository during parsing, so we do not
> loose the initial value.
>
> But it seems nobody care about this kind of details, so perhaps, you can
> just ignore this suggestion.
I might be wrong, but shared_repository is initialized to PERM_UMASK and
does not change before parse_options() is called, so this is not much
useful.
builtin-init-db.c | 57 +++++++++++++++++++++++++++++++++-------------------
1 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 38b4fcb..01b84a9 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -6,6 +6,7 @@
#include "cache.h"
#include "builtin.h"
#include "exec_cmd.h"
+#include "parse-options.h"
#ifndef DEFAULT_GIT_TEMPLATE_DIR
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -353,8 +354,18 @@ static int guess_repository_type(const char *git_dir)
return 1;
}
-static const char init_db_usage[] =
-"git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]]";
+static const char * const init_db_usage[] = {
+ "git init [-q | --quiet] [--bare] [--template=<dir>] [--shared[=<type>]]",
+ NULL
+};
+
+static int parse_opt_shared_cb(const struct option *opt, const char *arg,
+ int unset)
+{
+ *(int *)(opt->value) = unset ? PERM_UMASK :
+ git_config_perm("arg", arg);
+ return 0;
+}
/*
* If you want to, you can share the DB area with any number of branches.
@@ -367,25 +378,29 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
const char *git_dir;
const char *template_dir = NULL;
unsigned int flags = 0;
- int i;
-
- for (i = 1; i < argc; i++, argv++) {
- const char *arg = argv[1];
- if (!prefixcmp(arg, "--template="))
- template_dir = arg+11;
- else if (!strcmp(arg, "--bare")) {
- static char git_dir[PATH_MAX+1];
- is_bare_repository_cfg = 1;
- setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
- sizeof(git_dir)), 0);
- } else if (!strcmp(arg, "--shared"))
- shared_repository = PERM_GROUP;
- else if (!prefixcmp(arg, "--shared="))
- shared_repository = git_config_perm("arg", arg+9);
- else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
- flags |= INIT_DB_QUIET;
- else
- usage(init_db_usage);
+ int bare = 0;
+
+ const struct option options[] = {
+ OPT_STRING(0, "template", &template_dir, "path",
+ "path to the template directory"),
+ OPT_BOOLEAN(0, "bare", &bare, "set up a bare repository"),
+ { OPTION_CALLBACK, 0, "shared", &shared_repository,
+ "permissions", "set up a shared repository",
+ PARSE_OPT_OPTARG, parse_opt_shared_cb },
+ OPT_BIT('q', "quiet", &flags, "be quiet", INIT_DB_QUIET),
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, init_db_usage, 0);
+
+ if (argc > 0)
+ usage_with_options(init_db_usage, options);
+
+ if (bare) {
+ static char git_dir[PATH_MAX+1];
+ is_bare_repository_cfg = 1;
+ setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
+ sizeof(git_dir)), 0);
}
/*
--
1.5.6.3
^ permalink raw reply related
* [JGIT PATCH 9/9] Add debug-show-commands to display the command table
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-9-git-send-email-spearce@spearce.org>
This can be useful to debug the command catalog.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../services/org.spearce.jgit.pgm.TextBuiltin | 2 +
.../src/org/spearce/jgit/pgm/CommandRef.java | 7 ++
.../org/spearce/jgit/pgm/debug/ShowCommands.java | 78 ++++++++++++++++++++
3 files changed, 87 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/debug/ShowCommands.java
diff --git a/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin b/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
index 69ef046..1ff5a30 100644
--- a/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
+++ b/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
@@ -10,3 +10,5 @@ org.spearce.jgit.pgm.Push
org.spearce.jgit.pgm.RevList
org.spearce.jgit.pgm.ShowRev
org.spearce.jgit.pgm.Tag
+
+org.spearce.jgit.pgm.debug.ShowCommands
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
index 40400a7..8bf784b 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
@@ -120,6 +120,13 @@ public class CommandRef {
}
/**
+ * @return loader for {@link #getImplementationClassName()}.
+ */
+ public ClassLoader getImplementationClassLoader() {
+ return impl.getClassLoader();
+ }
+
+ /**
* @return a new instance of the command implementation.
*/
public TextBuiltin create() {
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/debug/ShowCommands.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/debug/ShowCommands.java
new file mode 100644
index 0000000..64ecf7f
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/debug/ShowCommands.java
@@ -0,0 +1,78 @@
+package org.spearce.jgit.pgm.debug;
+
+import java.net.URL;
+
+import org.kohsuke.args4j.Option;
+import org.spearce.jgit.pgm.Command;
+import org.spearce.jgit.pgm.CommandCatalog;
+import org.spearce.jgit.pgm.CommandRef;
+import org.spearce.jgit.pgm.TextBuiltin;
+
+@Command(usage = "Display a list of all registered jgit commands")
+class ShowCommands extends TextBuiltin {
+ @Option(name = "--pretty", usage = "alter the detail shown")
+ private Format pretty = Format.USAGE;
+
+ @Override
+ protected void run() throws Exception {
+ final CommandRef[] list = CommandCatalog.all();
+
+ int width = 0;
+ for (final CommandRef c : list)
+ width = Math.max(width, c.getName().length());
+ width += 2;
+
+ for (final CommandRef c : list) {
+ System.err.print(c.isCommon() ? '*' : ' ');
+ System.err.print(' ');
+
+ System.err.print(c.getName());
+ for (int i = c.getName().length(); i < width; i++)
+ System.err.print(' ');
+
+ pretty.print(c);
+ System.err.println();
+ }
+ System.err.println();
+ }
+
+ static enum Format {
+ /** */
+ USAGE {
+ void print(final CommandRef c) {
+ System.err.print(c.getUsage());
+ }
+ },
+
+ /** */
+ CLASSES {
+ void print(final CommandRef c) {
+ System.err.print(c.getImplementationClassName());
+ }
+ },
+
+ /** */
+ URLS {
+ void print(final CommandRef c) {
+ final ClassLoader ldr = c.getImplementationClassLoader();
+
+ String cn = c.getImplementationClassName();
+ cn = cn.replace('.', '/') + ".class";
+
+ final URL url = ldr.getResource(cn);
+ if (url == null) {
+ System.err.print("!! NOT FOUND !!");
+ return;
+ }
+
+ String rn = url.toExternalForm();
+ if (rn.endsWith(cn))
+ rn = rn.substring(0, rn.length() - cn.length());
+
+ System.err.print(rn);
+ }
+ };
+
+ abstract void print(CommandRef c);
+ }
+}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 6/9] Document some common commands with the new Command annotation
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-6-git-send-email-spearce@spearce.org>
This way they are known to be common at runtime, by looking at
the annotation associated with the class instance. Right now
we do not use these annotations but they will be useful soon.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Fetch.java | 1 +
.../src/org/spearce/jgit/pgm/Log.java | 1 +
.../src/org/spearce/jgit/pgm/Push.java | 1 +
.../src/org/spearce/jgit/pgm/Tag.java | 1 +
4 files changed, 4 insertions(+), 0 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 194f669..dcad972 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
@@ -47,6 +47,7 @@ import org.spearce.jgit.transport.RefSpec;
import org.spearce.jgit.transport.TrackingRefUpdate;
import org.spearce.jgit.transport.Transport;
+@Command(common = true, usage = "Update remote refs from another repository")
class Fetch extends TextBuiltin {
@Argument(index = 0, metaVar = "uri-ish")
private String remote = "origin";
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java
index 780a63b..e16387b 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Log.java
@@ -45,6 +45,7 @@ import java.util.TimeZone;
import org.spearce.jgit.lib.PersonIdent;
import org.spearce.jgit.revwalk.RevCommit;
+@Command(common = true, usage = "View commit history")
class Log extends RevWalkTextBuiltin {
private final TimeZone myTZ = TimeZone.getDefault();
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 df6c664..6b35ab8 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
@@ -51,6 +51,7 @@ import org.spearce.jgit.transport.RemoteRefUpdate;
import org.spearce.jgit.transport.Transport;
import org.spearce.jgit.transport.RemoteRefUpdate.Status;
+@Command(common = true, usage = "Update remote repository from local refs")
class Push extends TextBuiltin {
@Argument(index = 0, metaVar = "uri-ish")
private String remote = "origin";
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 a7bd037..6c73552 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
@@ -45,6 +45,7 @@ import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.ObjectLoader;
import org.spearce.jgit.lib.PersonIdent;
+@Command(common = true, usage = "Create a tag")
class Tag extends TextBuiltin {
@Option(name = "-f", usage = "force replacing an existing tag")
private boolean force;
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 8/9] Refactor SubcommandHandler to use CommandCatalog instead of reflection
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-8-git-send-email-spearce@spearce.org>
Now that all commands are known to the CommandCatalog we do not need
to perform direct reflection inside of the SubcommandHandler. Instead
we can reuse the lookup table already known to the CommandCatalog.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/TextBuiltin.java | 8 +--
.../spearce/jgit/pgm/opt/SubcommandHandler.java | 65 ++------------------
2 files changed, 6 insertions(+), 67 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 e2eef84..5c066cb 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
@@ -83,13 +83,7 @@ public abstract class TextBuiltin {
/** 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.
- *
- * @param name
- * the name of the command.
- */
- public void setCommandName(final String name) {
+ final void setCommandName(final String name) {
commandName = name;
}
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
index c7e1bf6..86004bb 100644
--- 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
@@ -37,8 +37,6 @@
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;
@@ -47,7 +45,8 @@ 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.CommandCatalog;
+import org.spearce.jgit.pgm.CommandRef;
import org.spearce.jgit.pgm.TextBuiltin;
/**
@@ -57,12 +56,6 @@ import org.spearce.jgit.pgm.TextBuiltin;
* 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>
@@ -80,65 +73,17 @@ public class SubcommandHandler extends OptionHandler<TextBuiltin> {
@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))
+ final CommandRef cr = CommandCatalog.get(name);
+ if (cr == null)
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();
-
+ setter.addValue(cr.create());
return 1;
}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 7/9] Include commonly used commands in main help output
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-7-git-send-email-spearce@spearce.org>
If the main loop did not get a subcommand during parsing of the
command line then we should offer up a list of commonly used
commands and their one-line usage summary, to help the user make
a decision about which command they should try to execute.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Main.java | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
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 c069989..c8bade8 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
@@ -121,6 +121,24 @@ public class Main {
System.err.println();
clp.printUsage(System.err);
System.err.println();
+ } else if (subcommand == null) {
+ System.err.println();
+ System.err.println("The most commonly used commands are:");
+ final CommandRef[] common = CommandCatalog.common();
+ int width = 0;
+ for (final CommandRef c : common)
+ width = Math.max(width, c.getName().length());
+ width += 2;
+
+ for (final CommandRef c : common) {
+ System.err.print(' ');
+ System.err.print(c.getName());
+ for (int i = c.getName().length(); i < width; i++)
+ System.err.print(' ');
+ System.err.print(c.getUsage());
+ System.err.println();
+ }
+ System.err.println();
}
System.exit(1);
}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 5/9] Create a catalog of CommandRefs for lookup and enumeration
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-5-git-send-email-spearce@spearce.org>
The command catalog supports enumerating commands registered through
a services list, converting each entry into a CommandRef and making
that available to callers on demand. The CommandRef can be later used
to create a command instance or just to obtain documentation about it.
All current commands are listed in the service registration.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../services/org.spearce.jgit.pgm.TextBuiltin | 12 ++
.../src/org/spearce/jgit/pgm/CommandCatalog.java | 188 ++++++++++++++++++++
2 files changed, 200 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
diff --git a/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin b/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
new file mode 100644
index 0000000..69ef046
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
@@ -0,0 +1,12 @@
+org.spearce.jgit.pgm.DiffTree
+org.spearce.jgit.pgm.Fetch
+org.spearce.jgit.pgm.Glog
+org.spearce.jgit.pgm.IndexPack
+org.spearce.jgit.pgm.Log
+org.spearce.jgit.pgm.LsRemote
+org.spearce.jgit.pgm.LsTree
+org.spearce.jgit.pgm.MergeBase
+org.spearce.jgit.pgm.Push
+org.spearce.jgit.pgm.RevList
+org.spearce.jgit.pgm.ShowRev
+org.spearce.jgit.pgm.Tag
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
new file mode 100644
index 0000000..13c585c
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
@@ -0,0 +1,188 @@
+/*
+ * 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;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * List of all commands known by jgit's command line tools.
+ * <p>
+ * Commands are implementations of {@link TextBuiltin}, with an optional
+ * {@link Command} class annotation to insert additional documentation or
+ * override the default command name (which is guessed from the class name).
+ * <p>
+ * Commands may be registered by adding them to a services file in the same JAR
+ * (or classes directory) as the command implementation. The service file name
+ * is <code>META-INF/services/org.spearce.jgit.pgm.TextBuiltin</code> and it
+ * contains one concrete implementation class name per line.
+ * <p>
+ * Command registration is identical to Java 6's services, however the catalog
+ * uses a lightweight wrapper to delay creating a command instance as much as
+ * possible. This avoids initializing the AWT or SWT GUI toolkits even if the
+ * command's constructor might require them.
+ */
+public class CommandCatalog {
+ private static final CommandCatalog INSTANCE = new CommandCatalog();
+
+ /**
+ * Locate a single command by its user friendly name.
+ *
+ * @param name
+ * name of the command. Typically in dash-lower-case-form, which
+ * was derived from the DashLowerCaseForm class name.
+ * @return the command instance; null if no command exists by that name.
+ */
+ public static CommandRef get(final String name) {
+ return INSTANCE.commands.get(name);
+ }
+
+ /**
+ * @return all known commands, sorted by command name.
+ */
+ public static CommandRef[] all() {
+ return toSortedArray(INSTANCE.commands.values());
+ }
+
+ /**
+ * @return all common commands, sorted by command name.
+ */
+ public static CommandRef[] common() {
+ final ArrayList<CommandRef> common = new ArrayList<CommandRef>();
+ for (final CommandRef c : INSTANCE.commands.values())
+ if (c.isCommon())
+ common.add(c);
+ return toSortedArray(common);
+ }
+
+ private static CommandRef[] toSortedArray(final Collection<CommandRef> c) {
+ final CommandRef[] r = c.toArray(new CommandRef[c.size()]);
+ Arrays.sort(r, new Comparator<CommandRef>() {
+ public int compare(final CommandRef o1, final CommandRef o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ return r;
+ }
+
+ private final ClassLoader ldr;
+
+ private final Map<String, CommandRef> commands;
+
+ private CommandCatalog() {
+ ldr = Thread.currentThread().getContextClassLoader();
+ commands = new HashMap<String, CommandRef>();
+
+ final Enumeration<URL> catalogs = catalogs();
+ while (catalogs.hasMoreElements())
+ scan(catalogs.nextElement());
+ }
+
+ private Enumeration<URL> catalogs() {
+ try {
+ final String pfx = "META-INF/services/";
+ return ldr.getResources(pfx + TextBuiltin.class.getName());
+ } catch (IOException err) {
+ return new Vector<URL>().elements();
+ }
+ }
+
+ private void scan(final URL cUrl) {
+ final BufferedReader cIn;
+ try {
+ final InputStream in = cUrl.openStream();
+ cIn = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+ } catch (IOException err) {
+ // If we cannot read from the service list, go to the next.
+ //
+ return;
+ }
+
+ try {
+ String line;
+ while ((line = cIn.readLine()) != null) {
+ if (line.length() > 0 && !line.startsWith("#"))
+ load(line);
+ }
+ } catch (IOException err) {
+ // If we failed during a read, ignore the error.
+ //
+ } finally {
+ try {
+ cIn.close();
+ } catch (IOException e) {
+ // Ignore the close error; we are only reading.
+ }
+ }
+ }
+
+ private void load(final String cn) {
+ final Class<? extends TextBuiltin> clazz;
+ try {
+ clazz = Class.forName(cn, false, ldr).asSubclass(TextBuiltin.class);
+ } catch (ClassNotFoundException notBuiltin) {
+ // Doesn't exist, even though the service entry is present.
+ //
+ return;
+ } catch (ClassCastException notBuiltin) {
+ // Isn't really a builtin, even though its listed as such.
+ //
+ return;
+ }
+
+ final CommandRef cr;
+ final Command a = clazz.getAnnotation(Command.class);
+ if (a != null)
+ cr = new CommandRef(clazz, a);
+ else
+ cr = new CommandRef(clazz);
+
+ commands.put(cr.getName(), cr);
+ }
+}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 4/9] Create a lightweight registration wrapper for TextBuiltin
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-4-git-send-email-spearce@spearce.org>
Automatic command list generation requires knowing what commands
are available to this runtime, and what name those commands can be
called as by the end-user. This lightweight wrappers carries the
data from the Command annotation, possibly filling in the name of
the command by generating it from the implementation class name.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/CommandRef.java | 151 ++++++++++++++++++++
1 files changed, 151 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
new file mode 100644
index 0000000..40400a7
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
@@ -0,0 +1,151 @@
+/*
+ * 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;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Description of a command (a {@link TextBuiltin} subclass.
+ * <p>
+ * These descriptions are lightweight compared to creating a command instance
+ * and are therefore suitable for catalogs of "known" commands without linking
+ * the command's implementation and creating a dummy instance of the command.
+ */
+public class CommandRef {
+ private final Class<? extends TextBuiltin> impl;
+
+ private final String name;
+
+ private String usage;
+
+ boolean common;
+
+ CommandRef(final Class<? extends TextBuiltin> clazz) {
+ this(clazz, guessName(clazz));
+ }
+
+ CommandRef(final Class<? extends TextBuiltin> clazz, final Command cmd) {
+ this(clazz, cmd.name().length() > 0 ? cmd.name() : guessName(clazz));
+ usage = cmd.usage();
+ common = cmd.common();
+ }
+
+ private CommandRef(final Class<? extends TextBuiltin> clazz, final String cn) {
+ impl = clazz;
+ name = cn;
+ usage = "";
+ }
+
+ private static String guessName(final Class<? extends TextBuiltin> clazz) {
+ final StringBuilder s = new StringBuilder();
+ if (clazz.getName().startsWith("org.spearce.jgit.pgm.debug."))
+ s.append("debug-");
+
+ boolean lastWasDash = true;
+ for (final char c : clazz.getSimpleName().toCharArray()) {
+ if (Character.isUpperCase(c)) {
+ if (!lastWasDash)
+ s.append('-');
+ lastWasDash = !lastWasDash;
+ s.append(Character.toLowerCase(c));
+ } else {
+ s.append(c);
+ }
+ }
+ return s.toString();
+ }
+
+ /**
+ * @return name the command is invoked as from the command line.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return one line description of the command's feature set.
+ */
+ public String getUsage() {
+ return usage;
+ }
+
+ /**
+ * @return true if this command is considered to be commonly used.
+ */
+ public boolean isCommon() {
+ return common;
+ }
+
+ /**
+ * @return name of the Java class which implements this command.
+ */
+ public String getImplementationClassName() {
+ return impl.getName();
+ }
+
+ /**
+ * @return a new instance of the command implementation.
+ */
+ public TextBuiltin create() {
+ final Constructor<? extends TextBuiltin> c;
+ try {
+ c = impl.getDeclaredConstructor();
+ } catch (SecurityException e) {
+ throw new RuntimeException("Cannot create command " + getName(), e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Cannot create command " + getName(), e);
+ }
+ c.setAccessible(true);
+
+ final TextBuiltin r;
+ try {
+ r = c.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException("Cannot create command " + getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Cannot create command " + getName(), e);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("Cannot create command " + getName(), e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Cannot create command " + getName(), e);
+ }
+ r.setCommandName(getName());
+ return r;
+ }
+}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 3/9] Create an optional documentation annotation for TextBuiltin
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-3-git-send-email-spearce@spearce.org>
This new annotation can be used for automatic command list creation,
or additional help generation by the default help generator.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/Command.java | 72 ++++++++++++++++++++
1 files changed, 72 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Command.java
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Command.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Command.java
new file mode 100644
index 0000000..40be1f7
--- /dev/null
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Command.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to document a {@link TextBuiltin}.
+ * <p>
+ * This is an optional annotation for TextBuiltin subclasses and it carries
+ * documentation forward into the runtime system describing what the command is
+ * and why users may want to invoke it.
+ */
+@Retention(RUNTIME)
+@Target( { TYPE })
+public @interface Command {
+ /**
+ * @return name the command is invoked as from the command line. If the
+ * (default) empty string is supplied the name will be generated
+ * from the class name.
+ */
+ public String name() default "";
+
+ /**
+ * @return one line description of the command's feature set.
+ */
+ public String usage() default "";
+
+ /**
+ * @return true if this command is considered to be commonly used.
+ */
+ public boolean common() default false;
+}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 2/9] Remove unnecessary duplicate if (help) test inside TextBuiltin
From: Shawn O. Pearce @ 2008-07-25 19:46 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-2-git-send-email-spearce@spearce.org>
This was caused by a copy-and-paste error as I borrowed the
global argument handling code in Main to help start writing
the command specific argument handling in TextBuiltin.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/pgm/TextBuiltin.java | 9 ++++-----
1 files changed, 4 insertions(+), 5 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 d02a0a2..e2eef84 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
@@ -145,11 +145,10 @@ public abstract class TextBuiltin {
clp.printSingleLineUsage(System.err);
System.err.println();
- if (help) {
- System.err.println();
- clp.printUsage(System.err);
- System.err.println();
- }
+ System.err.println();
+ clp.printUsage(System.err);
+ System.err.println();
+
System.exit(1);
}
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 1/9] Switch jgit.pgm to J2SE-1.5 execution environment
From: Shawn O. Pearce @ 2008-07-25 19:45 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1217015167-4680-1-git-send-email-spearce@spearce.org>
We have been keeping the jgit library itself on Java 5, and the
jgit command line tools should also be on Java 5 and avoid using
any Java 6 APIs (for now). Not all of our target platforms have
a Java 6 virtual machine available out of the box.
Since the pgm project broke out of the library project our code
already conforms to Java 5 APIs, so we just have to switch the
build path settings.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
org.spearce.jgit.pgm/.classpath | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit.pgm/.classpath b/org.spearce.jgit.pgm/.classpath
index cc861d2..50dd6d3 100644
--- a/org.spearce.jgit.pgm/.classpath
+++ b/org.spearce.jgit.pgm/.classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/args4j-2.0.9.jar" sourcepath="lib/args4j-2.0.9.zip"/>
- <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/org.spearce.jgit"/>
<classpathentry kind="output" path="bin"/>
</classpath>
--
1.6.0.rc0.182.gb96c7
^ permalink raw reply related
* [JGIT PATCH 0/9] List commonly used (or recognized) commands
From: Shawn O. Pearce @ 2008-07-25 19:45 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
This series adds support to jgit to list commonly used subcommands
if the user just executes `jgit` with no subcommand requested:
$ jgit
jgit --git-dir GIT_DIR --help (-h) --show-stack-trace command [ARG ...]
The most commonly used commands are:
fetch Update remote refs from another repository
log View commit history
push Update remote repository from local refs
tag Create a tag
Commands inside of the pgm.debug package are automatically given
the debug- prefix, allowing debug-show-commands to be used to show
the command table.
Commands must be listed in the META-INF/services/org...TextBuiltin
file in order to be considered for execution. This means that we
must add (or remove) command class names from the listing each time
we introduce or remove a command line subcommand.
One advantage to this structure is additional commands can defined
in other packages, and are available so long as the classes are
reachable through the CLASSPATH. Since jgit.sh hardcodes the
CLASSPATH to only itself this is not fully supported yet, but does
open the door for users to extend jgit's command line support.
Shawn O. Pearce (9):
Switch jgit.pgm to J2SE-1.5 execution environment
Remove unnecessary duplicate if (help) test inside TextBuiltin
Create an optional documentation annotation for TextBuiltin
Create a lightweight registration wrapper for TextBuiltin
Create a catalog of CommandRefs for lookup and enumeration
Document some common commands with the new Command annotation
Include commonly used commands in main help output
Refactor SubcommandHandler to use CommandCatalog instead of
reflection
Add debug-show-commands to display the command table
org.spearce.jgit.pgm/.classpath | 2 +-
.../services/org.spearce.jgit.pgm.TextBuiltin | 14 ++
.../src/org/spearce/jgit/pgm/Command.java | 72 ++++++++
.../src/org/spearce/jgit/pgm/CommandCatalog.java | 188 ++++++++++++++++++++
.../src/org/spearce/jgit/pgm/CommandRef.java | 158 ++++++++++++++++
.../src/org/spearce/jgit/pgm/Fetch.java | 1 +
.../src/org/spearce/jgit/pgm/Log.java | 1 +
.../src/org/spearce/jgit/pgm/Main.java | 18 ++
.../src/org/spearce/jgit/pgm/Push.java | 1 +
.../src/org/spearce/jgit/pgm/Tag.java | 1 +
.../src/org/spearce/jgit/pgm/TextBuiltin.java | 17 +--
.../org/spearce/jgit/pgm/debug/ShowCommands.java | 78 ++++++++
.../spearce/jgit/pgm/opt/SubcommandHandler.java | 65 +------
13 files changed, 543 insertions(+), 73 deletions(-)
create mode 100644 org.spearce.jgit.pgm/src/META-INF/services/org.spearce.jgit.pgm.TextBuiltin
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Command.java
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandCatalog.java
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/CommandRef.java
create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/debug/ShowCommands.java
^ permalink raw reply
* Re: [PATCH] Set TAR in t/Makefile and in t4116-apply-reverse.sh
From: Junio C Hamano @ 2008-07-25 19:37 UTC (permalink / raw)
To: Stephan Beyer; +Cc: Brandon Casey, git
In-Reply-To: <20080725185818.GA13539@leksak.fem-net>
Stephan Beyer <s-beyer@gmx.net> writes:
> Junio C Hamano wrote:
>> Stephan Beyer <s-beyer@gmx.net> writes:
>> >> diff --git a/Makefile b/Makefile
>> >> index b003e3e..1d14209 100644
>> >> --- a/Makefile
>> >> +++ b/Makefile
>> >> @@ -1212,6 +1212,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
>> >>
>> >> GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPTIONS
>> >> @echo SHELL_PATH=\''$(SHELL_PATH_SQ)'\' >$@
>> >> + @echo TAR=\''$(subst ','\'',$(TAR))'\' >>$@
>> >>
>> >> ### Detect Tck/Tk interpreter path changes
>> >> ifndef NO_TCLTK
>> >
>> > But then TAR has to be set in test-lib.sh also, to be able to
>> > invoke t5000 and t4116 directly, hasn't it?
>>
>> Dosen't test-lib source GIT-BUILD-OPTIONS?
>
> It does. Great, then.
Sorry, but not quite. The above shell construct is toooootally bogus.
We need this patch on top.
-- >8 --
[PATCH] Makefile: fix shell quoting
Makefile records paths to a few programs in GIT-BUILD-OPTIONS file. These
paths need to be quoted twice: once to protect specials from the shell
that runs the generated GIT-BUILD-OPTIONS file, and again to protect them
(and the first level of quoting itself) from the shell that runs the
"echo" inside the Makefile.
You can test this by trying:
$ ln -s /bin/tar "$HOME/Tes' program/tar"
$ make TAR="$HOME/Tes' program/tar" test
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Makefile | 7 +++++--
t/t5000-tar-tree.sh | 10 +++++-----
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 1d14209..f13184b 100644
--- a/Makefile
+++ b/Makefile
@@ -1210,9 +1210,12 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
echo "$$FLAGS" >GIT-CFLAGS; \
fi
+# We need to apply sq twice, once to protect from the shell
+# that runs GIT-BUILD-OPTIONS, and then again to protect it
+# and the first level quoting from the shell that runs "echo".
GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPTIONS
- @echo SHELL_PATH=\''$(SHELL_PATH_SQ)'\' >$@
- @echo TAR=\''$(subst ','\'',$(TAR))'\' >>$@
+ @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@
+ @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
### Detect Tck/Tk interpreter path changes
ifndef NO_TCLTK
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 5eb119e..87902f8 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -67,7 +67,7 @@ test_expect_success \
test_expect_success \
'validate file modification time' \
'mkdir extract &&
- $TAR xf b.tar -C extract a/a &&
+ "$TAR" xf b.tar -C extract a/a &&
perl -e '\''print((stat("extract/a/a"))[9], "\n")'\'' >b.mtime &&
echo "1117231200" >expected.mtime &&
diff expected.mtime b.mtime'
@@ -79,7 +79,7 @@ test_expect_success \
test_expect_success \
'extract tar archive' \
- '(cd b && $TAR xf -) <b.tar'
+ '(cd b && "$TAR" xf -) <b.tar'
test_expect_success \
'validate filenames' \
@@ -96,7 +96,7 @@ test_expect_success \
test_expect_success \
'extract tar archive with prefix' \
- '(cd c && $TAR xf -) <c.tar'
+ '(cd c && "$TAR" xf -) <c.tar'
test_expect_success \
'validate filenames with prefix' \
@@ -116,7 +116,7 @@ test_expect_success \
test_expect_success \
'extract substfiles' \
- '(mkdir f && cd f && $TAR xf -) <f.tar'
+ '(mkdir f && cd f && "$TAR" xf -) <f.tar'
test_expect_success \
'validate substfile contents' \
@@ -128,7 +128,7 @@ test_expect_success \
test_expect_success \
'extract substfiles from archive with prefix' \
- '(mkdir g && cd g && $TAR xf -) <g.tar'
+ '(mkdir g && cd g && "$TAR" xf -) <g.tar'
test_expect_success \
'validate substfile contents from archive with prefix' \
--
1.6.0.rc0.51.g51a9e
^ permalink raw reply related
* Re: [EGIT] Supported Eclipse version
From: Robin Rosenberg @ 2008-07-25 19:35 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Marek Zawirski, Jean-Frannnois Veillette, git
In-Reply-To: <20080725161652.GA21117@spearce.org>
fredagen den 25 juli 2008 18.16.52 skrev Shawn O. Pearce:
> Marek Zawirski <marek.zawirski@gmail.com> wrote:
> > Jean-François Veillette wrote:
> >>> Maybe some users (or developers) from mailing list can tell us about
> >>> their opinion?
> >>
> >> I think keeping comptability for one version behind the 'current'
> >> (still compatible 3.3 while 3.4 is the current) is a reasonable goal.
> >> 3.2 is relatively far behind, tools vendor had time to get up to date
> >> by now.
> >
> > Robin, Shawn, would you accept next patches using 3.3 API?
>
> Yes, we should be dropping support for 3.2 now and supporting only
> 3.3 and 3.4 going forward. 3.2 is ancient and anyone who is serious
> aboug using Git with Eclipse really should be on a more current
> version of the tools.
We already dropped 3.2 compatibility with the push/fetch support. That
was an accident, of course.
Support for 3.3 could also end ahead of schedule if we absolutely need
some feature that is only available in 3.4. We'll discuss that then, when/if
it happens. The plan is to support 3.3 until 3.5 is out (or even longer if
that requires no effort).
So much for intent. We reserve the right to change our minds or make mistakes
without notice.
-- robin
^ permalink raw reply
* Re: git rebase to move a batch of patches onto the current branch
From: Stephan Beyer @ 2008-07-25 19:25 UTC (permalink / raw)
To: Daniel Barkalow; +Cc: Avery Pennarun, Alex Riesen, Git Mailing List
In-Reply-To: <alpine.LNX.1.00.0807251509390.19665@iabervon.org>
Hi,
Daniel Barkalow wrote:
> > On 7/24/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> > > Avery Pennarun, Thu, Jul 24, 2008 22:16:06 +0200:
> > > > On 7/24/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> > >
> > > > > gcp3 ()
> > > > > {
> > > > > git format-patch -k --stdout --full-index "$@" | git am -k -3 --binary
> > > > > }
> > > >
> > > > But that'll give up when there are conflicts, right? git-rebase lets
> > > > me fix them in a nice way.
> > >
> > > No, it same as in rebase. You'll fix them and do "git am --resolved".
> > > See manpage of git am.
> >
> > Hmm, cool.
> >
> > So that command isn't too easy to come upon by accident. If I wanted
> > to submit a patch to make this process a bit more obvious, would it
> > make sense to simply have git-cherry-pick call that sequence when you
> > give it more than one commit?
>
> Before terribly long, we'll have "git sequencer", which should be easy to
> get to do the "rebase -i" thing with cherry-pick-style usage (somebody
> would just need to write code to generate the correct series of pick
> statements).
For simple cases this code could be something like:
git rev-list --reverse --cherry-pick --no-merges --first-parent <from>..<to> |
sed 's/^/pick /' | git sequencer
(At least this is what I use relatively often.)
But as long as git sequencer is not in official git, this is not an
option. :)
Regards,
Stephan
--
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
^ permalink raw reply
* Re: [PATCH] Build configuration to skip ctime for modification test
From: Alex Riesen @ 2008-07-25 5:55 UTC (permalink / raw)
To: Linus Torvalds; +Cc: Johannes Schindelin, Junio C Hamano, Johannes Sixt, git
In-Reply-To: <alpine.LFD.1.10.0807241854580.5249@nehalem.linux-foundation.org>
Linus Torvalds, Fri, Jul 25, 2008 04:00:29 +0200:
> On Wed, 23 Jul 2008, Alex Riesen wrote:
> >
> > It is not that it is broken. We just don't need it, because the st_mode
> > is not used, and the rest of inode information is not used anyway.
>
> That is NOT why git checks the ctime.
>
> Git checks the ctime not because it cares about the inode state being
> modified per se: since it can see that _directly_ - so why should it care
> about inode state like st_mode?
>
> No, git checks ctime because it in general tries to make it VERY VERY hard
> for people to try to "fake out" git and replace files from underneath it
> without git noticing.
>
> It's much easier and much more common for tools to restore 'mtime' when
> they do some operation on a file than it is for them to restore 'ctime'.
>
> For example, if you rsync files between two hosts, the '-t' flag will make
> rsync try to keep the mtimes in sync (and it's part of '-a', which is the
> common form that you'd use for rsync). So if you only look at mtime and
> size, you often miss the fact that the file has actually been messed with!
>
> Looking at ctime gets around a number of those things. Of course, it can
> cause git to be _too_ eager in thinking that a file is modified, and an
> example of that is the insane indexing that 'beagle' does, which actually
> modifies the files by adding inode extended attributes to them and thus
> changes ctime due to the indexing. But in general it's a lot better to be
> too careful than to miss the fact that somebody changed the file.
>
But, given the fact, that somewhere sometimes its very-very annoying
to have even one (un)changed file, something must be done about it.
Maybe just direct
# my .gitconfig for Windows machines with GDS
[core]
filemode = false
trustctime = false
logallrefupdates = false
[pack]
threads = 1
etc...
^ permalink raw reply
* how about removing --exec-path?
From: Alex Riesen @ 2008-07-25 9:40 UTC (permalink / raw)
To: git
The thing has at least this problem: is not passed to upload-pack when
running fetch. So upload-pack, everything past it gets called either
from GIT_EXEC_PATH (which usually is not set) or from builtin exec
path (and that's annoying when debugging for instance index-pack).
The feature has a stable alternative ($GIT_EXEC_PATH) anyway.
Or maybe just replace the whole argv_exec_path handling with a plain
setenv("GIT_EXEC_PATH", exec_path, 1)?
^ permalink raw reply
* Re: git rebase to move a batch of patches onto the current branch
From: Daniel Barkalow @ 2008-07-25 19:16 UTC (permalink / raw)
To: Avery Pennarun; +Cc: Alex Riesen, Git Mailing List
In-Reply-To: <32541b130807241342h483169d7we955512879075161@mail.gmail.com>
On Thu, 24 Jul 2008, Avery Pennarun wrote:
> On 7/24/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> > Avery Pennarun, Thu, Jul 24, 2008 22:16:06 +0200:
> > > On 7/24/08, Alex Riesen <raa.lkml@gmail.com> wrote:
> >
> > > > gcp3 ()
> > > > {
> > > > git format-patch -k --stdout --full-index "$@" | git am -k -3 --binary
> > > > }
> > >
> > > But that'll give up when there are conflicts, right? git-rebase lets
> > > me fix them in a nice way.
> >
> > No, it same as in rebase. You'll fix them and do "git am --resolved".
> > See manpage of git am.
>
> Hmm, cool.
>
> So that command isn't too easy to come upon by accident. If I wanted
> to submit a patch to make this process a bit more obvious, would it
> make sense to simply have git-cherry-pick call that sequence when you
> give it more than one commit?
Before terribly long, we'll have "git sequencer", which should be easy to
get to do the "rebase -i" thing with cherry-pick-style usage (somebody
would just need to write code to generate the correct series of pick
statements).
-Daniel
*This .sig left intentionally blank*
^ permalink raw reply
* Re: [PATCH] Set TAR in t/Makefile and in t4116-apply-reverse.sh
From: Stephan Beyer @ 2008-07-25 18:58 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Brandon Casey, git
In-Reply-To: <7vmyk5sska.fsf@gitster.siamese.dyndns.org>
Junio C Hamano wrote:
> Stephan Beyer <s-beyer@gmx.net> writes:
> >> diff --git a/Makefile b/Makefile
> >> index b003e3e..1d14209 100644
> >> --- a/Makefile
> >> +++ b/Makefile
> >> @@ -1212,6 +1212,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
> >>
> >> GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPTIONS
> >> @echo SHELL_PATH=\''$(SHELL_PATH_SQ)'\' >$@
> >> + @echo TAR=\''$(subst ','\'',$(TAR))'\' >>$@
> >>
> >> ### Detect Tck/Tk interpreter path changes
> >> ifndef NO_TCLTK
> >
> > But then TAR has to be set in test-lib.sh also, to be able to
> > invoke t5000 and t4116 directly, hasn't it?
>
> Dosen't test-lib source GIT-BUILD-OPTIONS?
It does. Great, then.
Regards.
--
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
^ permalink raw reply
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