[PATCH 7/5] pretty describe: add min_prio parameter to describe_commit()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If load_commit_names() is called with a certain priority and later with
a higher priority, all the old, low-priority names are still kept and
describe_commit() will happily take them into account.  It can thus
report heads, even if the user asked for annotated tags.

In the current code, this can't happen, because builtin-describe.c calls
load_commit_names() only once, and commit.c always asks for the highest
priority (annotated tags).  This patch fixes the problem anyway, for the
benefit of future users.

Signed-off-by: Rene Scharfe <rene.scharfe@xxxxxxxxxxxxxx>
---

 builtin-describe.c |    6 ++++--
 cache.h            |    2 +-
 commit.c           |    2 +-
 describe.c         |    7 ++++---
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/builtin-describe.c b/builtin-describe.c
index fcd93f4..481d92f 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -14,6 +14,7 @@ static int all;	/* Default to annotated tags only */
 static int tags;	/* But allow any tags if --tags is specified */
 static int abbrev = DEFAULT_ABBREV;
 static int max_candidates = 10;
+static int min_prio;
 
 static void describe(const char *arg, int last_one)
 {
@@ -28,7 +29,7 @@ static void describe(const char *arg, int last_one)
 	if (!cmit)
 		die("%s is not a valid '%s' object", arg, commit_type);
 
-	name = describe_commit(cmit, max_candidates, debug, &depth);
+	name = describe_commit(cmit, max_candidates, min_prio, debug, &depth);
 	if (!name)
 		die("cannot describe '%s'", sha1_to_hex(cmit->object.sha1));
 
@@ -74,7 +75,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 	 * If --tags, then any tags are used.
 	 * Otherwise only annotated tags are used.
 	 */
-	load_commit_names(all ? 0 : (tags ? 1 : 2));
+	min_prio = all ? 0 : (tags ? 1 : 2);
+	load_commit_names(min_prio);
 
 	if (argc == 0) {
 		describe("HEAD", 1);
diff --git a/cache.h b/cache.h
index 84423a3..703d6a9 100644
--- a/cache.h
+++ b/cache.h
@@ -605,6 +605,6 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
 /* describe.c */
 struct commit;
 extern void load_commit_names(int min_prio);
-extern char *describe_commit(struct commit *cmit, int max_candidates, int debug, int *depthp);
+extern char *describe_commit(struct commit *cmit, int max_candidates, int min_prio, int debug, int *depthp);
 
 #endif /* CACHE_H */
diff --git a/commit.c b/commit.c
index 9ff4735..624005b 100644
--- a/commit.c
+++ b/commit.c
@@ -897,7 +897,7 @@ void format_commit_message(struct commit *commit,
 		const char *abbr;
 
 		load_commit_names(2);
-		name = describe_commit(commit, 10, 0, &depth);
+		name = describe_commit(commit, 10, 2, 0, &depth);
 		clear_commit_name_flags(commit);
 		abbr = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
 
diff --git a/describe.c b/describe.c
index 18c7abc..b6de4c1 100644
--- a/describe.c
+++ b/describe.c
@@ -102,7 +102,8 @@ static unsigned long finish_depth_computation(
 	return seen_commits;
 }
 
-char *describe_commit(struct commit *cmit, int max_candidates, int debug, int *depthp)
+char *describe_commit(struct commit *cmit, int max_candidates, int min_prio,
+                      int debug, int *depthp)
 {
 	struct commit *gave_up_on = NULL;
 	struct commit_list *list;
@@ -110,7 +111,7 @@ char *describe_commit(struct commit *cmit, int max_candidates, int debug, int *d
 	unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
 	unsigned long seen_commits = 0;
 
-	if (cmit->name) {
+	if (cmit->name && cmit->name_prio >= min_prio) {
 		*depthp = 0;
 		return cmit->name;
 	}
@@ -130,7 +131,7 @@ char *describe_commit(struct commit *cmit, int max_candidates, int debug, int *d
 		struct commit *c = pop_commit(&list);
 		struct commit_list *parents = c->parents;
 		seen_commits++;
-		if (c->name) {
+		if (c->name && c->name_prio >= min_prio) {
 			if (match_cnt < max_candidates) {
 				struct possible_tag *t = &all_matches[match_cnt++];
 				t->name = c->name;
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux