# [PATCH] cg-fetch will now retrieve commits related to tags if missing.

7 messages from 2005-10-20 to 2005-10-20. Participants: Martin Langhoff, Junio C Hamano.
Thread: https://gitlist.dev/t/2157

## Martin Langhoff, 2005-10-20 00:55

Subject: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <1129769745158-git-send-email-martin@catalyst.net.nz>
URL: https://gitlist.dev/e/1129769745158-git-send-email-martin%40catalyst.net.nz

```
Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>


---

 cg-fetch |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

applies-to: 38ed7981343a8e2bb734d64e019186a8a482dbef
48cb643964910a058881307513cb63aeee28a1de
diff --git a/cg-fetch b/cg-fetch
index 7694584..d4650e5 100755
--- a/cg-fetch
+++ b/cg-fetch
@@ -417,7 +417,8 @@ $get -i -s -u -d "$uri/refs/tags" "$_git
 	for tag in *; do
 		[ "$tag" = "*" ] && break
 		tagid=$(cat $tag)
-		GIT_DIR=../.. git-cat-file -t "$tagid" >/dev/null 2>&1 && continue
+		GIT_DIR=../.. [ "`git-cat-file -t $tagid 2>/dev/null`" = "commit" ] && continue
+		GIT_DIR=../.. git-cat-file commit `git-rev-parse $tag^{commit}  2>/dev/null` 2>&1 >> /dev/null && continue
 		echo -n "Missing object of tag $tag... "
 		if [ "$fetch" != "fetch_rsync" ] && GIT_DIR=../.. $fetch "$tagid" "$uri" 2>/dev/null >&2; then
 			echo "retrieved"
---
0.99.8.GIT

```

## Junio C Hamano, 2005-10-20 01:25

Subject: Re: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <7voe5lvv1q.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7voe5lvv1q.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <1129769745158-git-send-email-martin@catalyst.net.nz>

```
Martin Langhoff <martin@catalyst.net.nz> writes:

> diff --git a/cg-fetch b/cg-fetch
> index 7694584..d4650e5 100755
> --- a/cg-fetch
> +++ b/cg-fetch
> @@ -417,7 +417,8 @@ $get -i -s -u -d "$uri/refs/tags" "$_git
>  	for tag in *; do
>  		[ "$tag" = "*" ] && break
>  		tagid=$(cat $tag)

You just reported this $tag needs quoting ;-).

> +		GIT_DIR=../.. [ "`git-cat-file -t $tagid 2>/dev/null`" = "commit" ] && continue
> +		GIT_DIR=../.. git-cat-file commit `git-rev-parse $tag^{commit}  2>/dev/null` 2>&1 >> /dev/null && continue

You are saying:
	if "$tagid" is already commit then continue;
        if "$tagid" dereferences to a commit and if you have it
	then continue

If that is the case, then this might be more efficient.

	GIT_DIR=../.. git-rev-parse --verify "$tagid^0" >/dev/null 2>&1 && continue

You can say ^{commit} instead of ^0 if you like that newer
style, of course.

```

## Martin Langhoff, 2005-10-20 04:15

Subject: Re: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <46a038f90510192115x21ed7e96l6d85ce233e66a5f2@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90510192115x21ed7e96l6d85ce233e66a5f2%40mail.gmail.com
In-Reply-To: <7voe5lvv1q.fsf@assigned-by-dhcp.cox.net>

```
On 10/20/05, Junio C Hamano <junkio@cox.net> wrote:
> You just reported this $tag needs quoting ;-).

I thought I had seen a post from you to Petr, mentioning that he had
just fixed it. I didn't see any fix when I updated, but I thought it
may have been due to mirroring issues. In any case, it obviously needs
quoting.

> > +             GIT_DIR=../.. [ "`git-cat-file -t $tagid 2>/dev/null`" = "commit" ] && continue
> > +             GIT_DIR=../.. git-cat-file commit `git-rev-parse $tag^{commit}  2>/dev/null` 2>&1 >> /dev/null && continue
>
> You are saying:
>         if "$tagid" is already commit then continue;
>         if "$tagid" dereferences to a commit and if you have it
>         then continue
>
> If that is the case, then this might be more efficient.
>
>         GIT_DIR=../.. git-rev-parse --verify "$tagid^0" >/dev/null 2>&1 && continue
>
> You can say ^{commit} instead of ^0 if you like that newer
> style, of course.

I tried, and failed to get it to work 100% so I reverted to the double
check you've seen. Must have been PEBKAC for now it works correctly --
possibly related to the unquoted tagnames.

Ok -- too many problems with that patch. Let's try it again...


martin

```

## Martin Langhoff, 2005-10-20 04:18

