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

[PATCH] describe: Refresh the index when run with --dirty

From
Allan Caffee <allan.caffee@gmail.com>
Date
Aug 1, 2011, 01:52 UTC
Message-ID
<1312163561-77072-1-git-send-email-allan.caffee@gmail.com>
In-Reply-To
<20110731062055.GB14384@sigill.intra.peff.net>

When running git describe --dirty the index should be refreshed. Previously the cached index would cause describe to think that the index was dirty when, in reality, it was just stale.

The issue was exposed by python setuptools which hardlinks files into another
directory when building a distribution.
---
 builtin/describe.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/builtin/describe.c b/builtin/describe.c
index 66fc291..792af76 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -24,6 +24,7 @@ static int longformat;
 static int abbrev = -1; /* unspecified */
 static int max_candidates = 10;
 static struct hash_table names;
+static struct lock_file index_lock; /* real index */
 static int have_util;
 static const char *pattern;
 static int always;
@@ -399,6 +400,7 @@ static void describe(const char *arg, int last_one)
 int cmd_describe(int argc, const char **argv, const char *prefix)
 {
 	int contains = 0;
+	int fd;
 	struct option options[] = {
 		OPT_BOOLEAN(0, "contains",   &contains, "find the tag that comes after the commit"),
 		OPT_BOOLEAN(0, "debug",      &debug, "debug search strategy on stderr"),
@@ -462,8 +464,16 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 		die(_("No names found, cannot describe anything."));
 
 	if (argc == 0) {
-		if (dirty && !cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1, diff_index_args, prefix))
-			dirty = NULL;
+		if (dirty) {
+			read_cache();
+			refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
+			fd = hold_locked_index(&index_lock, 0);
+			if (0 <= fd)
+				update_index_if_able(&the_index, &index_lock);
+
+			if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1, diff_index_args, prefix))
+				dirty = NULL;
+		}
 		describe("HEAD", 1);
 	} else if (dirty) {
 		die(_("--dirty is incompatible with committishes"));
-- 
1.7.3.2
Previous: Jeff KingNext: Jeff King
Message 7 of 10 in “Unusual behavior from git describe”
  1. Allan CaffeeJul 29, 2011
  2. Sverre RabbelierJul 29, 2011
  3. Allan CaffeeJul 30, 2011
  4. Sverre RabbelierJul 30, 2011
  5. Allan CaffeeJul 30, 2011
  6. Jeff KingJul 31, 2011
  7. describe: Refresh the index when run with --dirtyAllan Caffee, Aug 1, 2011
  8. Jeff KingAug 1, 2011
  9. Junio C HamanoAug 2, 2011
  10. Allan CaffeeAug 2, 2011

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.