Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH] Fix ref_newer() in send-pack.
Date: Fri, 05 Aug 2005 23:18:38 -0700	[thread overview]
Message-ID: <7v7jezbnb5.fsf@assigned-by-dhcp.cox.net> (raw)

When more than two references need to be checked with
ref_newer() function, the second and later calls did not work
correctly.  This was because the later calls found commits
retained by the "struct object" layer that still had smudges
made by earlier calls.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

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

51b0fca012310910783de76f2eacfd10b0f2f9fc
diff --git a/send-pack.c b/send-pack.c
--- a/send-pack.c
+++ b/send-pack.c
@@ -105,12 +105,23 @@ static int pack_objects(int fd, struct r
 	return 0;
 }
 
+static void unmark_and_free(struct commit_list *list, unsigned int mark)
+{
+	while (list) {
+		struct commit_list *temp = list;
+		temp->item->object.flags &= ~mark;
+		list = temp->next;
+		free(temp);
+	}
+}
+
 static int ref_newer(const unsigned char *new_sha1,
 		     const unsigned char *old_sha1)
 {
 	struct object *o;
 	struct commit *old, *new;
-	struct commit_list *list;
+	struct commit_list *list, *used;
+	int found = 0;
 
 	/* Both new and old must be commit-ish and new is descendant of
 	 * old.  Otherwise we require --force.
@@ -127,14 +138,20 @@ static int ref_newer(const unsigned char
 
 	if (parse_commit(new) < 0)
 		return 0;
-	list = NULL;
+
+	used = list = NULL;
 	commit_list_insert(new, &list);
 	while (list) {
 		new = pop_most_recent_commit(&list, 1);
-		if (new == old)
-			return 1;
+		commit_list_insert(new, &used);
+		if (new == old) {
+			found = 1;
+			break;
+		}
 	}
-	return 0;
+	unmark_and_free(list, 1);
+	unmark_and_free(used, 1);
+	return found;
 }
 
 static struct ref *local_refs, **local_tail;

                 reply	other threads:[~2005-08-06  6:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v7jezbnb5.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox