* [PATCH RFC] builtin-push: add --delete as syntactic sugar for :foo
From: Jan Krüger @ 2009-11-09 12:09 UTC (permalink / raw)
To: Git ML
Refspecs without a source side have been reported as confusing by many.
As an alternative, this adds support for commands like:
git push origin --delete somebranch
Specifically, --delete will prepend a colon to all colon-less refspecs
given on the command line.
Signed-off-by: Jan Krüger <jk@jk.gs>
---
Since I consider this extension pure syntactic sugar, it doesn't change
the underlying transport code. As such it's a relatively non-invasive
change.
One might imagine a different implementation that supports combining
--delete with --all and/or --tags, but perhaps it's better if people
are forced to do that kind of thing manually.
builtin-push.c | 15 +++++++++++++++
t/t5516-fetch-push.sh | 6 ++++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/builtin-push.c b/builtin-push.c
index 8631c06..4ae9166 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -15,6 +15,7 @@ static const char * const push_usage[] = {
};
static int thin;
+static int deleterefs;
static const char *receivepack;
static const char **refspec;
@@ -44,6 +45,14 @@ static void set_refspecs(const char **refs, int nr)
strcat(tag, refs[i]);
ref = tag;
}
+ if (deleterefs && !strchr(ref, ':')) {
+ char *delref;
+ int len = strlen(refs[i] + 1);
+ delref = xmalloc(len);
+ strcpy(delref, ":");
+ strcat(delref, refs[i]);
+ ref = delref;
+ }
add_refspec(ref);
}
}
@@ -181,6 +190,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
OPT_BIT( 0 , "all", &flags, "push all refs", TRANSPORT_PUSH_ALL),
OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
(TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
+ OPT_BOOLEAN( 0, "delete", &deleterefs, "delete refs"),
OPT_BOOLEAN( 0 , "tags", &tags, "push tags (can't be used with --all or --mirror)"),
OPT_BIT('n' , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
OPT_BIT( 0, "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
@@ -193,6 +203,11 @@ int cmd_push(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, push_usage, 0);
+ if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
+ die("--delete is incompatible with --all, --mirror and --tags");
+ if (deleterefs && argc < 2)
+ die("--delete doesn't make sense without any refs");
+
if (tags)
add_refspec("refs/tags/*");
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 6889a53..aa1450a 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -546,6 +546,12 @@ test_expect_success 'allow deleting an invalid remote ref' '
'
+test_expect_success 'allow deleting a ref using --delete' '
+ mk_test heads/master &&
+ git push testrepo --delete master &&
+ (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
+'
+
test_expect_success 'warn on push to HEAD of non-bare repository' '
mk_test heads/master
(cd testrepo &&
--
1.6.5.2.155.gbb47.dirty
^ permalink raw reply related
* Re: pulling git -- version confusion
From: Rustom Mody @ 2009-11-09 13:24 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: git
In-Reply-To: <fabb9a1e0911082351o326b205aic205552faae4e4da@mail.gmail.com>
On Mon, Nov 9, 2009 at 1:21 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> On Mon, Nov 9, 2009 at 08:45, Rustom Mody <rustompmody@gmail.com> wrote:
>> Gives me
>> fatal: ambiguous argument 'origin/master': unknown revision or path
>> not in the working tree.
>> Use '--' to separate paths from revisions
>
> Well, as what remote do you have upstream configured?
>
> What is the output of
> $ git config -l
gives me
core.safecrlf=true
user.email=<my email>
user.name=<my name>
core.repositoryformatversion=0
core.filemode=true
gui.geometry=885x450+0+27 207 192
So theres no remote?
But .git/remotes/origin has
URL: git://git.kernel.org/pub/scm/git/git.git
Pull: refs/heads/master:refs/heads/origin
Pull: refs/heads/maint:refs/heads/maint
Pull: refs/heads/next:refs/heads/next
Pull: refs/heads/html:refs/heads/html
Pull: refs/heads/pu:refs/heads/pu
Pull: refs/heads/todo:refs/heads/todo
Pull: refs/heads/man:refs/heads/man
Also [I just tried this] if I make a fresh repo directly and then do a git pull
it gives a fatal: where do you want to fetch from
But with the git repo pull (seems to be) pulling all sorts of stuff
and not erroring out.
^ permalink raw reply
* Re: [PATCH v2] Show usage string for 'git http-push -h'
From: Tay Ray Chuan @ 2009-11-09 13:56 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: Git Mailing List, Junio C Hamano
In-Reply-To: <20091109104732.GA15519@progeny.tock>
Hi,
On Mon, Nov 9, 2009 at 6:47 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> (I was making sure "git http-push -h" would work without a git
> directory by putting the check for -h before setup_git_directory().
> But nothing in the argv loop requires a git repository, so it is
> better and simpler to move the setup_git_directory() call to after the
> loop. Thanks for the catch.)
Actually, I didn't notice the removal of the "is in a git directory
for -h" requirement; I was only looking at the argument mix.
Thanks.
Acked-by: Tay Ray Chuan <rctay89@gmail.com>
--
Cheers,
Ray Chuan
^ permalink raw reply
* Re: Git drawbacks?
From: Jacob Helwig @ 2009-11-09 14:34 UTC (permalink / raw)
To: Dmitry Smirnov; +Cc: git
In-Reply-To: <loom.20091109T084539-720@post.gmane.org>
On Sun, Nov 8, 2009 at 23:53, Dmitry Smirnov <divis1969@gmail.com> wrote:
> <david <at> lang.hm> writes:
>
>> going back to the initial poster's comments. if the android repo is 1G,
>> eliminating the history will probably have significantly less impact than
>> you expect it to.
>
> Do you have 2 or more copies of the same repository at the same time?
> If yes, can I skip cloning new copy from network?
> Or even skip cloning it at all?
> Is it possible with Git to chekout into two (few) working trees?
>
Take a look at git-new-workdir. It's in the contrib directory of
git.git. This lets you skip re-cloning the same repository over
again, if you want a new working copy of it. It'll also give you some
space savings, by sharing certain key things in the .git directory
between working copies, by using symlinks.
It does have a few caveats, however. If you have the same branch
checked out in two different working copies created using
git-new-workdir, and update the branch in one of them, then the other
will appear to have a bunch of staged changes, even though you haven't
done anything in it. The branch pointer will have been updated out
from underneath it, and it will be "confused". As long as you
remember not to update a branch that is checked out in more than one
place on your machine, you'll never notice, thuogh.
^ permalink raw reply
* [PATCH 00/24] Let 'git <command> -h' show usage without a git dir
From: Jonathan Nieder @ 2009-11-09 15:02 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091108110341.GA23737@progeny.tock>
Junio C Hamano wrote:
> So I think the right approach is something like how you handled http-push;
> namely, check if the sole argument is "-h", and if so show help and exit.
I took a more aggressive approach with some commands. As long as it
was obviously safe and not too complicated to implement, I let -h work
wherever other options work.
Tested with
git_home=$(pwd)
while read a b
do
cmd=${a#git-}
test "$cmd" = "$a" && continue
echo "$cmd"
( cd /tmp && "$git_home/git" "$cmd" -h 2>&1 | head -1 )
done |
less
and the test suite.
Thoughts?
Jonathan Nieder (24):
Retire fetch--tool helper to contrib/examples
Show usage string for 'git grep -h'
Show usage string for 'git cherry -h'
Show usage string for 'git commit-tree -h'
Show usage string for 'git merge-ours -h'
Show usage string for 'git show-ref -h'
check-ref-format: update usage string
Show usage string for 'git check-ref-format -h'
Show usage string for 'git fast-import -h'
Show usage string for 'git get-tar-commit-id -h'
Show usage string for 'git imap-send -h'
Show usage string for 'git mailsplit -h'
Show usage string for 'git merge-one-file -h'
Show usage string for 'git rev-parse -h'
Show usage string for 'git show-index -h'
Show usage string for 'git unpack-file -h'
Show usage string for 'git stripspace -h'
merge: do not setup worktree twice
Let 'git http-fetch -h' show usage outside any git repository
http-fetch: add missing initialization of argv0_path
Let 'git <command> -h' show usage without a git dir
Let usage() take a printf-style format
merge-{recursive,subtree}: use usage() to print usage
diff --no-index: make the usage string less scary
Documentation/git-show-ref.txt | 3 +-
Makefile | 1 -
builtin-check-ref-format.c | 9 +++++++-
builtin-commit-tree.c | 2 +-
builtin-grep.c | 7 ++++++
builtin-log.c | 9 ++++++++
builtin-mailsplit.c | 2 +
builtin-merge-ours.c | 6 +++++
builtin-merge-recursive.c | 2 +-
builtin-merge.c | 1 -
builtin-mv.c | 8 +++---
builtin-read-tree.c | 4 +-
builtin-reflog.c | 3 ++
builtin-rerere.c | 3 ++
builtin-rev-parse.c | 10 +++++++++
builtin-show-ref.c | 10 +++++++-
builtin-stripspace.c | 4 ++-
builtin-tar-tree.c | 6 +++++
builtin.h | 1 -
.../examples/builtin-fetch--tool.c | 0
diff-no-index.c | 2 +-
fast-import.c | 3 ++
git-compat-util.h | 2 +-
git-merge-one-file.sh | 12 ++++++++++
git.c | 22 ++++++++++---------
http-fetch.c | 21 ++++++++++++------
imap-send.c | 5 ++++
index-pack.c | 3 ++
pack-redundant.c | 3 ++
show-index.c | 5 ++++
unpack-file.c | 2 +-
usage.c | 14 ++++++++----
32 files changed, 143 insertions(+), 42 deletions(-)
rename builtin-fetch--tool.c => contrib/examples/builtin-fetch--tool.c (100%)
^ permalink raw reply
* [PATCH 01/24] Retire fetch--tool helper to contrib/examples
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
When git-fetch was builtin-ized, the previous script was moved to
contrib/examples. Now, it is the sole remaining user for
'git fetch--tool'.
The fetch--tool code is still worth keeping around so people can
try out the old git-fetch.sh, for example when investigating
regressions from the builtinifaction.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
See also <http://thread.gmane.org/gmane.comp.version-control.git/65122/focus=65191>.
Makefile | 1 -
builtin.h | 1 -
.../examples/builtin-fetch--tool.c | 0
git.c | 1 -
4 files changed, 0 insertions(+), 3 deletions(-)
rename builtin-fetch--tool.c => contrib/examples/builtin-fetch--tool.c (100%)
diff --git a/Makefile b/Makefile
index 5d5976f..c0ba479 100644
--- a/Makefile
+++ b/Makefile
@@ -601,7 +601,6 @@ BUILTIN_OBJS += builtin-diff-index.o
BUILTIN_OBJS += builtin-diff-tree.o
BUILTIN_OBJS += builtin-diff.o
BUILTIN_OBJS += builtin-fast-export.o
-BUILTIN_OBJS += builtin-fetch--tool.o
BUILTIN_OBJS += builtin-fetch-pack.o
BUILTIN_OBJS += builtin-fetch.o
BUILTIN_OBJS += builtin-fmt-merge-msg.o
diff --git a/builtin.h b/builtin.h
index a2174dc..c3f83c0 100644
--- a/builtin.h
+++ b/builtin.h
@@ -48,7 +48,6 @@ extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
extern int cmd_fast_export(int argc, const char **argv, const char *prefix);
extern int cmd_fetch(int argc, const char **argv, const char *prefix);
extern int cmd_fetch_pack(int argc, const char **argv, const char *prefix);
-extern int cmd_fetch__tool(int argc, const char **argv, const char *prefix);
extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
extern int cmd_for_each_ref(int argc, const char **argv, const char *prefix);
extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
diff --git a/builtin-fetch--tool.c b/contrib/examples/builtin-fetch--tool.c
similarity index 100%
rename from builtin-fetch--tool.c
rename to contrib/examples/builtin-fetch--tool.c
diff --git a/git.c b/git.c
index bd2c5fe..f295561 100644
--- a/git.c
+++ b/git.c
@@ -304,7 +304,6 @@ static void handle_internal_command(int argc, const char **argv)
{ "fast-export", cmd_fast_export, RUN_SETUP },
{ "fetch", cmd_fetch, RUN_SETUP },
{ "fetch-pack", cmd_fetch_pack, RUN_SETUP },
- { "fetch--tool", cmd_fetch__tool, RUN_SETUP },
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
{ "for-each-ref", cmd_for_each_ref, RUN_SETUP },
{ "format-patch", cmd_format_patch, RUN_SETUP },
--
1.6.5.2
^ permalink raw reply related
* [PATCH 02/24] Show usage string for 'git grep -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Junio C Hamano
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Clarification: the following description only talks about "git
grep -h" without any other options and arguments.
Such a change cannot be breaking backward compatibility. "grep
-h" cannot be asking for suppressing filenames, as there is no
match pattern specified.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin-grep.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index 1df25b0..01be9bf 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -788,6 +788,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
OPT_END()
};
+ /*
+ * 'git grep -h', unlike 'git grep -h <pattern>', is a request
+ * to show usage information and exit.
+ */
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage_with_options(grep_usage, options);
+
memset(&opt, 0, sizeof(opt));
opt.prefix = prefix;
opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
--
1.6.5.2
^ permalink raw reply related
* [PATCH 04/24] Show usage string for 'git commit-tree -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Treat an "-h" option as a request for help, rather than a "Not a
valid object name" error.
"commit-tree -h" could be asking to create a new commit from a
treeish named "-h". Strictly speaking, such a pathological ref
name is possible, but the user would have to had said something
like "tags/-h" to name such a pathological already. commit-tree
is usually used in scripts with raw object ids, anyway.
For consistency, the "-h" option uses its new meaning even if
followed by other arguments.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-commit-tree.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c
index 6467077..ddcb7a4 100644
--- a/builtin-commit-tree.c
+++ b/builtin-commit-tree.c
@@ -105,7 +105,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
- if (argc < 2)
+ if (argc < 2 || !strcmp(argv[1], "-h"))
usage(commit_tree_usage);
if (get_sha1(argv[1], tree_sha1))
die("Not a valid object name %s", argv[1]);
--
1.6.5.2
^ permalink raw reply related
* [PATCH 05/24] Show usage string for 'git merge-ours -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
This change is strictly about 'git merge-ours -h' without
any other options and arguments.
This change cannot break compatibility since merge drivers are
always passed '--', among other arguments.
Any usage string for this command is a lie, since it ignored its
arguments until now. Still, it makes sense to let the user know
the expected usage when asked.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-merge-ours.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/builtin-merge-ours.c b/builtin-merge-ours.c
index 8f5bbaf..6844116 100644
--- a/builtin-merge-ours.c
+++ b/builtin-merge-ours.c
@@ -10,6 +10,9 @@
#include "git-compat-util.h"
#include "builtin.h"
+static const char builtin_merge_ours_usage[] =
+ "git merge-ours <base>... -- HEAD <remote>...";
+
static const char *diff_index_args[] = {
"diff-index", "--quiet", "--cached", "HEAD", "--", NULL
};
@@ -17,6 +20,9 @@ static const char *diff_index_args[] = {
int cmd_merge_ours(int argc, const char **argv, const char *prefix)
{
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(builtin_merge_ours_usage);
+
/*
* We need to exit with 2 if the index does not match our HEAD tree,
* because the current index is what we will be committing as the
--
1.6.5.2
^ permalink raw reply related
* [PATCH 09/24] Show usage string for 'git fast-import -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Shawn O. Pearce
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Let "git fast-import -h" (with no other arguments) print usage
before exiting, even when run outside any repository.
Cc: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
fast-import.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 6faaaac..f4f1de6 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2405,6 +2405,9 @@ int main(int argc, const char **argv)
git_extract_argv0_path(argv[0]);
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(fast_import_usage);
+
setup_git_directory();
git_config(git_pack_config, NULL);
if (!pack_compression_seen && core_compression_seen)
--
1.6.5.2
^ permalink raw reply related
* [PATCH 10/24] Show usage string for 'git get-tar-commit-id -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-tar-tree.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 8b3a35e..3f1e701 100644
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
@@ -11,6 +11,9 @@ static const char tar_tree_usage[] =
"git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
"*** Note that this command is now deprecated; use \"git archive\" instead.";
+static const char builtin_get_tar_commit_id_usage[] =
+"git get-tar-commit-id < <tarfile>";
+
int cmd_tar_tree(int argc, const char **argv, const char *prefix)
{
/*
@@ -81,6 +84,9 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
char *content = buffer + RECORDSIZE;
ssize_t n;
+ if (argc != 1)
+ usage(builtin_get_tar_commit_id_usage);
+
n = read_in_full(0, buffer, HEADERSIZE);
if (n < HEADERSIZE)
die("git get-tar-commit-id: read error");
--
1.6.5.2
^ permalink raw reply related
* [PATCH 11/24] Show usage string for 'git imap-send -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
imap-send.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 3847fd1..04e5374 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -93,6 +93,8 @@ struct msg_data {
unsigned int crlf:1;
};
+static const char imap_send_usage[] = "git imap-send < <mbox>";
+
#define DRV_OK 0
#define DRV_MSG_BAD -1
#define DRV_BOX_BAD -2
@@ -1491,6 +1493,9 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
+ if (argc != 1)
+ usage(imap_send_usage);
+
/* init the random number generator */
arc4_init();
--
1.6.5.2
^ permalink raw reply related
* [PATCH 13/24] Show usage string for 'git merge-one-file -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
git-merge-one-file.sh | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh
index 9c2c1b7..d067894 100755
--- a/git-merge-one-file.sh
+++ b/git-merge-one-file.sh
@@ -16,6 +16,18 @@
# been handled already by git read-tree, but that one doesn't
# do any merges that might change the tree layout.
+USAGE='<orig blob> <our blob> <their blob> <path>'
+USAGE="$USAGE <orig mode> <our mode> <their mode>"
+LONG_USAGE="Usage: git merge-one-file $USAGE
+
+Blob ids and modes should be empty for missing files."
+
+if ! test "$#" -eq 7
+then
+ echo "$LONG_USAGE"
+ exit 1
+fi
+
case "${1:-.}${2:-.}${3:-.}" in
#
# Deleted in both or deleted in one and unchanged in the other
--
1.6.5.2
^ permalink raw reply related
* [PATCH 12/24] Show usage string for 'git mailsplit -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-mailsplit.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c
index dfe5b15..207e358 100644
--- a/builtin-mailsplit.c
+++ b/builtin-mailsplit.c
@@ -231,6 +231,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
continue;
} else if ( arg[1] == 'f' ) {
nr = strtol(arg+2, NULL, 10);
+ } else if ( arg[1] == 'h' ) {
+ usage(git_mailsplit_usage);
} else if ( arg[1] == 'b' && !arg[2] ) {
allow_bare = 1;
} else if (!strcmp(arg, "--keep-cr")) {
--
1.6.5.2
^ permalink raw reply related
* [PATCH 16/24] Show usage string for 'git unpack-file -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
"unpack-file -h" could be asking to save the contents of a blob
named "-h". Strictly speaking, such a pathological ref name is
possible, but the user would have to had said something like
"tags/-h" to name such a pathological ref already. When used in
scripts, unpack-file is typically not passed a user-supplied tag
name directly.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
unpack-file.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/unpack-file.c b/unpack-file.c
index ac9cbf7..e9d8934 100644
--- a/unpack-file.c
+++ b/unpack-file.c
@@ -28,7 +28,7 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
- if (argc != 2)
+ if (argc != 2 || !strcmp(argv[1], "-h"))
usage("git unpack-file <sha1>");
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);
--
1.6.5.2
^ permalink raw reply related
* [PATCH 15/24] Show usage string for 'git show-index -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
show-index.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/show-index.c b/show-index.c
index 45bb535..63f9da5 100644
--- a/show-index.c
+++ b/show-index.c
@@ -1,6 +1,9 @@
#include "cache.h"
#include "pack.h"
+static const char show_index_usage[] =
+"git show-index < <packed archive index>";
+
int main(int argc, char **argv)
{
int i;
@@ -8,6 +11,8 @@ int main(int argc, char **argv)
unsigned int version;
static unsigned int top_index[256];
+ if (argc != 1)
+ usage(show_index_usage);
if (fread(top_index, 2 * 4, 1, stdin) != 1)
die("unable to read header");
if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
--
1.6.5.2
^ permalink raw reply related
* [PATCH 18/24] merge: do not setup worktree twice
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Builtins do not need to run setup_worktree() for themselves, since
the builtin machinery runs it for them.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
This matter since '-h' cannot suppress _this_ setup_work_tree()
through the builtin machinery.
builtin-merge.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/builtin-merge.c b/builtin-merge.c
index c69a305..1857138 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -843,7 +843,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
const char *best_strategy = NULL, *wt_strategy = NULL;
struct commit_list **remotes = &remoteheads;
- setup_work_tree();
if (file_exists(git_path("MERGE_HEAD")))
die("You have not concluded your merge. (MERGE_HEAD exists)");
if (read_cache_unmerged())
--
1.6.5.2
^ permalink raw reply related
* [PATCH 19/24] Let 'git http-fetch -h' show usage outside any git repository
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Delay search for a git directory until option parsing has finished.
None of the functions used in option parsing look for or read any
files other than stdin, so this is safe.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
http-fetch.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/http-fetch.c b/http-fetch.c
index e8f44ba..52a4f6d 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1,6 +1,10 @@
#include "cache.h"
+#include "exec_cmd.h"
#include "walker.h"
+static const char http_fetch_usage[] = "git http-fetch "
+"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url";
+
int main(int argc, const char **argv)
{
const char *prefix;
@@ -19,10 +23,6 @@ int main(int argc, const char **argv)
int get_verbosely = 0;
int get_recover = 0;
- prefix = setup_git_directory();
-
- git_config(git_default_config, NULL);
-
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') {
get_tree = 1;
@@ -37,6 +37,8 @@ int main(int argc, const char **argv)
} else if (argv[arg][1] == 'w') {
write_ref = &argv[arg + 1];
arg++;
+ } else if (argv[arg][1] == 'h') {
+ usage(http_fetch_usage);
} else if (!strcmp(argv[arg], "--recover")) {
get_recover = 1;
} else if (!strcmp(argv[arg], "--stdin")) {
@@ -44,10 +46,8 @@ int main(int argc, const char **argv)
}
arg++;
}
- if (argc < arg + 2 - commits_on_stdin) {
- usage("git http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
- return 1;
- }
+ if (argc != arg + 2 - commits_on_stdin)
+ usage(http_fetch_usage);
if (commits_on_stdin) {
commits = walker_targets_stdin(&commit_id, &write_ref);
} else {
@@ -55,6 +55,11 @@ int main(int argc, const char **argv)
commits = 1;
}
url = argv[arg];
+
+ prefix = setup_git_directory();
+
+ git_config(git_default_config, NULL);
+
if (url && url[strlen(url)-1] != '/') {
rewritten_url = xmalloc(strlen(url)+2);
strcpy(rewritten_url, url);
--
1.6.5.2
^ permalink raw reply related
* [PATCH 20/24] http-fetch: add missing initialization of argv0_path
From: Jonathan Nieder @ 2009-11-09 15:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
http-fetch.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/http-fetch.c b/http-fetch.c
index 52a4f6d..ffd0ad7 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -23,6 +23,8 @@ int main(int argc, const char **argv)
int get_verbosely = 0;
int get_recover = 0;
+ git_extract_argv0_path(argv[0]);
+
while (arg < argc && argv[arg][0] == '-') {
if (argv[arg][1] == 't') {
get_tree = 1;
--
1.6.5.2
^ permalink raw reply related
* [PATCH 21/24] Let 'git <command> -h' show usage without a git dir
From: Jonathan Nieder @ 2009-11-09 15:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
There is no need for "git <command> -h" to depend on being inside
a repository.
Reported by Gerfried Fuchs through http://bugs.debian.org/462557
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-log.c | 6 ++++++
builtin-mv.c | 8 ++++----
builtin-read-tree.c | 4 ++--
builtin-reflog.c | 3 +++
builtin-rerere.c | 3 +++
git.c | 21 ++++++++++++---------
index-pack.c | 3 +++
pack-redundant.c | 3 +++
8 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 5248507..a0fa30c 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -50,6 +50,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
if (default_date_mode)
rev->date_mode = parse_date_format(default_date_mode);
+ /*
+ * Check for -h before setup_revisions(), or "git log -h" will
+ * fail when run without a git directory.
+ */
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(builtin_log_usage);
argc = setup_revisions(argc, argv, rev, "HEAD");
if (rev->diffopt.pickaxe || rev->diffopt.filter)
diff --git a/builtin-mv.c b/builtin-mv.c
index 1b20028..f633d81 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -64,15 +64,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);
- newfd = hold_locked_index(&lock_file, 1);
- if (read_cache() < 0)
- die("index file corrupt");
-
argc = parse_options(argc, argv, prefix, builtin_mv_options,
builtin_mv_usage, 0);
if (--argc < 1)
usage_with_options(builtin_mv_usage, builtin_mv_options);
+ newfd = hold_locked_index(&lock_file, 1);
+ if (read_cache() < 0)
+ die("index file corrupt");
+
source = copy_pathspec(prefix, argv, argc, 0);
modes = xcalloc(argc, sizeof(enum update_mode));
dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 14c836b..2a3a32c 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -108,11 +108,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
git_config(git_default_config, NULL);
- newfd = hold_locked_index(&lock_file, 1);
-
argc = parse_options(argc, argv, unused_prefix, read_tree_options,
read_tree_usage, 0);
+ newfd = hold_locked_index(&lock_file, 1);
+
prefix_set = opts.prefix ? 1 : 0;
if (1 < opts.merge + opts.reset + prefix_set)
die("Which one? -m, --reset, or --prefix?");
diff --git a/builtin-reflog.c b/builtin-reflog.c
index e23b5ef..7498210 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -698,6 +698,9 @@ static const char reflog_usage[] =
int cmd_reflog(int argc, const char **argv, const char *prefix)
{
+ if (argc > 1 && !strcmp(argv[1], "-h"))
+ usage(reflog_usage);
+
/* With no command, we default to showing it. */
if (argc < 2 || *argv[1] == '-')
return cmd_log_reflog(argc, argv, prefix);
diff --git a/builtin-rerere.c b/builtin-rerere.c
index adfb7b5..343d6cd 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -106,6 +106,9 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
if (argc < 2)
return rerere();
+ if (!strcmp(argv[1], "-h"))
+ usage(git_rerere_usage);
+
fd = setup_rerere(&merge_rr);
if (fd < 0)
return 0;
diff --git a/git.c b/git.c
index f295561..743ee57 100644
--- a/git.c
+++ b/git.c
@@ -229,21 +229,24 @@ struct cmd_struct {
static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
{
- int status;
+ int status, help;
struct stat st;
const char *prefix;
prefix = NULL;
- if (p->option & RUN_SETUP)
- prefix = setup_git_directory();
-
- if (use_pager == -1 && p->option & RUN_SETUP)
- use_pager = check_pager_config(p->cmd);
- if (use_pager == -1 && p->option & USE_PAGER)
- use_pager = 1;
+ help = argc == 2 && !strcmp(argv[1], "-h");
+ if (!help) {
+ if (p->option & RUN_SETUP)
+ prefix = setup_git_directory();
+
+ if (use_pager == -1 && p->option & RUN_SETUP)
+ use_pager = check_pager_config(p->cmd);
+ if (use_pager == -1 && p->option & USE_PAGER)
+ use_pager = 1;
+ }
commit_pager_choice();
- if (p->option & NEED_WORK_TREE)
+ if (!help && p->option & NEED_WORK_TREE)
setup_work_tree();
trace_argv_printf(argv, "trace: built-in: git");
diff --git a/index-pack.c b/index-pack.c
index b4f8278..190f372 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -882,6 +882,9 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(index_pack_usage);
+
/*
* We wish to read the repository's config file if any, and
* for that it is necessary to call setup_git_directory_gently().
diff --git a/pack-redundant.c b/pack-redundant.c
index 69a7ab2..21c61db 100644
--- a/pack-redundant.c
+++ b/pack-redundant.c
@@ -603,6 +603,9 @@ int main(int argc, char **argv)
git_extract_argv0_path(argv[0]);
+ if (argc == 2 && !strcmp(argv[1], "-h"))
+ usage(pack_redundant_usage);
+
setup_git_directory();
for (i = 1; i < argc; i++) {
--
1.6.5.2
^ permalink raw reply related
* [PATCH 23/24] merge-{recursive,subtree}: use usage() to print usage
From: Jonathan Nieder @ 2009-11-09 15:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Usage messages (for example, from "git merge-recursive -h") are
friendlier when not preceded by "fatal".
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-merge-recursive.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c
index d26a96e..add5900 100644
--- a/builtin-merge-recursive.c
+++ b/builtin-merge-recursive.c
@@ -33,7 +33,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
}
if (argc < 4)
- die("Usage: %s <base>... -- <head> <remote> ...", argv[0]);
+ usage("%s <base>... -- <head> <remote> ...", argv[0]);
for (i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "--"))
--
1.6.5.2
^ permalink raw reply related
* [PATCH 22/24] Let usage() take a printf-style format
From: Jonathan Nieder @ 2009-11-09 15:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
merge-recursive and diff --no-index are not able to use usage()
because their usage strings depend on the circumstances in which
they are called.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
git-compat-util.h | 2 +-
usage.c | 14 +++++++++-----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index ef60803..42048e7 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -188,7 +188,7 @@ extern char *gitbasename(char *);
#include "compat/bswap.h"
/* General helper functions */
-extern NORETURN void usage(const char *err);
+extern NORETURN void usage(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
diff --git a/usage.c b/usage.c
index c488f3a..f6d9ff5 100644
--- a/usage.c
+++ b/usage.c
@@ -12,9 +12,9 @@ static void report(const char *prefix, const char *err, va_list params)
fprintf(stderr, "%s%s\n", prefix, msg);
}
-static NORETURN void usage_builtin(const char *err)
+static NORETURN void usage_builtin(const char *err, va_list params)
{
- fprintf(stderr, "usage: %s\n", err);
+ report("usage: ", err, params);
exit(129);
}
@@ -36,7 +36,7 @@ static void warn_builtin(const char *warn, va_list params)
/* If we are in a dlopen()ed .so write to a global variable would segfault
* (ugh), so keep things static. */
-static NORETURN_PTR void (*usage_routine)(const char *err) = usage_builtin;
+static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = usage_builtin;
static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin;
static void (*error_routine)(const char *err, va_list params) = error_builtin;
static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
@@ -46,9 +46,13 @@ void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list param
die_routine = routine;
}
-void usage(const char *err)
+void usage(const char *err, ...)
{
- usage_routine(err);
+ va_list params;
+
+ va_start(params, err);
+ usage_routine(err, params);
+ va_end(params);
}
void die(const char *err, ...)
--
1.6.5.2
^ permalink raw reply related
* [PATCH 24/24] diff --no-index: make the usage string less scary
From: Jonathan Nieder @ 2009-11-09 15:05 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Start the diff --no-index usage string with "usage:" instead of
"fatal:".
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff-no-index.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 4ebc1db..a1f6fdf 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -201,7 +201,7 @@ void diff_no_index(struct rev_info *revs,
return;
}
if (argc != i + 2)
- die("git diff %s takes two paths",
+ usage("git diff %s <path> <path>",
no_index ? "--no-index" : "[--no-index]");
diff_setup(&revs->diffopt);
--
1.6.5.2
^ permalink raw reply related
* [PATCH 14/24] Show usage string for 'git rev-parse -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-rev-parse.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 45bead6..24ee8b3 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -426,6 +426,13 @@ static void die_no_single_rev(int quiet)
die("Needed a single revision");
}
+static const char builtin_rev_parse_usage[] =
+"git rev-parse --parseopt [options] -- [<args>...]\n"
+" or: git rev-parse --sq-quote [<arg>...]\n"
+" or: git rev-parse [options] [<arg>...]\n"
+"\n"
+"Run \"git rev-parse --parseopt -h\" for more information on the first usage.";
+
int cmd_rev_parse(int argc, const char **argv, const char *prefix)
{
int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
@@ -438,6 +445,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
if (argc > 1 && !strcmp("--sq-quote", argv[1]))
return cmd_sq_quote(argc - 2, argv + 2);
+ if (argc > 1 && !strcmp("-h", argv[1]))
+ usage(builtin_rev_parse_usage);
+
prefix = setup_git_directory();
git_config(git_default_config, NULL);
for (i = 1; i < argc; i++) {
--
1.6.5.2
^ permalink raw reply related
* [PATCH 03/24] Show usage string for 'git cherry -h'
From: Jonathan Nieder @ 2009-11-09 15:04 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <20091109150235.GA23871@progeny.tock>
Treat an "-h" option as a request for help, rather than an
"Unknown commit -h" error.
"cherry -h" could be asking to compare histories that leads to
our HEAD and a commit that can be named as "-h". Strictly
speaking, that may be a valid refname, but the user would have to
say something like "tags/-h" to name such a pathological ref
already, so it is not such a big deal.
The "-h" option keeps its meaning even if preceded by other
options or followed by other arguments. This keeps the
command-line syntax closer to what parse_options would give and
supports shell aliases like 'alias cherry="git cherry -v"' a
little better.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
builtin-log.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 207a361..5248507 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -1237,6 +1237,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
argv++;
}
+ if (argc > 1 && !strcmp(argv[1], "-h"))
+ usage(cherry_usage);
+
switch (argc) {
case 4:
limit = argv[3];
--
1.6.5.2
^ 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