Git development
 help / color / mirror / Atom feed
* [PATCH] Make git-send-pack exit with error when some refs couldn't be pushed out
From: Petr Baudis @ 2005-12-14  0:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

In case some refs couldn't be pushed out due to an error (mostly the
not-a-proper-subset error), make git-send-pack exit with non-zero status
after the push is over (that is, it still tries to push out the rest
of the refs).

Cogito (0.17pre only, 0.16 is unaffected) needs to know that the push
failed so that it won't update its remote branch head pointer - otherwise
it gets out of sync, which can lead even to loss of commits on the local
side (this happenned to Jonas Fonseca - thanks for the report, BTW).
I sort of expected that git-send-pack would return an error in case
of a failure, so just applying this should magically fix Cogito.

I don't insist on this particular solution though - a fetch-pack-alike
approach where I get the list of changed refs on stdout is fine too
(currently I get something on stderr, but I'm reluctant to grab stderr
of GIT commands and try to heuristically mangle it).

At any rate, please consider this a major problem from Cogito perspective.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---

 send-pack.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/send-pack.c b/send-pack.c
index f61c15c..6ce0d9f 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -179,6 +179,7 @@ static int send_pack(int in, int out, in
 {
 	struct ref *ref;
 	int new_refs;
+	int ret = 0;
 
 	/* No funny business with the matcher */
 	remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, 1);
@@ -232,6 +233,7 @@ static int send_pack(int in, int out, in
 				error("remote '%s' object %s does not "
 				      "exist on local",
 				      ref->name, sha1_to_hex(ref->old_sha1));
+				ret = -2;
 				continue;
 			}
 
@@ -245,12 +247,14 @@ static int send_pack(int in, int out, in
 				error("remote ref '%s' is not a strict "
 				      "subset of local ref '%s'.", ref->name,
 				      ref->peer_ref->name);
+				ret = -2;
 				continue;
 			}
 		}
 		memcpy(ref->new_sha1, ref->peer_ref->new_sha1, 20);
 		if (is_zero_sha1(ref->new_sha1)) {
 			error("cannot happen anymore");
+			ret = -3;
 			continue;
 		}
 		new_refs++;
@@ -267,7 +271,7 @@ static int send_pack(int in, int out, in
 	if (new_refs)
 		pack_objects(out, remote_refs);
 	close(out);
-	return 0;
+	return ret;
 }
 
 

^ permalink raw reply related

* Re: git-merge fails when trying to merge from a tag
From: Carl Baldwin @ 2005-12-14  0:00 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <7vy82o951s.fsf@assigned-by-dhcp.cox.net>

On Tue, Dec 13, 2005 at 11:21:19AM -0800, Junio C Hamano wrote:
> Carl Baldwin <cnb@fc.hp.com> writes:
> 
> > I just tried to merge using a tag object.
> 
> Thanks for the report.
> 
> > % git merge "Merging release-0.3.1" HEAD refs/tags/release-0.3.1
> 
> Once I considered changing commit-tree to take any committish
> after -p, but thought the command is a low level primitive and
> the user should know what he is doing, but apparently, git-merge
> does not know what it is doing ;-).
> 
> In fact, I never use "merge" myself, and haven't noticed this
> breakage until now (you would notice that the Everyday document
> never talks about "git merge").  Instead, I always do this:
> 
> 	$ git pull . tag release-0.3.1

I've done this also.  Personally, I feel a little more in control with a
fetch, merge, tag type of flow.  Maybe its just me but I couldn't get
used to pull doing it all for me so I like to split the operation so
that I can easily run a diff-tree between the two if I want after
performing the fetch.

While we're on the subject.  It might be nice if merge behaved a little
more like pull (without the fetch of course).  At the moment, I've got
to give merge three arguments whereas pull is happy with just one of
them.

So, sometimes I would like to type this
% git merge <head>

much like one would type
% git pull . <head>

Rather than typing
% git merge "Message" HEAD <head>

But, this might not be an easy API change to make.  I suppose I could
just type 'git pull . <head>' and be satisfied but my thought process
tells be that I'm merging branches rather than pulling so I usually
don't think about it.  I'm really just typing my stream of thought at
this point so I'll wrap it up.

Thanks,
Carl

> But you are right.  It is advertised as the end-user
> command and demonstrated in the tutorial.
> 
> How about this patch?  I haven't looked at what (old)
> git-resolve and git-octopus commands do --- they may need
> similar parameter massaging.
> 
> -- >8 --
> [PATCH] allow merging any committish
> 
> Although "git-merge" is advertised as the end-user level command
> (instead of being a "git-pull" backend), it was not prepared to
> take tag objects that point at commits and barfed when fed one.
> Sanitize the input while we validate them, for which we already
> have a loop.
> 
> Signed-off-by: Junio C Hamano <junkio@cox.net>
> ---
> diff --git a/git-merge.sh b/git-merge.sh
> index a221daa..d25ae4b 100755
> --- a/git-merge.sh
> +++ b/git-merge.sh
> @@ -97,11 +97,14 @@ head=$(git-rev-parse --verify "$1"^0) ||
>  shift
>  
>  # All the rest are remote heads
> +remoteheads=
>  for remote
>  do
> -	git-rev-parse --verify "$remote"^0 >/dev/null ||
> +	remotehead=$(git-rev-parse --verify "$remote"^0) ||
>  	    die "$remote - not something we can merge"
> +	remoteheads="${remoteheads}$remotehead "
>  done
> +set x $remoteheads ; shift
>  
>  case "$#" in
>  1)
> 
> 

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

^ permalink raw reply

* [PATCH 6/11] git-cherry: Usage string clean-up, use the 'usage' function
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-cherry.sh |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

a3b435a4c9bbde849dbe1aac1431387d673cf754
diff --git a/git-cherry.sh b/git-cherry.sh
index 867522b..5e9bd0c 100755
--- a/git-cherry.sh
+++ b/git-cherry.sh
@@ -3,11 +3,8 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
-. git-sh-setup
-
-usage="usage: $0 "'[-v] <upstream> [<head>]
-
-             __*__*__*__*__> <upstream>
+USAGE='[-v] <upstream> [<head>]'
+LONG_USAGE='             __*__*__*__*__> <upstream>
             /
   fork-point
             \__+__+__+__+__+__+__+__> <head>
@@ -16,8 +13,8 @@ Each commit between the fork-point and <
 compared against the change each commit between the fork-point and
 <upstream> introduces.  If the change seems to be in the upstream,
 it is shown on the standard output with prefix "+".  Otherwise
-it is shown with prefix "-".
-'
+it is shown with prefix "-".'
+. git-sh-setup
 
 case "$1" in -v) verbose=t; shift ;; esac 
 
@@ -35,7 +32,7 @@ case "$#" in
 2) upstream=`git-rev-parse --verify "$1"` &&
    ours=`git-rev-parse --verify "$2"` || exit
    ;;
-*) echo >&2 "$usage"; exit 1 ;;
+*) usage ;;
 esac
 
 # Note that these list commits in reverse order;
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 7/11] git-fetch: Usage string clean-up, emit usage string at unrecognized option
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-fetch.sh |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

