git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH] git-describe: introduce --first-parent

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Sep 21, 2010, 09:35 UTC
Message-ID
<7d63bc1d2c7408090501bade7e7f8a9eb43cffb3.1285061563.git.git@drmicha.warpmail.net>
In-Reply-To
<4C987C2E.3060001@drmicha.warpmail.net>

so that git-describe searches first-parent history only when looking for a named commit. This is useful for describing commits by tags on their "main" (first-parent) branch.

git describe --contains --first-parent is forbidden because git name-rev (which is called by that) favors first-parent transversal already, although not strictly so.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Notes:
    Is this considered useful? RFC because of lack of doc and test.
    I consider it easier than (and different from) --match in some cases.
 builtin/describe.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/builtin/describe.c b/builtin/describe.c
index 43caff2..6b2b599 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -22,6 +22,7 @@ static int tags;	/* Allow lightweight tags */
 static int longformat;
 static int abbrev = DEFAULT_ABBREV;
 static int max_candidates = 10;
+static int first_parent;
 static int found_names;
 static const char *pattern;
 static int always;
@@ -302,7 +303,7 @@ static void describe(const char *arg, int last_one)
 			if (!(p->object.flags & SEEN))
 				insert_by_date(p, &list);
 			p->object.flags |= c->object.flags;
-			parents = parents->next;
+			parents = first_parent ? NULL : parents->next;
 		}
 	}
 
@@ -380,6 +381,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			   "only consider tags matching <pattern>"),
 		OPT_BOOLEAN(0, "always",     &always,
 			   "show abbreviated commit object as fallback"),
+		OPT_BOOLEAN(0, "first-parent",     &first_parent,
+			   "follow first parents only"),
 		{OPTION_STRING, 0, "dirty",  &dirty, "mark",
 			   "append <mark> on dirty working tree (default: \"-dirty\")",
 		 PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
@@ -397,6 +400,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 	if (longformat && abbrev == 0)
 		die("--long is incompatible with --abbrev=0");
 
+	if (contains && first-parent)
+		die("--contains is incompatible with --first-parent");
+
 	if (contains) {
 		const char **args = xmalloc((7 + argc) * sizeof(char *));
 		int i = 0;
-- 
1.7.3.234.g7bba3
Previous: Michael J GruberNext: Johannes Sixt
Message 3 of 12 in “can git-describe learn first-parent behavior?”
  1. Joshua ShraderSep 21, 2010
  2. Michael J GruberSep 21, 2010
  3. git-describe: introduce --first-parentMichael J Gruber, Sep 21, 2010
  4. Johannes SixtSep 21, 2010
  5. Michael J GruberSep 21, 2010
  6. Johannes SixtSep 21, 2010
  7. Michael J GruberSep 21, 2010
  8. Johannes SixtSep 21, 2010
  9. Michael J GruberSep 21, 2010
  10. Joshua ShraderSep 21, 2010
  11. Michael J GruberSep 22, 2010
  12. Joshua ShraderSep 22, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.