threads / patch / 18471

patch, 4 partstest-suite: adding a test for fast-export with tag variants

Subject: [PATCH 1/4] test-suite: adding a test for fast-export with tag variants

## tl;dr

9 messages between Mar 22, 2009 and Mar 23, 2009. Diffs are folded; open one to read it.

replies: 8people: 2as markdown or json

Erik Faye-Lund· Mar 22, 2009, 21:50 UTC · lore
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 t/t9302-fast-export-tags.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100644 t/t9302-fast-export-tags.sh
Show changes to t/t9302-fast-export-tags.sh +25 −0
diff --git a/t/t9302-fast-export-tags.sh b/t/t9302-fast-export-tags.sh
new file mode 100644
index 0000000..2ecac32
--- /dev/null
+++ b/t/t9302-fast-export-tags.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Erik Faye-Lund
+#
+
+test_description='git fast-export tag variants'
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	touch dummy &&
+	git add dummy &&
+	git commit -m "initial commit" &&
+	HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` &&
+	git tag    tree_tag        -m "tagging a tree" $HEAD_TREE &&
+	git tag -a tree_tag-obj    -m "tagging a tree" $HEAD_TREE &&
+	git tag    tag-obj_tag     -m "tagging a tag" tree_tag-obj &&
+	git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
+'
+
+test_expect_success 'tree_tag'        'git fast-export tree_tag'
+test_expect_success 'tree_tag-obj'    'git fast-export tree_tag-obj'
+test_expect_success 'tag-obj_tag'     'git fast-export tag-obj_tag'
+test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
+
+test_done
-- 
1.6.2.1.226.gcb2dd
Erik Faye-Lund· Mar 22, 2009, 21:50 UTC · re: Erik Faye-Lund · lore

[PATCH 2/4] builtin-fast-export.c: turn error into warning

fast-import doesn't have a syntax to support tree-objects (and some other object-types), so fast-export shouldn't handle them. However, aborting the operation is a bit drastic. This patch turns the error into a warning instead.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 builtin-fast-export.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
Show changes to builtin-fast-export.c +4 −2
diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index fdf4ae9..02bad1f 100644
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
@@ -378,8 +378,10 @@ static void get_tags_and_duplicates(struct object_array *pending,
 			}
 			break;
 		default:
-			die ("Unexpected object of type %s",
-			     typename(e->item->type));
+			warning("%s: Unexpected object of type %s, skipping.",
+			        e->name,
+			        typename(e->item->type));
+			continue;
 		}
 		if (commit->util)
 			/* more than one name for the same object */
-- 
1.6.2.1.226.gcb2dd
Erik Faye-Lund· Mar 22, 2009, 21:50 UTC · re: Erik Faye-Lund · lore

[PATCH 3/4] builtin-fast-export.c: fix crash on tagged trees

If a tag object points to a tree (or another unhandled type), the commit- pointer is left uninitialized and later dereferenced. This patch adds a default case to the switch that issues a warning and skips the object.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 builtin-fast-export.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Show changes to builtin-fast-export.c +4 −0
diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index 02bad1f..c3ce320 100644
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
@@ -375,6 +375,10 @@ static void get_tags_and_duplicates(struct object_array *pending,
 			case OBJ_BLOB:
 				handle_object(tag->object.sha1);
 				continue;
+			default: /* OBJ_TAG (nested tags) is already handled */
+				warning("Tag points to object of unexpected type %s, skipping.",
+				        typename(tag->object.type));
+				continue;
 			}
 			break;
 		default:
-- 
1.6.2.1.226.gcb2dd
Erik Faye-Lund· Mar 22, 2009, 21:50 UTC · re: Erik Faye-Lund · lore

[PATCH 4/4] builtin-fast-export.c: handle nested tags

When tags that points to tags are passed to fast-export, an error saying "Tag [TAGNAME] points nowhere?". This fix calls parse_object() on the object before referencing it's tag, to ensure the tag-info is fully initialized. In addition, it inserts a comment to point out where nested tags are handled. This is consistent with the comment for signed tags.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 builtin-fast-export.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to builtin-fast-export.c +3 −0
diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index c3ce320..8083c5f 100644
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
@@ -362,7 +362,10 @@ static void get_tags_and_duplicates(struct object_array *pending,
 			break;
 		case OBJ_TAG:
 			tag = (struct tag *)e->item;
+
+			/* handle nested tags */
 			while (tag && tag->object.type == OBJ_TAG) {
+				parse_object(tag->object.sha1);
 				string_list_append(full_name, extra_refs)->util = tag;
 				tag = (struct tag *)tag->tagged;
 			}
-- 
1.6.2.1.226.gcb2dd
Junio C Hamano· Mar 23, 2009, 00:39 UTC · re: Erik Faye-Lund · lore

Re: [PATCH 3/4] builtin-fast-export.c: fix crash on tagged trees

Erik Faye-Lund <kusmabite@gmail.com> writes:
Show 18 quoted lines
> If a tag object points to a tree (or another unhandled type), the commit-
> pointer is left uninitialized and later dereferenced. This patch adds a default
> case to the switch that issues a warning and skips the object.
>
> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
> ---
>  builtin-fast-export.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/builtin-fast-export.c b/builtin-fast-export.c
> index 02bad1f..c3ce320 100644
> --- a/builtin-fast-export.c
> +++ b/builtin-fast-export.c
> @@ -375,6 +375,10 @@ static void get_tags_and_duplicates(struct object_array *pending,
>  			case OBJ_BLOB:
>  				handle_object(tag->object.sha1);
>  				continue;
> +			default: /* OBJ_TAG (nested tags) is already handled */

The comment is good but only if you make this the last patch that comes after the one that actually fixes the tag-to-tag (currently 4/4), no?

Show 8 quoted lines
> +				warning("Tag points to object of unexpected type %s, skipping.",
> +				        typename(tag->object.type));
> +				continue;
>  			}
>  			break;
>  		default:
> -- 
> 1.6.2.1.226.gcb2dd
Erik Faye-Lund· Mar 23, 2009, 01:01 UTC · re: Junio C Hamano · lore

Re: [PATCH 3/4] builtin-fast-export.c: fix crash on tagged trees

> The comment is good but only if you make this the last patch that comes
> after the one that actually fixes the tag-to-tag (currently 4/4), no?

Ah, good catch! I'll reorder the commits. The order of the last two patches isn't really important, so if it makes the comment more senseful, I'm all for it ;)

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656
Junio C Hamano· Mar 23, 2009, 00:39 UTC · re: Erik Faye-Lund · lore

Re: [PATCH 1/4] test-suite: adding a test for fast-export with tag variants

Erik Faye-Lund <kusmabite@gmail.com> writes:
Show 8 quoted lines
> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
> ---
>  t/t9302-fast-export-tags.sh |   25 +++++++++++++++++++++++++
>  1 files changed, 25 insertions(+), 0 deletions(-)
>  create mode 100644 t/t9302-fast-export-tags.sh
>
> diff --git a/t/t9302-fast-export-tags.sh b/t/t9302-fast-export-tags.sh
> new file mode 100644

Make it executable if you need to add a new script, but shouldn't these small tests be done as an addition to existing t9301, not as a brand new script?

Show 29 quoted lines
> index 0000000..2ecac32
> --- /dev/null
> +++ b/t/t9302-fast-export-tags.sh
> @@ -0,0 +1,25 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2009 Erik Faye-Lund
> +#
> +
> +test_description='git fast-export tag variants'
> +. ./test-lib.sh
> +
> +test_expect_success 'setup' '
> +	touch dummy &&
> +	git add dummy &&
> +	git commit -m "initial commit" &&
> +	HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` &&
> +	git tag    tree_tag        -m "tagging a tree" $HEAD_TREE &&
> +	git tag -a tree_tag-obj    -m "tagging a tree" $HEAD_TREE &&
> +	git tag    tag-obj_tag     -m "tagging a tag" tree_tag-obj &&
> +	git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
> +'
> +
> +test_expect_success 'tree_tag'        'git fast-export tree_tag'
> +test_expect_success 'tree_tag-obj'    'git fast-export tree_tag-obj'
> +test_expect_success 'tag-obj_tag'     'git fast-export tag-obj_tag'
> +test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
> +
> +test_done

The purpose of the first patch that adds tests is to expose existing problems, and it is better to say test_expect_failure in them. Later patch to fix these issues will contain code change and also change to flip some of the expect_failure to expect_success, and that way we can see what issue is fixed with which patch more easily.

These tests seem to only care about fast-export not dying, but don't we also want to check if they produce correct results?

Erik Faye-Lund· Mar 23, 2009, 00:55 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/4] test-suite: adding a test for fast-export with tag variants

On Mon, Mar 23, 2009 at 1:39 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
>> diff --git a/t/t9302-fast-export-tags.sh b/t/t9302-fast-export-tags.sh
>> new file mode 100644
>
> Make it executable if you need to add a new script, but shouldn't these
> small tests be done as an addition to existing t9301, not as a brand new
> script?
Sure, will do. I just have to figure out how to make it executable in windows ;)

As this is my first test, I was wondering a bit about how much I could depend on the state of the repo, so I was a bit reluctant to add it to the same test. But I guess it's easier for everyone in the long term to put it into the same test, so I'll give it a go.

Show 12 quoted lines
>> +test_expect_success 'tree_tag'        'git fast-export tree_tag'
>> +test_expect_success 'tree_tag-obj'    'git fast-export tree_tag-obj'
>> +test_expect_success 'tag-obj_tag'     'git fast-export tag-obj_tag'
>> +test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
>> +
>> +test_done
>
> The purpose of the first patch that adds tests is to expose existing
> problems, and it is better to say test_expect_failure in them.  Later
> patch to fix these issues will contain code change and also change to flip
> some of the expect_failure to expect_success, and that way we can see what
> issue is fixed with which patch more easily.

Sure, will do. I was a bit lazy, but updating it as we go will make stuff easier in the future.

> These tests seem to only care about fast-export not dying, but don't we
> also want to check if they produce correct results?

Well, yeah. But I was working mainly on fixing a crash-bug here, and I don't think I know enough about the correct output of fast-export to pull this off. Perhaps tighting up the test is something someone else would care to do?

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656
Junio C Hamano· Mar 23, 2009, 03:41 UTC · re: Erik Faye-Lund · lore

Re: [PATCH 1/4] test-suite: adding a test for fast-export with tag variants

Erik Faye-Lund <kusmabite@googlemail.com> writes:
Show 9 quoted lines
> On Mon, Mar 23, 2009 at 1:39 AM, Junio C Hamano <gitster@pobox.com> wrote:
> ...
>> These tests seem to only care about fast-export not dying, but don't we
>> also want to check if they produce correct results?
>
> Well, yeah. But I was working mainly on fixing a crash-bug here, and I
> don't think I know enough about the correct output of fast-export to
> pull this off. Perhaps tighting up the test is something someone else
> would care to do?
Surely; for a starter, saying something like this:

+# NEEDSWORK: not just check return status, but validate the output +test_expect_failure 'tree_tag'        'git fast-export tree_tag' +test_expect_failure 'tree_tag-obj'    'git fast-export tree_tag-obj' +test_expect_failure 'tag-obj_tag'     'git fast-export tag-obj_tag' +test_expect_failure 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'

would do, and will invite others to fill the gap when they have time.
Thanks.

← back to recent threads