64d3f091f8cfa405ee479f49c4890ae452ac0afd
diff --git a/git-fetch.sh b/git-fetch.sh
index 14ea295..767ca61 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 #
+
+USAGE='<fetch-options> <repository> <refspec>...'
 . git-sh-setup
 . git-parse-remote
 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
@@ -34,6 +36,9 @@ do
 	-v|--verbose)
 		verbose=Yes
 		;;
+	-*)
+		usage
+		;;
 	*)
 		break
 		;;
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 5/11] git-applypatch: Usage string clean-up, emit usage string at incorrect invocation
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-applypatch.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

4aecb38bdf7d1f22bec895d0b3a936ded39bef4d
diff --git a/git-applypatch.sh b/git-applypatch.sh
index a112e1a..214f5c3 100755
--- a/git-applypatch.sh
+++ b/git-applypatch.sh
@@ -10,8 +10,12 @@
 ##	$3 - "info" file with Author, email and subject
 ##	$4 - optional file containing signoff to add
 ##
+
+USAGE='<msg> <patch> <info> [<signoff>]'
 . git-sh-setup
 
+[[ "$#" = "3" || "$#" = "4" ]] || usage
+
 final=.dotest/final-commit
 ##
 ## If this file exists, we ask before applying
-- 
0.99.9.GIT

^ permalink raw reply related

* Re: [ANNOUNCE] Cogito-0.16.1
From: Petr Baudis @ 2005-12-13 22:31 UTC (permalink / raw)
  To: Paul Dickson; +Cc: git
In-Reply-To: <20051213110257.a37be18b.paul@permanentmail.com>

Dear diary, on Tue, Dec 13, 2005 at 07:02:57PM CET, I got a letter
where Paul Dickson <paul@permanentmail.com> said that...
> On Tue, 13 Dec 2005 17:56:45 +0100, Petr Baudis wrote:
> 
> > Dear diary, on Tue, Dec 13, 2005 at 02:26:36AM CET, I got a letter
> > where Paul Dickson <paul@permanentmail.com> said that...
> > > Any chance of man files?  I'm more use to type man than cg-help.
> > 
> > You can make the man files by
> > 
> > 	make doc
> > 
> > and install them by
> > 
> > 	make install-doc
> > 
> > 
> > This isn't done by default so that you won't need asciidoc for the
> > build. This is exactly the same way in GIT.
> 
> See my messages about 0.99.9m and xmlto (and asciidoc).  They are
> currently required for building the RPMs.  Perhaps the spec file needs
> updating.

But the spec file also makes the 'doc' and 'install-doc' targets. When
you act as a packager, asciidoc becomes a reasonable build-time
requirement.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.

^ permalink raw reply

* [PATCH 0/11] Usage string clean-up
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git

Hi,

This is a redone version of the usage string clean-up patch series. It
should apply cleanly on top of the current 'pu' branch.

This version is supposed to get the details right.

The scripts are supposed to set the variable USAGE to some suitable
value before they source git-sh-setup. Optionally they can also set
LONG_USAGE to a more descriptive help message.

* --help makes the scripts print the (long) usage string and exit
  cleanly.
* Unrecognized options prints the usage string and exits non-cleanly.
* The printed string is of the form "Usage: $0 options". The "Usage:
  $0 " part can easily be changed by changing git-sh-setup.sh

The real value of this series is that all commands prints a usage
message when they get '--help'.

I have left *.perl for a later patch.

 git-add.sh           |   13 +++----------
 git-am.sh            |   10 +++-------
 git-applymbox.sh     |    6 +-----
 git-applypatch.sh    |    4 ++++
 git-checkout.sh      |    6 ++----
 git-cherry.sh        |   13 +++++--------
 git-clone.sh         |    2 +-
 git-commit.sh        |    5 +----
 git-count-objects.sh |    4 +++-
 git-fetch.sh         |    5 +++++
 git-format-patch.sh  |   25 ++++++++-----------------
 git-grep.sh          |    7 +++++--
 git-lost-found.sh    |   10 +++++++++-
 git-merge.sh         |    6 ++----
 git-prune.sh         |    3 ++-
 git-pull.sh          |   13 ++-----------
 git-push.sh          |    7 ++-----
 git-rebase.sh        |    5 +++--
 git-repack.sh        |    2 ++
 git-request-pull.sh  |   12 +++++-------
 git-reset.sh         |    6 ++----
 git-resolve.sh       |    6 ++----
 git-revert.sh        |   19 +++++--------------
 git-tag.sh           |   14 +++-----------
 git-verify-tag.sh    |   14 ++++++++------
 25 files changed, 88 insertions(+), 129 deletions(-)

- Fredrik

^ permalink raw reply

* [PATCH 10/11] git-rebase: Usage string clean-up, emit usage string at incorrect invocation
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-rebase.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

e5739c10c7fb47d091cf774941da6e4b4629f350
diff --git a/git-rebase.sh b/git-rebase.sh
index 638ff0d..8a5f44a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -3,6 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
+USAGE='<upstream> [<head>]'
 . git-sh-setup
 
 # Make sure we do not have .dotest
@@ -19,7 +20,7 @@ you still have something valuable there.
 fi
 
 # The other head is given.  Make sure it is valid.
-other=$(git-rev-parse --verify "$1^0") || exit
+other=$(git-rev-parse --verify "$1^0") || usage
 
 # Make sure we have HEAD that is valid.
 head=$(git-rev-parse --verify "HEAD^0") || exit
@@ -36,7 +37,7 @@ esac
 # If the branch to rebase is given, first switch to it.
 case "$#" in
 2)
-	git-checkout "$2" || exit
+	git-checkout "$2" || usage
 esac
 
 # If the HEAD is a proper descendant of $other, we do not even need
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 9/11] git-prune: Usage string clean-up, use the 'usage' function
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-prune.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

7fb74410bb8975f547d0bae395b74ca783a5cce4
diff --git a/git-prune.sh b/git-prune.sh
index 7e7f0ad..7b61d05 100755
--- a/git-prune.sh
+++ b/git-prune.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+USAGE='[-n] [--] [<head>...]'
 . git-sh-setup
 
 dryrun=
@@ -9,7 +10,7 @@ do
     case "$1" in
     -n) dryrun=-n echo=echo ;;
     --) break ;;
-    -*) echo >&2 "usage: git-prune [ -n ] [ heads... ]"; exit 1 ;;
+    -*) usage ;;
     *)  break ;;
     esac
     shift;
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 11/11] git-repack: Usage string clean-up, emit usage at incorrect invocation
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-repack.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

8b8f12ef2bdb33a0695a82c9f7a4f4eed112ad25
diff --git a/git-repack.sh b/git-repack.sh
index 430ddc5..1fafb6e 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -3,6 +3,7 @@
 # Copyright (c) 2005 Linus Torvalds
 #
 
+USAGE='[-a] [-d] [-l] [-n]'
 . git-sh-setup
 	
 no_update_info= all_into_one= remove_redundant= local=
