git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] format-patch: dereference tags with --ignore-if-in-upstream

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 1, 2015, 17:44 UTC
Message-ID
<xmqq6177728a.fsf@gitster.dls.corp.google.com>
In-Reply-To
<xmqqr3pv8okj.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
>> diff --git a/builtin/log.c b/builtin/log.c
>> index dd8f3fc..e0465ba 100644
>> --- a/builtin/log.c
>> +++ b/builtin/log.c
>> @@ -807,6 +807,12 @@ static void get_patch_ids(struct rev_info *rev,
>> struct patch_ids *ids)
>>  	o2 = rev->pending.objects[1].item;
>>  	flags2 = o2->flags;
>>  
>> +	o1 = deref_tag(o1, NULL, 0);
>> +	o2 = deref_tag(o2, NULL, 0);
>> +
>> +	if (!o1 || !o2)
>> +		die(_("Invalid tag."));
>
> Shouldn't you ensure o1 and o2 are commits here?

Heh, I should have read the remainder of the thread before responding.

How about doing it this way? We know and trust that existing revision traversal machinery is doing the right thing, and it is only that the clear_commit_marks() calls are botched.

diff --git a/builtin/log.c b/builtin/log.c
index dd8f3fc..23a42fa 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -795,7 +795,7 @@ static int reopen_stdout(struct commit *commit, const char *subject,
 static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
 {
 	struct rev_info check_rev;
-	struct commit *commit;
+	struct commit *commit, *c1, *c2;
 	struct object *o1, *o2;
 	unsigned flags1, flags2;
 
@@ -803,9 +803,11 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
 		die(_("Need exactly one range."));
 
 	o1 = rev->pending.objects[0].item;
-	flags1 = o1->flags;
 	o2 = rev->pending.objects[1].item;
+	flags1 = o1->flags;
 	flags2 = o2->flags;
+	c1 = lookup_commit_reference(o1->sha1);
+	c2 = lookup_commit_reference(o2->sha1);
 
 	if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
 		die(_("Not a range."));
@@ -827,10 +829,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
 	}
 
 	/* reset for next revision walk */
-	clear_commit_marks((struct commit *)o1,
-			SEEN | UNINTERESTING | SHOWN | ADDED);
-	clear_commit_marks((struct commit *)o2,
-			SEEN | UNINTERESTING | SHOWN | ADDED);
+	clear_commit_marks(c1, SEEN | UNINTERESTING | SHOWN | ADDED);
+	clear_commit_marks(c2, SEEN | UNINTERESTING | SHOWN | ADDED);
 	o1->flags = flags1;
 	o2->flags = flags2;
 }
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index c39e500..890db11 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -57,6 +57,14 @@ test_expect_success "format-patch --ignore-if-in-upstream" '
 
 '
 
+test_expect_success "format-patch --ignore-if-in-upstream handles tags" '
+	git tag -a v1 -m tag side &&
+	git tag -a v2 -m tag master &&
+	git format-patch --stdout --ignore-if-in-upstream v2..v1 >patch1 &&
+	cnt=$(grep "^From " patch1 | wc -l) &&
+	test $cnt = 2
+'
+
 test_expect_success "format-patch doesn't consider merge commits" '
 
 	git checkout -b slave master &&
Previous: Junio C HamanoNext: Jeff King
Message 13 of 21 in “seg fault in "git format-patch"”
  1. Bruce KorbMay 31, 2015
  2. Christian CouderMay 31, 2015
  3. Bruce KorbMay 31, 2015
  4. Bruce KorbMay 31, 2015
  5. Christian CouderMay 31, 2015
  6. Christian CouderMay 31, 2015
  7. Christian CouderJun 1, 2015
  8. format-patch: dereference tags with --ignore-if-in-upstreambrian m. carlson, Jun 1, 2015
  9. Jeff KingJun 1, 2015
  10. brian m. carlsonJun 1, 2015
  11. Jeff KingJun 1, 2015
  12. Junio C HamanoJun 1, 2015
  13. Junio C HamanoJun 1, 2015
  14. Jeff KingJun 1, 2015
  15. Junio C HamanoJun 1, 2015
  16. brian m. carlsonJun 1, 2015
  17. Junio C HamanoJun 1, 2015
  18. Junio C HamanoJun 1, 2015
  19. Christian CouderJun 1, 2015
  20. Christian CouderJun 1, 2015
  21. Bruce KorbJun 1, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.