All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] fast-import: empty/reset branch bugs
@ 2011-09-22 19:47 Dmitry Ivankov
  2011-09-22 19:47 ` [PATCH 1/2] fast-import: don't allow to tag empty branch Dmitry Ivankov
  2011-09-22 19:47 ` [PATCH 2/2] fast-import: don't allow to note on " Dmitry Ivankov
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Ivankov @ 2011-09-22 19:47 UTC (permalink / raw)
  To: git
  Cc: Jonathan Nieder, Shawn O. Pearce, David Barr, Sverre Rabbelier,
	Dmitry Ivankov

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(-)

-- 
1.7.3.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] fast-import: don't allow to tag empty branch
  2011-09-22 19:47 [PATCH 0/2] fast-import: empty/reset branch bugs Dmitry Ivankov
@ 2011-09-22 19:47 ` Dmitry Ivankov
  2011-09-22 22:28   ` Sverre Rabbelier
  2011-09-22 19:47 ` [PATCH 2/2] fast-import: don't allow to note on " Dmitry Ivankov
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Ivankov @ 2011-09-22 19:47 UTC (permalink / raw)
  To: git
  Cc: Jonathan Nieder, Shawn O. Pearce, David Barr, Sverre Rabbelier,
	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.

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

diff --git a/fast-import.c b/fast-import.c
index 742e7da..c44cc11 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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 == ':') {
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 1a6c066..0b97d7a 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -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
 ###
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] fast-import: don't allow to note on empty branch
  2011-09-22 19:47 [PATCH 0/2] fast-import: empty/reset branch bugs Dmitry Ivankov
  2011-09-22 19:47 ` [PATCH 1/2] fast-import: don't allow to tag empty branch Dmitry Ivankov
@ 2011-09-22 19:47 ` Dmitry Ivankov
  2011-09-22 22:29   ` Sverre Rabbelier
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Ivankov @ 2011-09-22 19:47 UTC (permalink / raw)
  To: git
  Cc: Jonathan Nieder, Shawn O. Pearce, David Barr, Sverre Rabbelier,
	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.

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

diff --git a/fast-import.c b/fast-import.c
index c44cc11..a8a3ad1 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -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);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 0b97d7a..bd32b91 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -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)
 ###
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] fast-import: don't allow to tag empty branch
  2011-09-22 19:47 ` [PATCH 1/2] fast-import: don't allow to tag empty branch Dmitry Ivankov
@ 2011-09-22 22:28   ` Sverre Rabbelier
  0 siblings, 0 replies; 5+ messages in thread
From: Sverre Rabbelier @ 2011-09-22 22:28 UTC (permalink / raw)
  To: Dmitry Ivankov; +Cc: git, Jonathan Nieder, Shawn O. Pearce, David Barr

Heya,

On Thu, Sep 22, 2011 at 21:47, Dmitry Ivankov <divanorama@gmail.com> wrote:
> '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.

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] fast-import: don't allow to note on empty branch
  2011-09-22 19:47 ` [PATCH 2/2] fast-import: don't allow to note on " Dmitry Ivankov
@ 2011-09-22 22:29   ` Sverre Rabbelier
  0 siblings, 0 replies; 5+ messages in thread
From: Sverre Rabbelier @ 2011-09-22 22:29 UTC (permalink / raw)
  To: Dmitry Ivankov; +Cc: git, Jonathan Nieder, Shawn O. Pearce, David Barr

Heya,

On Thu, Sep 22, 2011 at 21:47, Dmitry Ivankov <divanorama@gmail.com> wrote:
> '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.

-- 
Cheers,

Sverre Rabbelier

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-09-22 22:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 19:47 [PATCH 0/2] fast-import: empty/reset branch bugs Dmitry Ivankov
2011-09-22 19:47 ` [PATCH 1/2] fast-import: don't allow to tag empty branch Dmitry Ivankov
2011-09-22 22:28   ` Sverre Rabbelier
2011-09-22 19:47 ` [PATCH 2/2] fast-import: don't allow to note on " Dmitry Ivankov
2011-09-22 22:29   ` Sverre Rabbelier

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.