@@ -13,7 +14,7 @@ do
 	-a)	all_into_one=t ;;
 	-d)	remove_redundant=t ;;
 	-l)	local=t ;;
-	*)	break ;;
+	*)	usage ;;
 	esac
 	shift
 done
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 8/11] git-lost-found: Usage string clean-up, emit usage string at incorrect invocation
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-lost-found.sh |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

240de5191779f0637fb339a80a76770ee35f5a68
diff --git a/git-lost-found.sh b/git-lost-found.sh
index 2beec2a..ba6d587 100755
--- a/git-lost-found.sh
+++ b/git-lost-found.sh
@@ -1,6 +1,14 @@
 #!/bin/sh
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
+USAGE=''
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
+if [ "$#" != "0" ]
+then
+    usage
+fi
+
 laf="$GIT_DIR/lost-found"
 rm -fr "$laf" && mkdir -p "$laf/commit" "$laf/other" || exit
 
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 4/11] git-am: Usage string clean-up
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-am.sh |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)

243b906a6786cd7401285cacaf9ade994ff83db8
diff --git a/git-am.sh b/git-am.sh
index 6ed527c..39f2552 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -1,14 +1,10 @@
 #!/bin/sh
 #
 #
-. git-sh-setup
 
-usage () {
-    echo >&2 "usage: $0 [--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>"
-    echo >&2 "	or, when resuming"
-    echo >&2 "	$0 [--skip | --resolved]"
-    exit 1;
-}
+USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way] <mbox>
+  or, when resuming [--skip | --resolved]'
+. git-sh-setup
 
 stop_here () {
     echo "$1" >"$dotest/next"
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 2/11] git-verify-tag: Usage string clean-up, emit usage string at incorrect invocation
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-verify-tag.sh |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

e1bab3098c4926a09cb74dc767d03fd0f3bf8343
diff --git a/git-verify-tag.sh b/git-verify-tag.sh
index 1f44da5..726b1e7 100755
--- a/git-verify-tag.sh
+++ b/git-verify-tag.sh
@@ -1,11 +1,13 @@
 #!/bin/sh
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
-
-die () {
-    echo >&2 "$*"
-    exit 1
-}
+USAGE='<tag>'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
+if [ "$#" != "1" ]
+then
+  usage
+fi
 
 type="$(git-cat-file -t "$1" 2>/dev/null)" ||
 	die "$1: no such object."
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 1/11] Trivial usage string clean-up
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>



Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

This patch contains all 'trivial' changes in this series. In
particular, there are no argument parsing changes here.

 git-add.sh           |   13 +++----------
 git-applymbox.sh     |    6 +-----
 git-checkout.sh      |    6 ++----
 git-clone.sh         |    2 +-
 git-commit.sh        |    5 +----
 git-format-patch.sh  |   25 ++++++++-----------------
 git-grep.sh          |    7 +++++--
 git-merge.sh         |    6 ++----
 git-pull.sh          |   13 ++-----------
 git-push.sh          |    7 ++-----
 git-request-pull.sh  |   12 +++++-------
 git-reset.sh         |    6 ++----
 git-resolve.sh       |    6 ++----
 git-tag.sh           |   14 +++-----------
 14 files changed, 39 insertions(+), 89 deletions(-)

50fb9150eb63cd5a4aebeae401f771bd8d1827aa
diff --git a/git-add.sh b/git-add.sh
index fdec86d..f719b4b 100755
--- a/git-add.sh
+++ b/git-add.sh
@@ -1,13 +1,8 @@
 #!/bin/sh
 
-die () {
-    echo >&2 "$*"
-    exit 1
-}
-
-usage() {
-    die "usage: git add [-n] [-v] <file>..."
-}
+USAGE='[-n] [-v] <file>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
 
 show_only=
 verbose=
@@ -29,8 +24,6 @@ while : ; do
   shift
 done
 
-GIT_DIR=$(git-rev-parse --git-dir) || exit
-
 if test -f "$GIT_DIR/info/exclude"
 then
 	git-ls-files -z \
diff --git a/git-applymbox.sh b/git-applymbox.sh
index c686cc8..61c8c02 100755
--- a/git-applymbox.sh
+++ b/git-applymbox.sh
@@ -18,13 +18,9 @@
 ##
 ## git-am is supposed to be the newer and better tool for this job.
 
+USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
 . git-sh-setup
 
-usage () {
-    echo >&2 "applymbox [-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]"
-    exit 1
-}
-
 keep_subject= query_apply= continue= utf8= resume=t
 while case "$#" in 0) break ;; esac
 do
diff --git a/git-checkout.sh b/git-checkout.sh
index 4cf30e2..f241d4b 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -1,9 +1,7 @@
 #!/bin/sh
-. git-sh-setup
 
-usage () {
-    die "usage: git checkout [-f] [-b <new_branch>] [<branch>] [<paths>...]"
-}
+USAGE='[-f] [-b <new_branch>] [<branch>] [<paths>...]'
+. git-sh-setup
 
 old=$(git-rev-parse HEAD)
 new=
diff --git a/git-clone.sh b/git-clone.sh
index 699205e..4a7aeef 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -9,7 +9,7 @@
 unset CDPATH
 
 usage() {
-	echo >&2 "* git clone [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
+	echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
 	exit 1
 }
 
diff --git a/git-commit.sh b/git-commit.sh
index 3d250ec..7e39c10 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -3,12 +3,9 @@
 # Copyright (c) 2005 Linus Torvalds
 #
 
+USAGE='[-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
 . git-sh-setup
 
-usage () {
-	die 'git commit [-a] [-s] [-v | --no-verify]  [-m <message> | -F <logfile> | (-C|-c) <commit>] [-e] [<path>...]'
-}
-
 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
 while case "$#" in 0) break;; esac
 do
diff --git a/git-format-patch.sh b/git-format-patch.sh
index 921feee..01508e3 100755
--- a/git-format-patch.sh
+++ b/git-format-patch.sh
@@ -3,19 +3,8 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-. git-sh-setup
-
-# Force diff to run in C locale.
-LANG=C LC_ALL=C
-export LANG LC_ALL
-
-usage () {
-    echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
-    [--check] [--signoff] [-<diff options>...]
-    [--help]
-    ( from..to ... | upstream [ our-head ] )
-
-Prepare each commit with its patch since our-head forked from upstream,
+USAGE='[-n | -k] [-o <dir> | --stdout] [--signoff] [--check] [--mbox] [--diff-options] <upstream> [<our-head>]'
+LONG_USAGE='Prepare each commit with its patch since our-head forked from upstream,
 one file per patch, for e-mail submission.  Each output file is
 numbered sequentially from 1, and uses the first line of the commit
 message (massaged for pathname safety) as the filename.
@@ -28,10 +17,12 @@ as "[PATCH N/M] Subject", unless you hav
 
 When --mbox is specified, the output is formatted to resemble
 UNIX mailbox format, and can be concatenated together for processing
-with applymbox.
-'
-    exit 1
-}
+with applymbox.'
+. git-sh-setup
+
+# Force diff to run in C locale.
+LANG=C LC_ALL=C
+export LANG LC_ALL
 
 diff_opts=
 LF='
