Skip to contentSkip to conversation

fast-import: empty/reset branch bugs

PATCH In review Dmitry Ivankov 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover fast-import: empty/reset branch bugs

fast-import uses null_sha1 for empty branches. It doesn't make a null_sha1 parent nor writes out a branch with null_sha1 head. But for notemodify and tag commands there is no check for null_sha1 and so bad tag/notes are produced instead of a error message.

Dmitry Ivankov (2):
fast-import: don't allow to tag empty branch
fast-import: don't allow to note on empty branch

 fast-import.c          |    4 ++++
 t/t9300-fast-import.sh |   29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/2 fast-import: don't allow to tag empty branch

'reset' command makes fast-import start a branch from scratch. It's name is kept in lookup table but it's sha1 is null_sha1 (special value). 'tag' command can be used to tag a branch by it's name. lookup_branch() is used it that case and it doesn't check for null_sha1. So fast-import writes a tag for null_sha1 object instead of giving a error.

Add a check to deny tagging an empty branch and add a corresponding test.

---
 fast-import.c          |    2 ++
 t/t9300-fast-import.sh |   12 ++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
fast-import.c +2 -0
index 742e7da..c44cc11 100644
@@ -2717,6 +2717,8 @@ static void parse_new_tag(void)
 	from = strchr(command_buf.buf, ' ') + 1;
 	s = lookup_branch(from);
 	if (s) {
+		if (is_null_sha1(s->sha1))
+			die("Can't tag an empty branch.");
 		hashcpy(sha1, s->sha1);
 		type = OBJ_COMMIT;
 	} else if (*from == ':') {
t/t9300-fast-import.sh +12 -0
index 1a6c066..0b97d7a 100755
@@ -820,6 +820,18 @@ test_expect_success \
 	'test 1 = `git rev-list J | wc -l` &&
 	 test 0 = `git ls-tree J | wc -l`'
 
+cat >input <<INPUT_END
+reset refs/heads/J2
+
+tag wrong_tag
+from refs/heads/J2
+data <<EOF
+Tag branch that was reset.
+EOF
+INPUT_END
+test_expect_success \
+	'J: tag must fail on empty branch' \
+	'test_must_fail git fast-import <input'
 ###
 ### series K
 ###
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [PATCH 1/2] fast-import: don't allow to tag empty branch

Heya,

Quoted 7 lines · Dmitry Ivankov

'reset' command makes fast-import start a branch from scratch. It's name is kept in lookup table but it's sha1 is null_sha1 (special value). 'tag' command can be used to tag a branch by it's name. lookup_branch() is used it that case and it doesn't check for null_sha1. So fast-import writes a tag for null_sha1 object instead of giving a error.

Add a check to deny tagging an empty branch and add a corresponding test.

Makes sense to me.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#3 lore raw

PATCH 2/2 fast-import: don't allow to note on empty branch

In reply to Dmitry Ivankov

'reset' command makes fast-import start a branch from scratch. It's name is kept in lookup table but it's sha1 is null_sha1 (special value). 'notemodify' command can be used to add a note on branch head given it's name. lookup_branch() is used it that case and it doesn't check for null_sha1. So fast-import writes a note for null_sha1 object instead of giving a error.

Add a check to deny adding a note on empty branch and add a corresponding test.

---
 fast-import.c          |    2 ++
 t/t9300-fast-import.sh |   17 +++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
fast-import.c +2 -0
index c44cc11..a8a3ad1 100644
@@ -2416,6 +2416,8 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)
 	/* <committish> */
 	s = lookup_branch(p);
 	if (s) {
+		if (is_null_sha1(s->sha1))
+			die("Can't add a note on empty branch.");
 		hashcpy(commit_sha1, s->sha1);
 	} else if (*p == ':') {
 		uintmax_t commit_mark = strtoumax(p + 1, NULL, 10);
t/t9300-fast-import.sh +17 -0
index 0b97d7a..bd32b91 100755
@@ -1987,6 +1987,23 @@ test_expect_success \
 	'Q: verify second note for second commit' \
 	'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
 
+cat >input <<EOF
+reset refs/heads/Q0
+
+commit refs/heads/note-Q0
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+Note for an empty branch.
+COMMIT
+
+N inline refs/heads/Q0
+data <<NOTE
+some note
+NOTE
+EOF
+test_expect_success \
+	'Q: deny note on empty branch' \
+	'test_must_fail git fast-import <input'
 ###
 ### series R (feature and option)
 ###
Signature · 1 line
1.7.3.4
#4 lore raw

Re: [PATCH 2/2] fast-import: don't allow to note on empty branch

Heya,

Quoted 9 lines · Dmitry Ivankov

'reset' command makes fast-import start a branch from scratch. It's name is kept in lookup table but it's sha1 is null_sha1 (special value). 'notemodify' command can be used to add a note on branch head given it's name. lookup_branch() is used it that case and it doesn't check for null_sha1. So fast-import writes a note for null_sha1 object instead of giving a error.

Add a check to deny adding a note on empty branch and add a corresponding test.

Makes sense as well.

Signature · 3 lines
Cheers,

Sverre Rabbelier