git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Jarosch <thomas.jarosch@intra2net.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [patch] Fix a corner case in git update-index --index-info
Date: Sat, 13 Dec 2008 14:03:06 +0100	[thread overview]
Message-ID: <200812131403.08740.thomas.jarosch@intra2net.com> (raw)

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);
 }

             reply	other threads:[~2008-12-13 13:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-13 13:03 Thomas Jarosch [this message]
2008-12-13 19:29 ` [patch] Fix a corner case in git update-index --index-info Junio C Hamano
2008-12-15 10:52   ` Thomas Jarosch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200812131403.08740.thomas.jarosch@intra2net.com \
    --to=thomas.jarosch@intra2net.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).