Skip to contentSkip to conversation

name-rev: Fix tag lookup on repository with mixed types of tags

PATCH In review [email protected] 2 participants 2 messages Jun 22, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 name-rev: Fix tag lookup on repository with mixed types of tags

From: Orgad Shaneh <[email protected]>

Commit 7550424804 (name-rev: include taggerdate in considering the best name) introduced a bug in name-rev.

If a repository has both annotated and non-annotated tags, annotated tag will always win, even if it was created decades after the commit.

Consider a repository that always used non-annotated tags, and at some point started using annotated tags - name-rev --tags will return the first annotated tags for all the old commits (in our repository it is followed by ~5067 for one commit, or by ~120^2~21^2~88^2~87 for another...). This is obviously not what the user expects.

The taggerdate should only be matched if *both tags* have it.

---
 builtin/name-rev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
builtin/name-rev.c +4 -2
index 92a5d8a5d2..8f77023482 100644
@@ -46,11 +46,13 @@ static void name_rev(struct commit *commit,
 		commit->util = name;
 		goto copy_data;
 	} else if (name->taggerdate > taggerdate ||
-			(name->taggerdate == taggerdate &&
+			((taggerdate == ULONG_MAX || name->taggerdate == taggerdate) &&
 			 name->distance > distance)) {
 copy_data:
 		name->tip_name = tip_name;
-		name->taggerdate = taggerdate;
+		if (taggerdate != ULONG_MAX) {
+			name->taggerdate = taggerdate;
+		}
 		name->generation = generation;
 		name->distance = distance;
 	} else
Signature · 1 line
2.13.1.windows.1.1.ga36e14b3aa
#1 lore raw
Quoted 8 lines · On Thu, Jun 22, 2017 at 12:52 PM, <[email protected]> wrote:

From: Orgad Shaneh <[email protected]>

Commit 7550424804 (name-rev: include taggerdate in considering the best name) introduced a bug in name-rev.

If a repository has both annotated and non-annotated tags, annotated tag will always win, even if it was created decades after the commit.

Quoted 7 lines

Consider a repository that always used non-annotated tags, and at some point started using annotated tags - name-rev --tags will return the first annotated tags for all the old commits (in our repository it is followed by ~5067 for one commit, or by ~120^2~21^2~88^2~87 for another...). This is obviously not what the user expects.

The taggerdate should only be matched if *both tags* have it.

Please sign off the patch. See https://developercertificate.org/
or Documentation/SubmittingPatches

Quoted 11 lines
---
 builtin/name-rev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
builtin/name-rev.c +0 -0
index 92a5d8a5d2..8f77023482 100644
@@ -46,11 +46,13 @@ static void name_rev(struct commit *commit,
                commit->util = name;
                goto copy_data;

builtin/name-rev.c static void name_rev(struct commit *commit, · line 55

Quoted 10 lines
builtin/name-rev.c +4 -2
        } else if (name->taggerdate > taggerdate ||
-                       (name->taggerdate == taggerdate &&
+                       ((taggerdate == ULONG_MAX || name->taggerdate == taggerdate) &&
                         name->distance > distance)) {
 copy_data:
                name->tip_name = tip_name;
-               name->taggerdate = taggerdate;
+               if (taggerdate != ULONG_MAX) {
+                       name->taggerdate = taggerdate;
+               }

style: you may omit the braces for a single statement after if.

Quoted 6 lines
builtin/name-rev.c +0 -1
                name->generation = generation;
                name->distance = distance;
        } else
--

2.13.1.windows.1.1.ga36e14b3aa