diff --git a/git-grep.sh b/git-grep.sh
index 44c1613..2ed8e95 100755
--- a/git-grep.sh
+++ b/git-grep.sh
@@ -3,6 +3,10 @@
 # Copyright (c) Linus Torvalds, 2005
 #
 
+USAGE='<option>... <pattern> <path>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
 pattern=
 flags=()
 git_flags=()
@@ -40,8 +44,7 @@ while : ; do
 	shift
 done
 [ "$pattern" ] || {
-	echo >&2 "usage: 'git grep <pattern> [pathspec*]'"
-	exit 1
+	usage
 }
 git-ls-files -z "${git_flags[@]}" "$@" |
 	xargs -0 grep "${flags[@]}" -e "$pattern"
diff --git a/git-merge.sh b/git-merge.sh
index a221daa..bed1ffd 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -3,15 +3,13 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
+
+USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
 . git-sh-setup
 
 LF='
 '
 
-usage () {
-    die "git-merge [-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+"
-}
-
 all_strategies='recursive octopus resolve stupid ours'
 default_strategies='recursive'
 use_strategies=
diff --git a/git-pull.sh b/git-pull.sh
index 3a13984..0991d5f 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -4,19 +4,10 @@
 #
 # Fetch one or more remote refs and merge it/them into the current HEAD.
 
+USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'
+LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
 . git-sh-setup
 
-usage () {
-    echo >&2 "usage: $0"' [-n] [--no-commit] [--no-summary] [--help]
-    [-s strategy]...
-    [<fetch-options>]
-    <repo> <head>...
-
-Fetch one or more remote refs and merge it/them into the current HEAD.
-'
-    exit 1
-}
-
 strategy_args= no_summary= no_commit=
 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
 do
diff --git a/git-push.sh b/git-push.sh
index 140c8f8..1c5cf80 100755
--- a/git-push.sh
+++ b/git-push.sh
@@ -1,10 +1,7 @@
 #!/bin/sh
-. git-sh-setup
-
-usage () {
-    die "Usage: git push [--all] [--force] <repository> [<refspec>]"
-}
 
+USAGE='[--all] [--force] <repository> [<refspec>...]'
+. git-sh-setup
 
 # Parse out parameters and then stop at remote, so that we can
 # translate it using .git/branches information
diff --git a/git-request-pull.sh b/git-request-pull.sh
index ae6cd27..2c48bfb 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -4,13 +4,11 @@
 # This file is licensed under the GPL v2, or a later version
 # at the discretion of Linus Torvalds.
 
-usage()
-{
-	echo "$0 <commit> <url> [ <head> ]"
-	echo "  Summarizes the changes since <commit> to the standard output,"
-	echo "  and includes <url> in the message generated."
-	exit 1
-}
+USAGE='<commit> <url> [<head>]'
+LONG_USAGE='Summarizes the changes since <commit> to the standard output,
+and includes <url> in the message generated.'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
 
 revision=$1
 url=$2
diff --git a/git-reset.sh b/git-reset.sh
index 72ef303..eb44ee8 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -1,9 +1,7 @@
 #!/bin/sh
-. git-sh-setup
 
-usage () {
-	die 'Usage: git reset [--mixed | --soft | --hard]  [<commit-ish>]'
-}
+USAGE='[--mixed | --soft | --hard]  [<commit-ish>]'
+. git-sh-setup
 
 tmp=/var/tmp/reset.$$
 trap 'rm -f $tmp-*' 0 1 2 3 15
diff --git a/git-resolve.sh b/git-resolve.sh
index fcc5ad7..9263070 100755
--- a/git-resolve.sh
+++ b/git-resolve.sh
@@ -4,11 +4,9 @@
 #
 # Resolve two trees.
 #
-. git-sh-setup
 
-usage () {
-	die "git-resolve <head> <remote> <merge-message>"
-}
+USAGE='<head> <remote> <merge-message>'
+. git-sh-setup
 
 dropheads() {
 	rm -f -- "$GIT_DIR/MERGE_HEAD" \
diff --git a/git-tag.sh b/git-tag.sh
index 2435a75..6d0c973 100755
--- a/git-tag.sh
+++ b/git-tag.sh
@@ -1,17 +1,9 @@
 #!/bin/sh
 # Copyright (c) 2005 Linus Torvalds
 
-GIT_DIR=`git-rev-parse --git-dir` || exit $?
-
-usage () {
-    echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]"
-    exit 1
-}
-
-die () {
-    echo >&2 "$*"
-    exit 1
-}
+USAGE='[-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
 
 annotate=
 signed=
-- 
0.99.9.GIT

^ permalink raw reply related

* [PATCH 3/11] git-revert: Usage string clean-up
From: freku045 @ 2005-12-13 22:30 UTC (permalink / raw)
  To: git; +Cc: Fredrik Kuivinen
In-Reply-To: <11345130302438-git-send-email-freku045@student.liu.se>

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>

---

 git-revert.sh |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

16ecbff0d2e6cf51ff92f081ad66b5bcc3883e31
diff --git a/git-revert.sh b/git-revert.sh
index 9d499c4..63d201b 100755
--- a/git-revert.sh
+++ b/git-revert.sh
@@ -3,29 +3,20 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2005 Junio C Hamano
 #
-. git-sh-setup
 
 case "$0" in
 *-revert* )
 	test -t 0 && edit=-e
-	me=revert ;;
+	me=revert
+	USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
 *-cherry-pick* )
 	edit=
-	me=cherry-pick ;;
+	me=cherry-pick
+	USAGE='[--edit] [-n] [-r] <commit-ish>'  ;;
 * )
 	die "What are you talking about?" ;;
 esac
-
-usage () {
-	case "$me" in
-	cherry-pick)
-		die "usage git $me [--edit] [-n] [-r] <commit-ish>"
-		;;
-	revert)
-		die "usage git $me [--edit | --no-edit] [-n] <commit-ish>"
-		;;
-	esac
-}
+. git-sh-setup
 
 no_commit= replay=
 while case "$#" in 0) break ;; esac
-- 
0.99.9.GIT

^ permalink raw reply related

* Re: git cole give unexpected error message
From: Petr Baudis @ 2005-12-13 22:28 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: git
In-Reply-To: <20051213212820.GB5232@mars.ravnborg.org>

Dear diary, on Tue, Dec 13, 2005 at 10:28:20PM CET, I got a letter
where Sam Ravnborg <sam@ravnborg.org> said that...
> cogito being a nice porcelain gives the git errormessage but manage to
> clean up when the clone fails.
> So also cogito would benefit from a more descriptive errormessage.

Well, git clone can fail for many reasons and I don't think the "no such
repository" one is completely overwhelming, so hinting that by Cogito
could be quite confusing (theme of the day: usability ;-)).

The real solution would be proper error reporting by the git daemon.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.

^ permalink raw reply

* Re: Tip of the day: archaeology
From: Junio C Hamano @ 2005-12-13 22:19 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git
In-Reply-To: <Pine.LNX.4.64.0512131351100.4184@g5.osdl.org>

Linus Torvalds <torvalds@osdl.org> writes:

