Re: name-rev does not show the shortest path

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeff King
Date: Sunday, August 26, 2007 - 2:23 am

On Sat, Aug 25, 2007 at 05:04:33PM +0200, Johannes Schindelin wrote:


It does execute that code, just not for the rev in question. We hit the
third part of that conditional and stop recursing on a different rev, so
we only touch our "interesting" rev one time.

That being said, I think this test is totally bogus. You're just looking
at the generation and merge traversals from some tip. However, the tip
_isn't_ the actual ref, but instead gets re-written as a string when we
follow a merge. That string contains important generational information
that is no longer taken into account, so you end up with things like
"foo~999" with generation "3" is better than "bar~10" with generation
"5".

Here is a patch (below) that tracks an absolute "distance to ref" and at
least names the rev in question after v2.6.22-rc1. However, because it
is now preferring "distance to ref" strictly over merge traversals, it
seems to generate some obscenely long names:

0567a0c022d5b343370a343121f38fd89925de55 tags/v2.6.22-rc1~1^2^2^2~11^2~13^2~8^2~1^3~5

So perhaps there is a more sane metric, but I'd have to think about it
more.

-Peff

---
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 61eba34..c003e20 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -13,13 +13,14 @@ typedef struct rev_name {
 	const char *tip_name;
 	int merge_traversals;
 	int generation;
+	int distance;
 } rev_name;
 
 static long cutoff = LONG_MAX;
 
 static void name_rev(struct commit *commit,
 		const char *tip_name, int merge_traversals, int generation,
-		int deref)
+		int deref, int distance)
 {
 	struct rev_name *name = (struct rev_name *)commit->util;
 	struct commit_list *parents;
@@ -45,13 +46,16 @@ static void name_rev(struct commit *commit,
 		name = xmalloc(sizeof(rev_name));
 		commit->util = name;
 		goto copy_data;
-	} else if (name->merge_traversals > merge_traversals ||
-			(name->merge_traversals == merge_traversals &&
-			 name->generation > generation)) {
+	} else if (name->distance > distance ||
+			(name->distance == distance &&
+			 name->merge_traversals > merge_traversals ||
+			 (name->merge_traversals == merge_traversals &&
+			  name->generation > generation))) {
 copy_data:
 		name->tip_name = tip_name;
 		name->merge_traversals = merge_traversals;
 		name->generation = generation;
+		name->distance = distance;
 	} else
 		return;
 
@@ -75,10 +79,10 @@ copy_data:
 						parent_number);
 
 			name_rev(parents->item, new_name,
-				merge_traversals + 1 , 0, 0);
+				merge_traversals + 1 , 0, 0, distance + 1);
 		} else {
 			name_rev(parents->item, tip_name, merge_traversals,
-				generation + 1, 0);
+				generation + 1, 0, distance + 1);
 		}
 	}
 }
@@ -120,7 +124,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
 		else if (!prefixcmp(path, "refs/"))
 			path = path + 5;
 
-		name_rev(commit, xstrdup(path), 0, 0, deref);
+		name_rev(commit, xstrdup(path), 0, 0, deref, 0);
 	}
 	return 0;
 }
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
name-rev does not show the shortest path, Uwe , (Thu Aug 23, 3:38 am)
Re: name-rev does not show the shortest path, Julian Phillips, (Fri Aug 24, 4:55 am)
Re: name-rev does not show the shortest path, Julian Phillips, (Fri Aug 24, 8:21 am)
Re: name-rev does not show the shortest path, Junio C Hamano, (Fri Aug 24, 11:33 am)
Re: name-rev does not show the shortest path, Johannes Schindelin, (Sat Aug 25, 8:04 am)
Re: name-rev does not show the shortest path, Jeff King, (Sun Aug 26, 2:23 am)
Re: name-rev does not show the shortest path, Johannes Schindelin, (Sun Aug 26, 8:38 am)
Re: name-rev does not show the shortest path, Jeff King, (Mon Aug 27, 2:24 am)
Re: name-rev does not show the shortest path, Johannes Schindelin, (Mon Aug 27, 2:57 am)
Re: name-rev does not show the shortest path, Johannes Schindelin, (Mon Aug 27, 4:18 am)
[PATCH] name-rev: Fix non-shortest description, Johannes Schindelin, (Mon Aug 27, 4:37 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 1:20 am)
Re: [PATCH] name-rev: Fix non-shortest description, Johannes Schindelin, (Tue Aug 28, 1:39 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 2:00 am)
Re: [PATCH] name-rev: Fix non-shortest description, Johannes Schindelin, (Tue Aug 28, 2:15 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 2:25 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 2:26 am)
Re: [PATCH] name-rev: Fix non-shortest description, Johannes Schindelin, (Tue Aug 28, 3:03 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 3:26 am)
Re: [PATCH] name-rev: Fix non-shortest description, Johannes Schindelin, (Tue Aug 28, 4:02 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 4:11 am)
Re: [PATCH] name-rev: Fix non-shortest description, Johannes Schindelin, (Tue Aug 28, 4:28 am)
Re: [PATCH] name-rev: Fix non-shortest description, Jeff King, (Tue Aug 28, 4:34 am)