* [PATCH v2] describe: Add --first-parent option
@ 2013-05-17 20:56 Mike Crowe
2013-05-20 22:47 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Mike Crowe @ 2013-05-17 20:56 UTC (permalink / raw)
To: git; +Cc: Mike Crowe
Only consider the first parent commit when walking the commit history. This
is useful if you only wish to match tags on your branch after a merge.
Signed-off-by: Mike Crowe <mac@mcrowe.com>
---
Documentation/git-describe.txt | 9 ++++++++-
builtin/describe.c | 5 +++++
t/t6120-describe.sh | 3 +++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
index 28e5ec0..9439cd6 100644
--- a/Documentation/git-describe.txt
+++ b/Documentation/git-describe.txt
@@ -88,6 +88,11 @@ OPTIONS
--always::
Show uniquely abbreviated commit object as fallback.
+--first-parent::
+ Follow only the first parent commit upon seeing a merge commit.
+ This is useful when you wish to not match tags on branches merged
+ in the history of the target commit.
+
EXAMPLES
--------
@@ -149,7 +154,9 @@ is found, its name will be output and searching will stop.
If an exact match was not found, 'git describe' will walk back
through the commit history to locate an ancestor commit which
has been tagged. The ancestor's tag will be output along with an
-abbreviation of the input committish's SHA-1.
+abbreviation of the input committish's SHA-1. If '--first-parent' was
+specified then the walk will only consider the first parent of each
+commit.
If multiple tags were found during the walk then the tag which
has the fewest commits different from the input committish will be
diff --git a/builtin/describe.c b/builtin/describe.c
index 6636a68..ad84716 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -21,6 +21,7 @@ static int debug; /* Display lots of verbose info */
static int all; /* Any valid ref can be used */
static int tags; /* Allow lightweight tags */
static int longformat;
+static int first_parent;
static int abbrev = -1; /* unspecified */
static int max_candidates = 10;
static struct hash_table names;
@@ -336,6 +337,9 @@ static void describe(const char *arg, int last_one)
commit_list_insert_by_date(p, &list);
p->object.flags |= c->object.flags;
parents = parents->next;
+
+ if (first_parent)
+ break;
}
}
@@ -404,6 +408,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
OPT_BOOLEAN(0, "all", &all, N_("use any ref")),
OPT_BOOLEAN(0, "tags", &tags, N_("use any tag, even unannotated")),
OPT_BOOLEAN(0, "long", &longformat, N_("always use long format")),
+ OPT_BOOLEAN(0, "first-parent", &first_parent, N_("only follow first parent")),
OPT__ABBREV(&abbrev),
OPT_SET_INT(0, "exact-match", &max_candidates,
N_("only output exact matches"), 0),
diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index f67aa6f..a25729f 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -110,6 +110,9 @@ check_describe tags/e --all HEAD^^^
check_describe B-0-* --long HEAD^^2^
check_describe A-3-* --long HEAD^^2
+check_describe c-7-* --tags
+check_describe e-3-* --first-parent --tags
+
: >err.expect
check_describe A --all A^0
test_expect_success 'no warning was displayed for A' '
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] describe: Add --first-parent option
2013-05-17 20:56 [PATCH v2] describe: Add --first-parent option Mike Crowe
@ 2013-05-20 22:47 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2013-05-20 22:47 UTC (permalink / raw)
To: Mike Crowe; +Cc: git
Thanks, will queue.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-20 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-17 20:56 [PATCH v2] describe: Add --first-parent option Mike Crowe
2013-05-20 22:47 ` Junio C Hamano
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).