> On Tue, 13 Dec 2005, Junio C Hamano wrote:
>> 
>> *1* Sometimes I wish we had "cvs co -p" equivalent.
>> 
>> 	$ git cat-blob rev path
>> 
>> Perhaps?
>
> Isn't "git-ls-tree rev path" good enough? Maybe you want to wrap it with
>
> 	#!/bin/sh
> 	git-ls-tree "$@" |
> 		while read mode type sha name
> 		do
> 			git-cat-file $type $sha
> 		done
>
> or something? 

Exactly.  The point was that we do not ship a prepackaged script
like that.

^ permalink raw reply

* Re: Tip of the day: archaeology
From: Linus Torvalds @ 2005-12-13 21:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Randal L. Schwartz, git
In-Reply-To: <7vpso07l63.fsf_-_@assigned-by-dhcp.cox.net>



On Tue, 13 Dec 2005, Junio C Hamano wrote:
> 
> *1* Sometimes I wish we had "cvs co -p" equivalent.
> 
> 	$ git cat-blob rev path
> 
> Perhaps?

Isn't "git-ls-tree rev path" good enough? Maybe you want to wrap it with

	#!/bin/sh
	git-ls-tree "$@" |
		while read mode type sha name
		do
			git-cat-file $type $sha
		done

or something? 

		Linus

^ permalink raw reply

* git cole give unexpected error message
From: Sam Ravnborg @ 2005-12-13 21:28 UTC (permalink / raw)
  To: git

Encountered following minor issue today:

Executed:
sam@mars ~/work $ git clone git://git.kernel.org/pub/scm/lib/klibc/klibc.git viggo
defaulting to local storage area
fatal: unexpected EOF

The errormessage "fatal: unexpected EOF" did not immediately tell me
that the requested git repository did not exists.

But I corrected the path and tried again:
sam@mars ~/work $ git clone git://git.kernel.org/pub/scm/libs/klibc/klibc.git viggo
viggo already exists.

So one can see that git did not clean up after the faulty clone.

It would be nice if git:
1) Displayed a more meaningfull error message
2) Cleaned up so I did not have to do a manual rm -rf viggo


cogito being a nice porcelain gives the git errormessage but manage to
clean up when the clone fails.
So also cogito would benefit from a more descriptive errormessage.

	Sam

^ permalink raw reply

* Tip of the day: archaeology
From: Junio C Hamano @ 2005-12-13 21:16 UTC (permalink / raw)
  To: Randal L. Schwartz; +Cc: git
In-Reply-To: <861x0hxfn2.fsf@blue.stonehenge.com>

merlyn@stonehenge.com (Randal L. Schwartz) writes:

> I see now that grepping "gitignore" shows git-add.sh and
> git-status.sh.  gitignore is indeed doc'ed in git-add.txt, but not in
> git-status.txt.  Must've snuck in recently.  I'm trying to watch
> "git-whatchanged -p Documentation/*", but I miss things sometimes.

Let me grab this opportunity to demonstrate archaeology tools.

    $ git whatchanged --pretty=oneline \
      -S'--exclude-per-directory=.gitignore' git-status.sh

shows the "Big tool rename" commit 215a7ad on Sep 7th had it as
621fa49 blob, and we can see that the revision:

    $ git cat-file blob 621fa49 | grep -B2 gitignore
            git-ls-files --others \
                --exclude-from="$GIT_DIR/info/exclude" \
                --exclude-per-directory=.gitignore |

already had .gitignore support [*1*].  Looking at the big rename
commit, we learn git-status.sh used to be called as
git-status-script:

    $ git-diff-tree -r -M --name-status 215a7ad | grep status.sh
    R093	git-status-script	git-status.sh

Digging further with the old name reveals that it is this commit:

    $ git whatchanged --pretty=oneline \
      -S'--exclude-per-directory=.gitignore' git-status-script
    diff-tree ba966b9... (from 9804b7d...)
    Teach git-status-script about git-ls-files --others
    :100755 100755 1999a66... 1696f23... M	git-status-script
    $ git cat-file blob 1696f23 | grep gitignore
	    --exclude-per-directory=.gitignore |
    $ git cat-file blob 1999a66 | grep gitignore
    $ git log --max-count=1 ba966b9 | head -n 5
    commit ba966b957908248396402acd785d10ba1da07294
    Author: Junio C Hamano <junkio@cox.net>
    Date:   Fri Aug 26 02:12:50 2005 -0700

        Teach git-status-script about git-ls-files --others


[Footnote]

*1* Sometimes I wish we had "cvs co -p" equivalent.

	$ git cat-blob rev path

Perhaps?

^ permalink raw reply

* Re: [PATCH] define MAXPATHLEN for hosts that don't support it
From: Junio C Hamano @ 2005-12-13 20:51 UTC (permalink / raw)
  To: Martin Atukunda; +Cc: git
In-Reply-To: <11344764941807-git-send-email-matlads@dsmagic.com>

What platform needs this, may I ask?

^ permalink raw reply

* [PATCH] repost: add git-nntp-post for posting git commit diffs as news messages
From: Artem Khodush @ 2005-12-13 19:55 UTC (permalink / raw)
  To: git

Sorry for posting again, the previous post has broken long lines in the patch.

In case anyone is still interested, here is a script
that exports git repository to a nntp server,
as prompted in http://marc.theaimsgroup.com/?l=git&m=113385203614980&w=2
Tested with INN on localhost with a copy of git repository
(newsgroups must be created beforehand, and inn.conf artcutoff:
and expire.ctl /remember/: parameters better set to never).

I'm not sure if I got this one right, though:

> A merge commit would probably become a multipart with usually 2
> attachments (but N attachments for a N-way octopus), showing
> diff from each branch.

Currently for merges, it posts diff with parent[0] as first attachment,
and diff between parent[i] and git-merge-base parent[i] parent[0]
as each next attachment.




Signed-off-by: Artem Khodush <greenkaa@gmail.com>

---

 Makefile           |    3
 git-nntp-post.perl |  492 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 494 insertions(+), 1 deletions(-)
 create mode 100755 git-nntp-post.perl

676443e459c0689a8b1ec6c6d46423c4f1bbac8e
diff --git a/Makefile b/Makefile
index 00521fe..2cb2a07 100644
--- a/Makefile
+++ b/Makefile
@@ -97,7 +97,8 @@ SCRIPT_SH = \
 SCRIPT_PERL = \
  git-archimport.perl git-cvsimport.perl git-relink.perl \
  git-shortlog.perl git-fmt-merge-msg.perl \
- git-svnimport.perl git-mv.perl git-cvsexportcommit.perl
+ git-svnimport.perl git-mv.perl git-cvsexportcommit.perl \
+ git-nntp-post.perl

 SCRIPT_PYTHON = \
  git-merge-recursive.py
diff --git a/git-nntp-post.perl b/git-nntp-post.perl
new file mode 100755
index 0000000..5a23faf
--- /dev/null
+++ b/git-nntp-post.perl
@@ -0,0 +1,492 @@
+#!/usr/bin/perl -w
+#
+# Copyright (C) 2005 Artem Khodush <greenkaa@gmail.com>
+#
+# This program contains parts from gitweb.cgi,
+# (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
+# (C) 2005, Christian Gierke <ch@gierke.de>
+
+# This program is licensed under the GPL v2, or a later version
+
+use warnings;
+use strict;
+use Net::NNTP;
+use HTTP::Date;
+use MIME::Lite;
+#use MIME::Entity; # interchangeable with the above, but slower
+
+BEGIN {
+       if( $^V ge v5.8.0 ) {
+               require Encode; import Encode;
+       }else {
+               no strict "refs";
+               *{"Encode::encode"}=sub { my ($a,$s,$b)=@_; return $s; };
+       }
+}
+
+# Read commits, starting from heads given on the command line,
+# (or all repository heads), and post each commit diff
+# to a newsgroup, starting with earliest commit.
+# Commits from different branches go to different newsgroups,
+# named after the head names.
+# The order of heads on the command line is important:
+# when branching point is encountered, the branch specified
+# earlier is considered to be the trunk, continuing into the past.
+
+# For commits with more than one parent, multipart message
+# is posted with first part containing diff with parent[0], and each
+# other part containing diff between parent[i] and
+# git-merge-base parent[i] parent[0] (thus showing summary change
+# followed by what was merged from each branch)
+
+# Subset of the git-rev-list options (--max-age, --min-age and
+# commits starting with ^) is accepted to limit the number of
+# commits posted.
+# Exactly one (the latest) commit may be posted with --one option.
+
+# By default, it posts to localhost nntp port (119), this may
+# be changed by --nntp-host and --nntp-port.
+
+# The newsgroup names are formed by taking the GIT_DIR
+# without the trailing .git, replacing / with ., and appending
+# the head name. This can be overriden with --newsgroup-prefix.
+
+# Each posted message gets an id of the form
+# <commit.SHA1@kernel.org>, and the nntp server is relied upon
+# to reject duplicate posts, and to keep the posting order intact.
+# Hence, with ordinary news servers, each commit
+# can appear only in the newsgroups it was originally posted
+# (currently only one), unless someone care to implement
+# logic for rewriting posts, or a special nntp server.
+
+sub usage() {
+       print STDERR <<EOT;
+$0 [OPTIONS] [<head> ...] [^<commit> ...]
+--nntp-host <host>
+--nntp-port <port>
+--newsgroup-prefix <prefix>
+--max-age <epoch>
+--min-age <epoch>
+--one
+--print-newsgroup-names
+--print-messages
+EOT
+       exit(1);
+}
+
+my $GIT_DIR = `git rev-parse --git-dir`;
+chop $GIT_DIR;
+exit 1 if $?; # rev-parse would have given "not a git dir" message.
+chomp($GIT_DIR);
+
+my $DOMAIN_ID="kernel.org"; # sufficiently unique string for Path
+ #and Message-Id headers
+
+my $NNTP_HOST="localhost";
+my $NNTP_PORT="119";
+my $NEWSGROUP_PREFIX;
+my $MAX_AGE;
+my $MIN_AGE;
+my $ONLY_ONE;
+my %HEADS;
+my @STOP_COMMITS;
+my $PRINT_NEWSGROUP_NAMES;
+my $PRINT_MESSAGES;
+
+my $HEAD_COUNT=0;
+
+while( my $arg=shift ) {
+       if( $arg eq "-h" || $arg eq "--nntp-host" ) {
+               $NNTP_HOST=shift or usage();
+       }elsif( $arg=~/^--nntp-host=(.+)$/ ) {
+               $NNTP_HOST=$1;
+       }elsif( $arg eq "-p" || $arg eq "--nntp-port" ) {
+               $NNTP_PORT=shift or usage();
+       }elsif( $arg=~/^--nntp-port=(.+)$/ ) {
+               $NNTP_PORT=$1;
+       }elsif( $arg eq "-n" || $arg eq "--newsgroup-prefix" ) {
+               $NEWSGROUP_PREFIX=shift or usage();
+       }elsif( $arg=~/^--newsgroup-prefix=(.+)$/ ) {
+               $NEWSGROUP_PREFIX=$1;
+       }elsif( $arg eq "-a" || $arg eq "--max-age" ) {
+               $MAX_AGE=shift or usage();
+       }elsif( $arg=~/^--max-age=(.+)$/ ) {
+               $MAX_AGE=$1;
+       }elsif( $arg eq "-i" || $arg eq "--min-age" ) {
+               $MIN_AGE=shift or usage();
+       }elsif( $arg=~/^--min-age=(.+)$/ ) {
+               $MIN_AGE=$1;
+       }elsif( $arg eq "-1" || $arg eq "--one" ) {
+               $ONLY_ONE=1;
+       }elsif( $arg eq "--print-newsgroup-names" ) {
+               $PRINT_NEWSGROUP_NAMES=1;
+       }elsif( $arg eq "--print-messages" ) {
+               $PRINT_MESSAGES=1;
+       }elsif( $arg=~/^\^/ ) {
+               push @STOP_COMMITS, $arg;
+       }else {
+               if( "HEAD" eq $arg ) {
+                       (undef,$arg)=split( " ", `git-name-rev HEAD` );
+               }
+               $HEADS{$arg}->{order}=++$HEAD_COUNT;
+       }
+}
+
+&verify_heads;
+&read_commits;
+&propagate_branches;
+&post_commits;
+exit( 0 );
+
+sub verify_heads()
+{
+       my $repo=$GIT_DIR;
+       my $read_all_heads= 0==$HEAD_COUNT;
+       open my $fd, "-|", "git-peek-remote $repo"
+        or die "$0: error running git-peek-remote: $!";
+       while( my $line=<$fd> ) {
+               my ($id,$name)=split ' ', $line;
+               my $is_head=0;
+               if( "HEAD" eq $name ) {
+                       $is_head=1;
+                       (undef,$name)=split( " ", `git-name-rev HEAD` );
+               }
+               if( $name=~s/^refs\/heads\/// || $is_head ) {
+ # if there were heads given on the command line,
+ # take only those. Otherwise, with --one, take only
+ # HEAD, without --one, take all heads.
+                       if( exists( $HEADS{$name} )
+   || ($read_all_heads && ($is_head || !$ONLY_ONE)) ) {
+                               $HEADS{$name}->{id}=$id;
+                       }
+               }
+       }
+       close $fd or die "$0: git_get_type: unable to close fd: $!";
+       if( $read_all_heads ) {
+               #sort them
+               my $n=0;
+               for my $name (sort keys %HEADS) {
+                       $HEADS{$name}->{order}=++$n;
+               }
+               # make master the first
+               $HEADS{"master"}->{order}=0 if exists $HEADS{"master"};
+       }
+       if( $ONLY_ONE && scalar( keys %HEADS )!=1 ) {
+               die "$0: --one requires exactly one head, but "
+        . scalar( keys %HEADS ) . " were given\n";
+       }
+       if( $PRINT_NEWSGROUP_NAMES ) { # just print them
+               for my $head (keys %HEADS) {
+                       print &make_newsgroup_name( $head ) . "\n";
+               }
+               exit( 0 );
+       }
+}
+
+my %COMMITS;
+
+sub read_commits
+{
+       my $args="";
+       $args.=" --max-age $MAX_AGE" if $MAX_AGE;
+       $args.=" " . join( " ", keys %HEADS );
+       $args.=" " . join( " ", @STOP_COMMITS );
+       $args.=" --max-count=1" if $ONLY_ONE;
+       $/ = "\0";
+       open my $fd, "-|", "git-rev-list --header --parents $args"
+        or die "$0: error running git-rev-list: $!";
+       while( my $commit_line=<$fd> ) {
+               $commit_line =~ s/\r$//;
+               my @commit_lines = split '\n', $commit_line;
+               pop @commit_lines;
+               my %co;
+
+               my $header = shift @commit_lines;
+               if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
+                       next;
+               }
+               ($co{'id'}, my @parents) = split ' ', $header;
+               $co{'parents'} = \@parents;
+               while (my $line = shift @commit_lines) {
+                       last if $line eq "\n";
+                       if ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
+                               $co{'author'} = $1;
+                               $co{'author_epoch'} = $2;
+                               $co{'author_tz'} = $3;
+                       }elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
+                               $co{'committer'} = $1;
+                               $co{'committer_epoch'} = $2;
+                               $co{'committer_tz'} = $3;
+                       }
+               }
+               $co{'title'}="";
+               $co{'title_short'}="";
+               foreach my $title (@commit_lines) {
+                       if ($title ne "") {
+                               $title=~s/^\s+//;
+                               $co{'title'}=chop_str($title, 80, 5);
+                               $co{'title_short'}=make_title_short( $title );
+                               last;
+                       }
+               }
+               # remove added spaces
+               foreach my $line (@commit_lines) {
+                       $line =~ s/^    //;
+               }
+               $co{'comment'} = \@commit_lines;
+               $COMMITS{$co{'id'}}=\%co;
+       }
+       close $fd or die "$0: git_read_commit: unable to close fd: $!";
+       $/ = "\n";
+}
+
+sub make_title_short
+{
+ my $title=shift;
+       # remove leading stuff of merges
+       # to make the interesting part visible
+       if (length($title) > 50) {
+        $title =~ s/^Automatic //;
+        $title =~ s/^merge (of|with) /Merge ... /i;
+        if (length($title) > 50) {
+        $title =~ s/(http|rsync):\/\///;
+        }
+        if (length($title) > 50) {
+        $title =~ s/(master|www|rsync)\.//;
+        }
+        if (length($title) > 50) {
+        $title =~ s/kernel.org:?//;
+        }
+        if (length($title) > 50) {
+        $title =~ s/\/pub\/scm//;
+        }
+       }
+ return chop_str($title, 50, 5)
+}
+
+sub propagate_branches
+{
+       for my $head (sort { $HEADS{$a}->{order} - $HEADS{$b}->{order} }
+        keys %HEADS) {
+               my $child_id=undef;
+               my $id=$HEADS{$head}->{id};
+               while( $id && exists $COMMITS{$id}
+            && !exists $COMMITS{$id}->{branch} ) {
+                       my $co=$COMMITS{$id};
+                       $co->{branch}=$head;
+                       $co->{child}=$child_id;
+                       $HEADS{$head}->{start_id}=$id;
+                       $child_id=$id;
+                       $id=$co->{parents}->[0];
+               }
+       }
+}
+
+sub make_message_id
+{
+       my $id=shift;
+       return "<commit.$id\@$DOMAIN_ID>",
+}
+
+sub make_commit_body
+{
+       my ($id,$other_id,$from_branch)=@_;
+       my $body="";
+       my ($author, $author_epoch, $committer, $committer_epoch);
+       my $comment="";
+       if( exists $COMMITS{$id} ) {
+        # if we have it already, spare git-cat-file
+               my $co=$COMMITS{$id};
+               $author=$co->{author};
+        $author_epoch=$co->{author_epoch};
+        $committer=$co->{committer};
+        $committer_epoch=$co->{committer_epoch};
+               $comment=join( "\n", @{$co->{comment}} );
+       }else {
+               open my $fd0, "-|", "git-cat-file commit $id"
+        or die "$0: error running git-cat-file: $!";
+               my $header=1;
+               while( <$fd0> ) {
+                       if( !$header ) {
+                               $comment.=$_;
+                       }elsif( m/^\s+$/ ) {
+                               $header=0;
+                       }elsif( m/^author (.*) ([0-9]+) (.*)$/ ) {
+                               $author=$1;
+                               $author_epoch=$2;
+                       }elsif( m/^committer (.*) ([0-9]+) (.*)$/ ) {
+                               $committer=$1;
+                               $committer_epoch=$2;
+                       }
+               }
+               close $fd0;
+       }
+       if( $from_branch ) {
+               my $merge_base=`git-merge-base $id $other_id`;
+               chop $merge_base;
+               $body.="merged from $id\n\n---\n";
+               $other_id=$merge_base if $merge_base;
+       }else {
+               my ($author_name,$author_email)=split( " ", $author );
+               my ($committer_name,$committer_email)=split( " ", $committer );
+               $body.="committer $committer ".time2str($committer_epoch)."\n"
+        unless $author_name eq $committer_name;
+               $body.=$comment;
+               $body.="\n---\n\n";
+       }
+       if( $other_id ) {
+               open my $fd1, "-|",
+ "git-diff-tree -p $other_id $id | git-apply --stat --summary"
+ or die "$0: error running git-diff-tree: $!";
+               while( <$fd1> ) {
+                       $body.=$_;
+               }
+               close $fd1;
+               $body.="\n";
+               open my $fd2, "-|", "git-diff-tree -p $other_id $id"
+        or die "$0: error running git-diff-tree again: $!";
+               while( <$fd2> ) {
+                       $body.=$_;
+               }
+               close $fd2;
+       }
+       return $body;
+}
+
+sub make_commit_message
+{
+       my ($newsgroup,$co)=@_;
+       my $n_parents=scalar( @{$co->{parents}} );
+       my $parents=join(" ", map( make_message_id( $_ ),  @{$co->{parents}}));
+       my $from=$co->{author};
+       $from=$co->{committer} unless $from;
+       $from="unknown author" unless $from;
+       my $subject=$co->{title_short};
+       $subject="undescribed patch" unless $subject;
+       my $msg=MIME::Lite->new(
+               From=>join( " ", map( Encode::encode( "MIME-Q", $_ ),
+        split( " ", $from ) ) ),
+               Subject=>join( " ", map( Encode::encode( "MIME-Q", $_ ),
+        split( " ", $subject ) ) ),
+               Date=>time2str( $co->{author_epoch} ),
+               "Message-Id"=>make_message_id( $co->{id} ),
+               ($n_parents>0 ? (References=>$parents) : ()),
+
+               ($n_parents>1 ? (Type=>"multipart/mixed")
+                       :(
+                       Type=>"text/plain; charset=utf8",
+                       Encoding=>"quoted-printable",
+                       Data=>make_commit_body( $co->{id},
+ $co->{parents}->[0],
+ 0)
+                       )
+               )
+       );
+       $msg->add( Path=>$DOMAIN_ID );
+       $msg->add( Newsgroups=>$newsgroup );
+       if( $n_parents>1 ) {
+               $msg->attach(
+                       Type=>"text/plain; charset=utf8",
+                       Encoding=>"quoted-printable",
+                       Data=>make_commit_body( $co->{id},
+        $co->{parents}->[0],
+        0 )
+               );
+               for my $n (1..$n_parents-1) {
+                       $msg->attach(
+                               Type=>"text/plain; charset=utf8",
+                               Encoding=>"quoted-printable",
+ Data=>make_commit_body( $co->{parents}->[$n],
+        $co->{parents}->[0],
+        1 )
+                       );
+               }
+       }
+       return $msg;
+}
+
+sub post_commit
+{
+       my ($nntp,$newsgroup,$co)=@_;
+       if( $PRINT_MESSAGES ) { # just print them
+               print make_commit_message( $newsgroup, $co )->as_string();
+               print "\0";
+       }else {
+               if( !$nntp->ihave( make_message_id( $co->{id} ) ) ) {
+                       my $reason=$nntp->message();
+                       unless( $reason=~m/got it/i
+     || $reason=~m/duplicate/i ) {
+                               print STDERR "unexpected responce in attempt "
+        . "to post $co->{id}: $reason"
+                       }
+               }else {
+        my$msg=make_commit_message(  $newsgroup, $co );
+                       $nntp->datasend( $msg->as_string() );
+                       if( !$nntp->dataend() ) {
+                               print STDERR "error posting $co->{id}: "
+        . $nntp->message() . "\n";
+                       }
+               }
+       }
+}
+
+sub make_newsgroup_name
+{
+       my $nhead=shift;
+       $nhead=~s/\/+$//;
+       $nhead=~s/^\/+//;
+       $nhead=~s/\./-/g;
+       $nhead=~s/\//\./g;
+       my $nprefix=$NEWSGROUP_PREFIX;
+       if( !defined( $nprefix ) ) {
+               $nprefix=$GIT_DIR;
+               $nprefix=~s/\/\.git\/?\s*$//;
+               $nprefix=~s/\/+$//;
+               $nprefix=~s/^\/+//;
+               $nprefix=~s/\./-/g;
+               $nprefix=~s/\//\./g;
+       }
+       return "$nprefix.$nhead";
+}
+
+sub post_commits
+{
+       my $nntp;
+       unless( $PRINT_MESSAGES ) {
+               $nntp=Net::NNTP->new( $NNTP_HOST,
+        Port=>$NNTP_PORT,
+ Reader=>0 );
+               die "unable to connect to nntp host "
+        ."${NNTP_HOST}:${NNTP_PORT}"
+        unless $nntp;
+       }
+       while( my ($head,$h)=each %HEADS ) {
+               my $id=$h->{start_id};
+               my $newsgroup_name=make_newsgroup_name( $head );
+               while( $id ) {
+                       my $co=$COMMITS{$id};
+                       $id=$co->{child};
+                       next if defined( $MIN_AGE )
+        && $co->{committer_epoch} > $MIN_AGE;
+                       post_commit( $nntp, $newsgroup_name, $co );
+               }
+       }
+}
+
+sub chop_str {
+       my $str = shift;
+       my $len = shift;
+       my $add_len = shift || 10;
+
+       # allow only $len chars, but don't cut a word if it would fit
+       # in $add_len. If it doesn't fit, cut it if it's still longer
+       # than the dots we would add
+       $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
+       my $body = $1;
+       my $tail = $2;
+       if (length($tail) > 4) {
+               $tail = " ...";
+       }
+       return "$body$tail";
+}
+
--
0.99.9.GIT

