git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "Uwe Kleine-König" <ukleinek@informatik.uni-freiburg.de>
Cc: git@vger.kernel.org, peff@peff.net, gitster@pobox.com
Subject: [PATCH] name-rev: Fix non-shortest description
Date: Mon, 27 Aug 2007 12:37:33 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0708231557590.20400@racer.site> (raw)
In-Reply-To: <20070823103817.GF6573@informatik.uni-freiburg.de>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2798 bytes --]


Uwe Kleine-König noticed that under certain circumstances, name-rev
picked a non-optimal tag.  Jeff King analyzed that name-rev only
takes into account the number of merge traversals, and then the
_last_ number in the description.

As an easy way to fix it, use a weighting factor for merge traversals:
A merge traversal is now made 65535 times more expensive than a
first-parent traversal.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	On Thu, 23 Aug 2007, Uwe Kleine-K?nig wrote:

	> I want to check to which kernel version I need to upgrade to get 
	> a certain feature.  For my case it was introduced in 
	> 0567a0c022d5b.
	> 
	> zeisberg@cassiopeia:~/gsrc/linux-2.6$ 
	> 	rev=0567a0c022d5b343370a343121f38fd89925de55
	> 
	> zeisberg@cassiopeia:~/gsrc/linux-2.6$ git name-rev --tags $rev
	> 0567a0c02[...] tags/v2.6.22~1686^2~1^3~5
	> 
	> zeisberg@cassiopeia:~/gsrc/linux-2.6$ git name-rev --refs=*-rc1 $rev
	> 0567a0c02[...] tags/v2.6.22-rc1~1009^2~1^3~5

	This fixes it.

 builtin-name-rev.c |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 61eba34..03083e9 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -11,14 +11,17 @@ static const char name_rev_usage[] =
 
 typedef struct rev_name {
 	const char *tip_name;
-	int merge_traversals;
 	int generation;
+	int distance;
 } rev_name;
 
 static long cutoff = LONG_MAX;
 
+/* How many generations are maximally preferred over _one_ merge traversal? */
+#define MERGE_TRAVERSAL_WEIGHT 65535
+
 static void name_rev(struct commit *commit,
-		const char *tip_name, int merge_traversals, int generation,
+		const char *tip_name, int generation, int distance,
 		int deref)
 {
 	struct rev_name *name = (struct rev_name *)commit->util;
@@ -45,13 +48,11 @@ 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) {
 copy_data:
 		name->tip_name = tip_name;
-		name->merge_traversals = merge_traversals;
 		name->generation = generation;
+		name->distance = distance;
 	} else
 		return;
 
@@ -74,11 +75,11 @@ copy_data:
 				sprintf(new_name, "%.*s^%d", len, tip_name,
 						parent_number);
 
-			name_rev(parents->item, new_name,
-				merge_traversals + 1 , 0, 0);
+			name_rev(parents->item, new_name, 0,
+				distance + MERGE_TRAVERSAL_WEIGHT, 0);
 		} else {
-			name_rev(parents->item, tip_name, merge_traversals,
-				generation + 1, 0);
+			name_rev(parents->item, tip_name, generation + 1,
+				distance + 1, 0);
 		}
 	}
 }
-- 
1.5.3.rc6.52.g5113-dirty

  parent reply	other threads:[~2007-08-27 11:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-23 10:38 name-rev does not show the shortest path Uwe Kleine-König
2007-08-24 11:55 ` Julian Phillips
2007-08-24 12:52   ` Uwe Kleine-König
2007-08-24 15:21     ` Julian Phillips
2007-08-24 18:33       ` Junio C Hamano
2007-08-25 15:04         ` Johannes Schindelin
2007-08-26  9:23           ` Jeff King
2007-08-26 15:38             ` Johannes Schindelin
2007-08-27  9:24               ` Jeff King
2007-08-27  9:57                 ` Johannes Schindelin
2007-08-27 11:18                   ` Johannes Schindelin
2007-08-27 11:37 ` Johannes Schindelin [this message]
2007-08-27 19:27   ` [PATCH] name-rev: Fix non-shortest description Uwe Kleine-König

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=Pine.LNX.4.64.0708231557590.20400@racer.site \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=ukleinek@informatik.uni-freiburg.de \
    /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;
as well as URLs for NNTP newsgroup(s).