name-rev: Fix non-shortest description
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> Acked-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2b9232cc23
commit
ac076c29ae
@ -11,14 +11,17 @@ static const char name_rev_usage[] =
|
|||||||
|
|
||||||
typedef struct rev_name {
|
typedef struct rev_name {
|
||||||
const char *tip_name;
|
const char *tip_name;
|
||||||
int merge_traversals;
|
|
||||||
int generation;
|
int generation;
|
||||||
|
int distance;
|
||||||
} rev_name;
|
} rev_name;
|
||||||
|
|
||||||
static long cutoff = LONG_MAX;
|
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,
|
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)
|
int deref)
|
||||||
{
|
{
|
||||||
struct rev_name *name = (struct rev_name *)commit->util;
|
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));
|
name = xmalloc(sizeof(rev_name));
|
||||||
commit->util = name;
|
commit->util = name;
|
||||||
goto copy_data;
|
goto copy_data;
|
||||||
} else if (name->merge_traversals > merge_traversals ||
|
} else if (name->distance > distance) {
|
||||||
(name->merge_traversals == merge_traversals &&
|
|
||||||
name->generation > generation)) {
|
|
||||||
copy_data:
|
copy_data:
|
||||||
name->tip_name = tip_name;
|
name->tip_name = tip_name;
|
||||||
name->merge_traversals = merge_traversals;
|
|
||||||
name->generation = generation;
|
name->generation = generation;
|
||||||
|
name->distance = distance;
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -74,11 +75,11 @@ copy_data:
|
|||||||
sprintf(new_name, "%.*s^%d", len, tip_name,
|
sprintf(new_name, "%.*s^%d", len, tip_name,
|
||||||
parent_number);
|
parent_number);
|
||||||
|
|
||||||
name_rev(parents->item, new_name,
|
name_rev(parents->item, new_name, 0,
|
||||||
merge_traversals + 1 , 0, 0);
|
distance + MERGE_TRAVERSAL_WEIGHT, 0);
|
||||||
} else {
|
} else {
|
||||||
name_rev(parents->item, tip_name, merge_traversals,
|
name_rev(parents->item, tip_name, generation + 1,
|
||||||
generation + 1, 0);
|
distance + 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user