^ permalink raw reply related

* git commit improvement request
From: Jon Nelson @ 2005-12-13 19:49 UTC (permalink / raw)
  To: git


There is a small improvement I would like to see it 'git commit'.
I am using 0.99.9i at this moment.

If I perform a 'git commit' on a series of files, and then decide not to 
perform the commit, I can back out of the operation with a blank commit 
message. Additionally, it would be nice for git commit to recognize a 
non-zero exit code theoretically indicating 'aborted commit'. In any 
case, the problem is that, even though git /states/ that it has aborted 
the commit due to the empty commit message, git diff /appears/ to show 
that the commit took place. a 'git reset' takes care of things for me 
but it was rather confusing at first and it seems counter-intuitive. I'm 
hoping that the behavior here can be changed before 1.0 is released, 
which I am in eager anticipation for.  Thanks!


--
Jon Nelson <jnelson-git@jamponi.net>

^ permalink raw reply

* Re: git-merge fails when trying to merge from a tag
From: Junio C Hamano @ 2005-12-13 19:21 UTC (permalink / raw)
  To: Carl Baldwin; +Cc: git
In-Reply-To: <20051213175516.GA3695@hpsvcnb.fc.hp.com>

Carl Baldwin <cnb@fc.hp.com> writes:

> I just tried to merge using a tag object.

