From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pete Wyckoff Subject: [PATCH] fast-import: catch garbage after marks in from/merge Date: Sun, 1 Apr 2012 18:54:07 -0400 Message-ID: <20120401225407.GA12127@padd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Jonathan Nieder , Dmitry Ivankov To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Mon Apr 02 00:54:20 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SETf7-0002uI-NM for gcvg-git-2@plane.gmane.org; Mon, 02 Apr 2012 00:54:18 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753535Ab2DAWyN (ORCPT ); Sun, 1 Apr 2012 18:54:13 -0400 Received: from honk.padd.com ([74.3.171.149]:47179 "EHLO honk.padd.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752777Ab2DAWyM (ORCPT ); Sun, 1 Apr 2012 18:54:12 -0400 Received: from arf.padd.com (unknown [50.55.145.32]) by honk.padd.com (Postfix) with ESMTPSA id 1DA941E66; Sun, 1 Apr 2012 15:54:11 -0700 (PDT) Received: by arf.padd.com (Postfix, from userid 7770) id E25D4313EC; Sun, 1 Apr 2012 18:54:07 -0400 (EDT) Content-Disposition: inline Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: A forgotten LF can lead to a confusing bug. The last line in this commit command is wrong: commit refs/heads/S2 committer Name 1112912893 -0400 data < --- 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 < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data <input < $GIT_COMMITTER_DATE +data <input < $GIT_COMMITTER_DATE +data <input < $GIT_COMMITTER_DATE +data <