All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pete Wyckoff <pw@padd.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	Dmitry Ivankov <divanorama@gmail.com>
Subject: [PATCH] fast-import: catch garbage after marks in from/merge
Date: Sun, 1 Apr 2012 18:54:07 -0400	[thread overview]
Message-ID: <20120401225407.GA12127@padd.com> (raw)

A forgotten LF can lead to a confusing bug.  The last
line in this commit command is wrong:

    commit refs/heads/S2
    committer Name <name@example.com> 1112912893 -0400
    data <<COMMIT
    commit message
    COMMIT
    from :1M 100644 :103 hello.c

It is missing a newline and should be:

    from :1
    M 100644 :103 hello.c

Make fast-import complain about the buggy input, for both
from and merge lines that use marks.

Signed-off-by: Pete Wyckoff <pw@padd.com>
---
I spent too long tracking down the bug described in the
commit message.  It might help future users if fast-import
were to complain in this case.

 fast-import.c          |   24 +++++++++--
 t/t9300-fast-import.sh |  104 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+), 4 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index a85275d..13001bb 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2537,8 +2537,16 @@ static int parse_from(struct branch *b)
 		hashcpy(b->branch_tree.versions[0].sha1, t);
 		hashcpy(b->branch_tree.versions[1].sha1, t);
 	} else if (*from == ':') {
-		uintmax_t idnum = strtoumax(from + 1, NULL, 10);
-		struct object_entry *oe = find_mark(idnum);
+		char *eptr;
+		uintmax_t idnum = strtoumax(from + 1, &eptr, 10);
+		struct object_entry *oe;
+		if (eptr) {
+			for (; *eptr && isspace(*eptr); eptr++) ;
+			if (*eptr)
+				die("Garbage after mark: %s",
+				    command_buf.buf);
+		}
+		oe = find_mark(idnum);
 		if (oe->type != OBJ_COMMIT)
 			die("Mark :%" PRIuMAX " not a commit", idnum);
 		hashcpy(b->sha1, oe->idx.sha1);
@@ -2572,8 +2580,16 @@ static struct hash_list *parse_merge(unsigned int *count)
 		if (s)
 			hashcpy(n->sha1, s->sha1);
 		else if (*from == ':') {
-			uintmax_t idnum = strtoumax(from + 1, NULL, 10);
-			struct object_entry *oe = find_mark(idnum);
+			char *eptr;
+			uintmax_t idnum = strtoumax(from + 1, &eptr, 10);
+			struct object_entry *oe;
+			if (eptr) {
+				for (; *eptr && isspace(*eptr); eptr++) ;
+				if (*eptr)
+					die("Garbage after mark: %s",
+					    command_buf.buf);
+			}
+			oe = find_mark(idnum);
 			if (oe->type != OBJ_COMMIT)
 				die("Mark :%" PRIuMAX " not a commit", idnum);
 			hashcpy(n->sha1, oe->idx.sha1);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 0f5b5e5..46346cd 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -2635,4 +2635,108 @@ test_expect_success \
 	'n=$(grep $a verify | wc -l) &&
 	 test 1 = $n'
 
+###
+### series S
+###
+#
+# Set up 1, 2, 3 of this:
+#
+# 1--2--4
+#  \   /
+#   -3-
+#
+# Then typo the merge to create #4, make sure it complains.
+#
+test_tick
+cat >input <<INPUT_END
+commit refs/heads/S
+mark :1
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+blob 1
+COMMIT
+M 100644 inline hello.c
+data <<BLOB
+blob 1
+BLOB
+
+commit refs/heads/S
+mark :2
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+blob 2
+COMMIT
+from :1
+M 100644 inline hello.c
+data <<BLOB
+blob 2
+BLOB
+INPUT_END
+
+test_expect_success 'S: add commits' '
+	git fast-import --export-marks=marks <input
+'
+
+cat >input <<INPUT_END
+blob
+mark :103
+data <<BLOB
+blob 3
+BLOB
+
+commit refs/heads/S2
+mark :3
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+blob 3
+COMMIT
+from :1M 100644 :103 hello.c
+INPUT_END
+
+test_expect_success 'S: from mark line overrun' '
+	test_must_fail git fast-import --import-marks=marks <input
+'
+
+cat >input <<INPUT_END
+blob
+mark :103
+data <<BLOB
+blob 3
+BLOB
+
+commit refs/heads/S2
+mark :3
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+blob 3
+COMMIT
+from :1
+M 100644 :103 hello.c
+INPUT_END
+
+test_expect_success 'S: add from commit' '
+	git fast-import --import-marks=marks --export-marks=marks <input
+'
+
+cat >input <<INPUT_END
+blob
+mark :104
+data <<BLOB
+blob 4
+BLOB
+
+commit refs/heads/S
+mark :4
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+blob 4
+COMMIT
+from :2
+merge :3M 100644 :4 hello.c
+INPUT_END
+
+test_expect_success 'S: merge mark line overrun' '
+	test_must_fail git fast-import --import-marks=marks <input
+'
+
 test_done
-- 
1.7.10.rc2.55.gb775a

             reply	other threads:[~2012-04-01 22:54 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-01 22:54 Pete Wyckoff [this message]
2012-04-01 23:12 ` [PATCH] fast-import: catch garbage after marks in from/merge Jonathan Nieder
2012-04-02  0:13   ` Pete Wyckoff
2012-04-02  6:56     ` Dmitry Ivankov
2012-04-02 16:16       ` Junio C Hamano
2012-04-02 15:43     ` Jonathan Nieder
2012-04-02 16:15 ` Junio C Hamano
2012-04-03  1:51 ` [PATCHv2 0/2] fast-import: tighten parsing of mark references Pete Wyckoff
2012-04-03  1:51   ` [PATCHv2 1/2] fast-import: test behavior of garbage after " Pete Wyckoff
2012-04-03 14:00     ` Jonathan Nieder
2012-04-04  0:46       ` Pete Wyckoff
2012-04-04  5:43         ` Jonathan Nieder
2012-04-03  1:51   ` [PATCHv2 2/2] fast-import: tighten parsing of " Pete Wyckoff
2012-04-03 14:20     ` Jonathan Nieder
2012-04-04  1:20       ` Pete Wyckoff
2012-04-04  5:32         ` Jonathan Nieder
2012-04-03  2:00   ` [PATCHv2 0/2] " Sverre Rabbelier
2012-04-05  1:51   ` [PATCHv3] " Pete Wyckoff
2012-04-05  2:24     ` Jonathan Nieder
2012-04-05 17:20       ` Junio C Hamano
2012-04-07 22:59     ` [PATCHv4] fast-import: tighten parsing of datarefs Pete Wyckoff
2012-04-10 21:40       ` Junio C Hamano

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=20120401225407.GA12127@padd.com \
    --to=pw@padd.com \
    --cc=divanorama@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@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.