All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Ivankov <divanorama@gmail.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	"Shawn O. Pearce" <spearce@spearce.org>,
	David Barr <davidbarr@google.com>,
	Sverre Rabbelier <srabbelier@gmail.com>,
	Dmitry Ivankov <divanorama@gmail.com>
Subject: [PATCH 2/2] fast-import: fix 'from 0{40}' test
Date: Mon, 19 Sep 2011 03:20:46 +0600	[thread overview]
Message-ID: <1316380846-15845-3-git-send-email-divanorama@gmail.com> (raw)
In-Reply-To: <1316380846-15845-1-git-send-email-divanorama@gmail.com>

parse_from_existing() has a special case for null_sha1 treating it
as a start of an orphaned branch. It is how null_sha1 parent is
treated in fast-import. For example parse_reset_branch() clears
sha1 of a branch but leaves it in a lookup table.

Looking at parse_from_existing() call sites, we can seen that it is
only called for sha1's that come from get_sha1() or an existing
object. So fast-import internals don't give it null_sha1 explicitly
and the only way for it to appear is direct '0{40}' in the input.

Don't treat null_sha1 as a magic sha1 in parse_from_existing thus
making 'from 0{40}' an invalid input. (Unless there is a commit
object having null_sha1, of course. And object with null_sha1 would
be a lot of trouble in fast-import regardless of this patch.)

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 fast-import.c          |   17 ++++++-----------
 t/t9300-fast-import.sh |    2 +-
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 742e7da..827434a 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2488,18 +2488,13 @@ static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
 
 static void parse_from_existing(struct branch *b)
 {
-	if (is_null_sha1(b->sha1)) {
-		hashclr(b->branch_tree.versions[0].sha1);
-		hashclr(b->branch_tree.versions[1].sha1);
-	} else {
-		unsigned long size;
-		char *buf;
+	unsigned long size;
+	char *buf;
 
-		buf = read_object_with_reference(b->sha1,
-			commit_type, &size, b->sha1);
-		parse_from_commit(b, buf, size);
-		free(buf);
-	}
+	buf = read_object_with_reference(b->sha1,
+		commit_type, &size, b->sha1);
+	parse_from_commit(b, buf, size);
+	free(buf);
 }
 
 static int parse_from(struct branch *b)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 8cc3f16..0784d50 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -381,7 +381,7 @@ data 0
 
 from 0000000000000000000000000000000000000000
 INPUT_END
-test_expect_failure 'B: fail on "from 0{40}"' '
+test_expect_success 'B: fail on "from 0{40}"' '
     test_must_fail git fast-import <input
 '
 rm -f .git/objects/pack_* .git/objects/index_*
-- 
1.7.3.4

  parent reply	other threads:[~2011-09-18 21:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-18 21:20 [PATCH/RFC 0/2] fast-import: commit from null_sha1 Dmitry Ivankov
2011-09-18 21:20 ` [PATCH 1/2] fast-import: add 'commit from 0{40}' failing test Dmitry Ivankov
2011-09-18 21:20 ` Dmitry Ivankov [this message]
2011-09-18 21:30 ` [PATCH/RFC 0/2] fast-import: commit from null_sha1 Jonathan Nieder
2011-09-18 21:40   ` Dmitry Ivankov

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=1316380846-15845-3-git-send-email-divanorama@gmail.com \
    --to=divanorama@gmail.com \
    --cc=davidbarr@google.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=spearce@spearce.org \
    --cc=srabbelier@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.