threads / patch / 2827

patchMake git-send-pack exit with error when some refs couldn't be pushed out

Subject: [PATCH] Make git-send-pack exit with error when some refs couldn't be pushed out

## tl;dr

5 messages between Dec 14, 2005 and Dec 14, 2005. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Petr Baudis· Dec 14, 2005, 00:45 UTC · lore

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(-)
Show changes to send-pack.c +5 −1
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;
 }
 
 
Junio C Hamano· Dec 14, 2005, 01:50 UTC · re: Petr Baudis · lore

Re: [PATCH] Make git-send-pack exit with error when some refs couldn't be pushed out

Petr Baudis <pasky@suse.cz> writes:
> 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).

I agree this change to send-pack is a good fix (I haven't looked at the code, but the above description describes a good fix).

However, I am not quite sure if the recent change to Cogito to update the mirror of remote branch is a good one. Since I am not a Cogito user, I did not question it when I saw the change, but I wondered what you are using the cached "remote ref is supposed to be pointing at this commit" knowledge for. If it is only "pretending to have fetched the remote branch immediately after we pushed into it before anybody else touched the same remote branch", then it probably is benign. But this bit puzzles and worries me:

> ... 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 do not remember seeing that report so I do not know how that lossage happens with unreleased Cogito, but I suspect there is something very fishy going on here. I presume it happens when the next fetch/pull from the remote is run, but if the locally cached information can affect the next fetch/pull in such a way, wouldn't updates by other people to the shared remote repository branch also cause things to go out-of-sync and cause the same breakage?

Petr Baudis· Dec 14, 2005, 02:30 UTC · re: Junio C Hamano · lore

Re: [PATCH] Make git-send-pack exit with error when some refs couldn't be pushed out

Dear diary, on Wed, Dec 14, 2005 at 02:50:02AM CET, I got a letter where Junio C Hamano <junkio@cox.net> said that...

Show 8 quoted lines
> However, I am not quite sure if the recent change to Cogito to
> update the mirror of remote branch is a good one.  Since I am
> not a Cogito user, I did not question it when I saw the change,
> but I wondered what you are using the cached "remote ref is
> supposed to be pointing at this commit" knowledge for.  If it is
> only "pretending to have fetched the remote branch immediately
> after we pushed into it before anybody else touched the same
> remote branch", then it probably is benign.

Exactly, we're just pretending that. It's useful since cg-fetch's diff-tree output is less confusing then, cg-log -r <remotebranch> and cg-diff -r ... gives expected results, etc.

Show 14 quoted lines
> But this bit puzzles and worries me:
> 
> > ... 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 do not remember seeing that report so I do not know how that
> lossage happens with unreleased Cogito, but I suspect there is
> something very fishy going on here.  I presume it happens when
> the next fetch/pull from the remote is run, but if the locally
> cached information can affect the next fetch/pull in such a way,
> wouldn't updates by other people to the shared remote repository
> branch also cause things to go out-of-sync and cause the same
> breakage?

Jonas only reported it on IRC as weird cg-commit behaviour (which it appeared to be, but the cause turned out to be this and the nice side-effect that this kind of breakage cannot lose you actual data at least, just metadata).

If the push really happened, this shouldn't be a problem, since then we get into a "fast-forward relation" to the remote branch, and commits by other people don't affect it either, since they don't break this relation. The "interesting behaviour" Cogito implements happens only if your current HEAD == <the_old_remote_head>, which can't happen when other people commit, only when you push it out to the remote head.

What kicks in is the fast-forward behaviour change I proposed quite some time ago on the mailing list and got zero feedback about --- when updating from a remote branch, the Cogito 0.17pre's fast-forward test is extended from

	if (head ancestor_of remote_new)
to
	if (head ancestor_of remote_new OR head == remote_old)

which will make fast-forward able to follow even remote rebases and should have no negative side-effects as long as remote_old was correct (which it is except when our bug comes out). So in the reported case, remote_old was set to head, while remote_new stayed as before, and Cogito therefore thought that the remote branch just got rebased from head to remote_new, and adjusted the head appropriately.

-- 
				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.
Jon Loeliger· Dec 14, 2005, 16:15 UTC · re: Petr Baudis · lore

Re: [PATCH] Make git-send-pack exit with error when some refs cou ldn't be pushed out

On Tue, 2005-12-13 at 20:30, Petr Baudis wrote:
> 
> Jonas only reported it on IRC as weird cg-commit behaviour (which it

Gah. Are we IRCing now too these days? Did I miss a step or an announcment? I thought we were all doing a reasonably good job of communicating here on list... And if I do need to sit-n-watch some IRC channel somewhere to get a complete git-fix, please let me know what it is! :-)

Thanks, jdl

Petr Baudis· Dec 14, 2005, 19:01 UTC · re: Jon Loeliger · lore

Re: [PATCH] Make git-send-pack exit with error when some refs cou ldn't be pushed out

Dear diary, on Wed, Dec 14, 2005 at 05:15:09PM CET, I got a letter where Jon Loeliger <jdl@freescale.com> said that...

Show 5 quoted lines
> On Tue, 2005-12-13 at 20:30, Petr Baudis wrote:
> > Jonas only reported it on IRC as weird cg-commit behaviour (which it
> 
> Gah.  Are we IRCing now too these days?  Did I miss a step
> or an announcment?

I mentioned the #git channel on the FreeNode network in several Cogito announcements, but this problem report was actually in a different channel (#elinks, since it occurred during work on ELinks) and it wouldn't make a difference if it was on a query or in a private mail.

> I thought we were all doing a reasonably good job of communicating
> here on list...

Sure, all important things are going on here, but it's often much more convenient to do some troubleshooting and stuff over IRC, and way too many people also mail me privately (sometimes it makes sense, sometimes they would be better off cc'ing the list).

#git serves mainly as quick help wrt. GIT usage, sometimes people report problems there (but for non-Cogito problems, I usually redir them to the mailing list), and sometimes (but quite rarely) larger feature-wise discussion spins out; but if it's about to get anything near real, it usually hits the mailing list anyway. Oh, and CIA reports Cogito commits on the channel.

The only IRC-only effort ever (so far) was I believe adding the cg-switch command.

-- 
				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.

← back to recent threads