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

[patch] Fix a corner case in git update-index --index-info

From
Thomas Jarosch <thomas.jarosch@intra2net.com>
Date
Dec 13, 2008, 13:03 UTC
Message-ID
<200812131403.08740.thomas.jarosch@intra2net.com>

Fix a corner case in git update-index --index-info: If there are no input lines, it won't create an empty index.

Here's a short test for this: echo -n "" |GIT_INDEX_FILE=index.new git update-index --index-info -> The index "index.new" won't get created

It failed for me while I was using git filter-branch as described in the man page:

    git filter-branch --index-filter \
            ´git ls-files -s | sed "s-\t-&newsubdir/-" |
                    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                            git update-index --index-info &&
            mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE´ HEAD

The conversion aborted because the first commit was empty. (created by cvs2svn)

Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 65d5775..998a48e 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -299,6 +299,7 @@ static void read_index_info(int line_termination)
 {
 	struct strbuf buf = STRBUF_INIT;
 	struct strbuf uq = STRBUF_INIT;
+	int found_something = 0;
 
 	while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
 		char *ptr, *tab;
@@ -308,6 +309,8 @@ static void read_index_info(int line_termination)
 		unsigned long ul;
 		int stage;
 
+		found_something = 1;
+
 		/* This reads lines formatted in one of three formats:
 		 *
 		 * (1) mode         SP sha1          TAB path
@@ -383,6 +386,11 @@ static void read_index_info(int line_termination)
 	bad_line:
 		die("malformed index info %s", buf.buf);
 	}
+
+	/* Force creation of empty index - needed by git filter-branch */
+	if (!found_something)
+		active_cache_changed = 1;
+
 	strbuf_release(&buf);
 	strbuf_release(&uq);
 }
Next: Junio C Hamano
Message 1 of 3 in “Fix a corner case in git update-index --index-info”
  1. Fix a corner case in git update-index --index-infoThomas Jarosch, Dec 13, 2008
  2. Junio C HamanoDec 13, 2008
  3. Thomas JaroschDec 15, 2008

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.