Subject: Re: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <46a038f90510192118s31c52fe7m73d88a9779653f4c@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90510192118s31c52fe7m73d88a9779653f4c%40mail.gmail.com
In-Reply-To: <7voe5lvv1q.fsf@assigned-by-dhcp.cox.net>

```
On 10/20/05, Junio C Hamano <junkio@cox.net> wrote:

> You are saying:
>         if "$tagid" is already commit then continue;
>         if "$tagid" dereferences to a commit and if you have it
>         then continue
>
> If that is the case, then this might be more efficient.
>
>         GIT_DIR=../.. git-rev-parse --verify "$tagid^0" >/dev/null 2>&1 && continue

Note however that git-rev-parse is lazy and won't check that the
commit is there. I have to call git-cat-file and check whether it
succeeds to know if we have the object.

cheers,


martin

```

## Junio C Hamano, 2005-10-20 04:44

Subject: Re: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <7virvsu79c.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7virvsu79c.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <46a038f90510192118s31c52fe7m73d88a9779653f4c@mail.gmail.com>

```
Martin Langhoff <martin.langhoff@gmail.com> writes:

>>         GIT_DIR=../.. git-rev-parse --verify "$tagid^0" >/dev/null 2>&1 && continue
>
> Note however that git-rev-parse is lazy and won't check that the
> commit is there. I have to call git-cat-file and check whether it
> succeeds to know if we have the object.

Are you sure?

What "rev^0" does is:

    1. parse "rev"; make sure it can deref to commit and read
       it (otherwise give up and say the whole thing is not an
       SHA1 expression);

    2. grab the nth parent SHA1.  If N>0, it is lazy and does
       not check if the parent object exists, but still 0th
       parent is the commit object itself and if we came this
       far you know that commit is available already.

Together with --verify, it barfs if the above does not say "rev^0"
is a valid SHA1 expression.  So this should work without
cat-file.  No?

BTW, I just got a SEGV while pulling Cogito repository over
git-fetch-pack after interrupting rsync transfer (I wanted to
switch to git transfer).  I am running with Johaness patch from
today so the cause may be different from yours, but now I have
something to look at, which is better than before.

Fetching with rsync (and interrupting in the middle) is a good
way to simulate a broken repository ;-).

```

## Martin Langhoff, 2005-10-20 04:59

Subject: Re: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <46a038f90510192159h25aad025kf377e3e33b5d30d@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90510192159h25aad025kf377e3e33b5d30d%40mail.gmail.com
In-Reply-To: <7virvsu79c.fsf@assigned-by-dhcp.cox.net>

```
On 10/20/05, Junio C Hamano <junkio@cox.net> wrote:
> Martin Langhoff <martin.langhoff@gmail.com> writes:
>
> >>         GIT_DIR=../.. git-rev-parse --verify "$tagid^0" >/dev/null 2>&1 && continue
> >
> > Note however that git-rev-parse is lazy and won't check that the
> > commit is there. I have to call git-cat-file and check whether it
> > succeeds to know if we have the object.
>
> Are you sure?
>
> What "rev^0" does is:

Ok -- I was using ^{commit} which _is_ lazy, but you are right, ^0 isn't lazy.

> BTW, I just got a SEGV while pulling Cogito repository over
> git-fetch-pack after interrupting rsync transfer (I wanted to
> switch to git transfer).  I am running with Johaness patch from
> today so the cause may be different from yours, but now I have
> something to look at, which is better than before.
>
> Fetching with rsync (and interrupting in the middle) is a good
> way to simulate a broken repository ;-).

Cool. That's something for you to play with I guess, to tell you the
truth, I'm not useful with gdb ;)

martin

```

## Junio C Hamano, 2005-10-20 05:23

Subject: Re: [PATCH] cg-fetch will now retrieve commits related to tags if missing.
Message-ID: <7v3bmwu5gt.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v3bmwu5gt.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <46a038f90510192159h25aad025kf377e3e33b5d30d@mail.gmail.com>

```
Martin Langhoff <martin.langhoff@gmail.com> writes:

> Ok -- I was using ^{commit} which _is_ lazy, but you are
> right, ^0 isn't lazy.

Ah, my mistake.  We would need something like this.

---

diff --git a/sha1_name.c b/sha1_name.c
index 75c688e..cc320d3 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -323,6 +323,8 @@ static int peel_onion(const char *name, 
 		return -1;
 	if (!type_string) {
 		o = deref_tag(o);
+		if (!o || (!o->parsed && !parse_object(o->sha1)))
+			return -1;
 		memcpy(sha1, o->sha1, 20);
 	}
 	else {
@@ -332,7 +334,7 @@ static int peel_onion(const char *name, 
 		 */
 
 		while (1) {
-			if (!o)
+			if (!o || (!o->parsed && !parse_object(o->sha1)))
 				return -1;
 			if (o->type == type_string) {
 				memcpy(sha1, o->sha1, 20);

```