Thanks for the report.

> % git merge "Merging release-0.3.1" HEAD refs/tags/release-0.3.1

Once I considered changing commit-tree to take any committish
after -p, but thought the command is a low level primitive and
the user should know what he is doing, but apparently, git-merge
does not know what it is doing ;-).

In fact, I never use "merge" myself, and haven't noticed this
breakage until now (you would notice that the Everyday document
never talks about "git merge").  Instead, I always do this:

	$ git pull . tag release-0.3.1

But you are right.  It is advertised as the end-user
command and demonstrated in the tutorial.

How about this patch?  I haven't looked at what (old)
git-resolve and git-octopus commands do --- they may need
similar parameter massaging.

-- >8 --
[PATCH] allow merging any committish

Although "git-merge" is advertised as the end-user level command
(instead of being a "git-pull" backend), it was not prepared to
take tag objects that point at commits and barfed when fed one.
Sanitize the input while we validate them, for which we already
have a loop.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
diff --git a/git-merge.sh b/git-merge.sh
index a221daa..d25ae4b 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -97,11 +97,14 @@ head=$(git-rev-parse --verify "$1"^0) ||
 shift
 
 # All the rest are remote heads
+remoteheads=
 for remote
 do
-	git-rev-parse --verify "$remote"^0 >/dev/null ||
+	remotehead=$(git-rev-parse --verify "$remote"^0) ||
 	    die "$remote - not something we can merge"
+	remoteheads="${remoteheads}$remotehead "
 done
+set x $remoteheads ; shift
 
 case "$#" in
 1)

^ permalink raw reply related

* Re: [PATCH] [COGITO] make cg-tag use git-check-ref-format
From: Junio C Hamano @ 2005-12-13 18:41 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git
In-Reply-To: <20051213170015.GD22159@pasky.or.cz>

Petr Baudis <pasky@suse.cz> writes:

> Thank you both for the patch, but I'd be much more comfortable if at
> least quotes (both ' and "), backslashes, ? and * would be prohibited in
> the names as well.

I second that, and thanks for pointing it out.  Any objections?

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox