A few fast-export fixups
This patch series fixes a few fast-export bugs I have come across, plus some new testcases to verify the fixes, and finally a small addition to the documentation.
PATCH 1/7 fast-export: Omit tags that tag trees
From: Elijah Newren <[email protected]>
Commit c0582c53bcf4e83bba70e1ad23abbad31f96ebc8 introduced logic to just omit tags that point to tree objects. However, a case was missed resulting in a tag being output which pointed at "mark :0", which would cause fast-import to crash.
--- builtin-fast-export.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
builtin-fast-export.c +7 -1
@@ -407,9 +407,15 @@ static void handle_tags_and_duplicates(struct string_list *extra_refs)for (i = extra_refs->nr -1 ; i >=0 ; i--) {const char *name = extra_refs->items[i].string;struct object *object = extra_refs->items[i].util; +struct tag *tag;switch (object->type) {case OBJ_TAG : -handle_tag (name, (struct tag *)object); + tag = (struct tag *)object; +if (tag->tagged->type ==OBJ_TREE ) { +/* Ignore this tag altogether */ +return ; + } +handle_tag (name, tag);break ;case OBJ_COMMIT :/* create refs pointing to already seen commits */
Signature · 1 line
1.6.3.2.323.gfb84f
Re: [PATCH 1/7] fast-export: Omit tags that tag trees
Quoted 6 lines · On Fri, Jun 19, 2009 at 10:36:57PM -0600, [email protected] wrote:
From: Elijah Newren <[email protected]>
Commit
c0582c53bcf4e83bba70e1ad23abbad31f96ebc8introduced logic to just omit tags that point to tree objects. However, a case was missed resulting in a tag being output which pointed at "mark :0", which would cause fast-import to crash.
Do we really want to disallow tags pointing to trees? There is at least one well-known case in use (kernel v2.6.11).
Also, (and I haven't investigated at all), this sounds like the same issue we have with tags pointing to tags. IOW, everything referenceable should be given a mark, but it is not currently. I posted a "how about this" patch for the tag case here:
http://article.gmane.org/gmane.comp.version-control.git/119245
but I never got around to following it up with tests. Could you do something similar for the tree case?
-Peff
Re: [PATCH 1/7] fast-export: Omit tags that tag trees
Hi,
Quoted 8 lines · Jeff King
Do we really want to disallow tags pointing to trees? There is at least one well-known case in use (kernel v2.6.11).
Also, (and I haven't investigated at all), this sounds like the same issue we have with tags pointing to tags. IOW, everything referenceable should be given a mark, but it is not currently. I posted a "how about this" patch for the tag case here:
Quoted 4 lines
http://article.gmane.org/gmane.comp.version-control.git/119245
but I never got around to following it up with tests. Could you do something similar for the tree case?
I don't see how we could do something similar for the tree case without making some significant change to the output/input of both fast-export and fast-import. Tag objects are part of the output of fast-export, thus we can add a mark line to give the object a name and thus provide us a valid mark we can make the outer tag point to. Trees are not output by fast-export (other than implicitly by including files in commits), so we have nothing to point such a tag at. If we were to do something like use the full sha1sum instead of marks in such a case (which git-fast-import should currently accept), then (a) we'd break exporting a repository limited by path ('git fast-export master -- libfoo"), and (b) we'd break interoperation with other tools like bzr-fast-import (or a possible future git that uses a different checksum).
If someone wanted to tackle modifying the output/input syntax of fast-export and fast-import, maybe something could be done here, but my patch just tries to make things operate sanely within the given documented limitations (as found in the git-fast-export manpage -- "Since 'git-fast-import' cannot tag trees, you will not be able to export the linux-2.6.git repository completely, as it contains a tag referencing a tree instead of a commit.").
Elijah
Re: [PATCH 1/7] fast-export: Omit tags that tag trees
Quoted 8 lines · Elijah Newren
I don't see how we could do something similar for the tree case without making some significant change to the output/input of both fast-export and fast-import. Tag objects are part of the output of fast-export, thus we can add a mark line to give the object a name and thus provide us a valid mark we can make the outer tag point to. Trees are not output by fast-export (other than implicitly by including files in commits), so we have nothing to point such a tag at. If we were to do something like use the full sha1sum instead of
Ah, right. That falls under the "I didn't look at this too closely" part of my previous message. :)
It does seem a shame not to be able to say "and now here is a tree" in the same way we say "and now here is a commit". And since that is not possible without add-ons that might cause compatibility issues, your fix seems reasonable to at least avoid generating bogus output.
Another option would be to generate a pseudo-commit with no parentage that holds the tree, and then point the tag at that. It's obviously not exactly what the user wanted, but neither is simply omitting. You could even mark the commit message with a "THIS IS REALLY A TREE" magic string, and then have fast-import recognize and convert those back to a tree (by just peeling the commit away).
-Peff
PATCH 2/7 Modify fast-export testcase to check that we correctly omit tags of trees
In reply to [email protected]From: Elijah Newren <[email protected]>
---
Should I have just squashed this with the previous patch? Or with the other testcase patch?
t/t9301-fast-export.sh | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
t/t9301-fast-export.sh +7 -1
@@ -272,7 +272,13 @@ test_expect_success 'set-up a few more tags for tag export tests' ' ' # NEEDSWORK: not just check return status, but validate the output -test_expect_success 'tree_tag' 'git fast-export tree_tag' +test_expect_success 'tree_tag' ' + mkdir result && + cd result && + git init && + cd .. + git fast-export tree_tag | (cd result && git fast-import) +' 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'
Signature · 1 line
1.6.3.2.323.gfb84f
Re: [PATCH 2/7] Modify fast-export testcase to check that we correctly omit tags of trees
t/t9301-fast-export.sh test_expect_success 'set-up a few more tags for tag export tests' ' · line 281
Quoted 8 lines · On Samstag, 20. Juni 2009, [email protected] wrote:
t/t9301-fast-export.sh +7
-1-test_expect_success 'tree_tag' 'git fast-export tree_tag' +test_expect_success 'tree_tag' ' + mkdir result && + cd result && + git init && + cd .. + git fast-export tree_tag | (cd result && git fast-import) +'
You should make this
test_expect_success 'tree_tag' '
mkdir result && (cd result && git init) && git fast-export tree_tag > fe-stream && (cd result && git fast-import < fe-stream)
'
in order to (1) not remain in the wrong directory if git init fails, and (2) to catch failures in git fast-export.
-- Hannes
Re: [PATCH 2/7] Modify fast-export testcase to check that we correctly omit tags of trees
Quoted 19 lines · Johannes Sixt
t/t9301-fast-export.sh test_expect_success 'set-up a few more tags for tag export tests' ' · line 281
Quoted 8 lines · On Samstag, 20. Juni 2009, [email protected] wrote:
t/t9301-fast-export.sh +7
-1-test_expect_success 'tree_tag' 'git fast-export tree_tag' +test_expect_success 'tree_tag' ' + mkdir result && + cd result && + git init && + cd .. + git fast-export tree_tag | (cd result && git fast-import) +'You should make this
test_expect_success'tree_tag' '
mkdir result &&
(cd result && git init) &&
git fast-exporttree_tag> fe-stream &&
(cd result && git fast-import < fe-stream)
'
Quoted 2 lines
in order to (1) not remain in the wrong directory if git init fails, and (2) to catch failures in git fast-export.
Thanks for the tips; I've sent a new patch series with these changes (except that the second fe-stream needs a ../ in front of it), as well as the changes suggested by Stephen Boyd in the other email in this thread.
Elijah
Re: [PATCH 2/7] Modify fast-export testcase to check that we correctly omit tags of trees
In reply to [email protected]Quoted 2 lines · [email protected] wrote:
Should I have just squashed this with the previous patch? Or with the other testcase patch?
I think squashing it with the previous one is better as long as this is directly related to patch 1.
t/t9301-fast-export.sh test_expect_success 'set-up a few more tags for tag export tests' ' · line 274
Quoted 12 lines
t/t9301-fast-export.sh | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)t/t9301-fast-export.sh +0
-0@@ -272,7 +272,13 @@ test_expect_success 'set-up a few more tags for tag export tests' ' ' # NEEDSWORK: not just check return status, but validate the output
Is this comment still relevant?
t/t9301-fast-export.sh test_expect_success 'set-up a few more tags for tag export tests' ' · line 284
Quoted 11 lines
t/t9301-fast-export.sh +7
-1-test_expect_success 'tree_tag' 'git fast-export tree_tag' +test_expect_success 'tree_tag' ' + mkdir result && + cd result && + git init && + cd .. + git fast-export tree_tag | (cd result && git fast-import) +' 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'
I don't really know, but could test_create_repo() be useful here?
PATCH 3/7 fast-export: Make sure we show actual ref names instead of "(null)"
In reply to [email protected]From: Elijah Newren <[email protected]>
Under some cases (e.g. 'git fast-export --parents master -- COPYING' run in git.git), the output included the lines
reset (null)
commit (null)
instead of
reset refs/heads/master
commit refs/heads/master
This simple change fixes that.
---
As noted above, run 'git fast-export --parents master -- COPYING' in git.git to see this bug triggered.
builtin-fast-export.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
builtin-fast-export.c +1 -0
@@ -531,6 +531,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)get_tags_and_duplicates (&revs.pending, &extra_refs); revs.topo_order =1 ; + revs.show_source =1 ;if (prepare_revision_walk (&revs))die ("revision walk setup failed" ); revs.diffopt.format_callback = show_filemodify;
Signature · 1 line
1.6.3.2.323.gfb84f
PATCH 4/7 fast-export: Do parent rewriting to avoid dropping relevant commits
In reply to [email protected]From: Elijah Newren <[email protected]>
When specifying paths to export, parent rewriting must be turned on for fast-export to output anything at all.
---
Try 'git fast-export master -- COPYING' in git.git and notice how there is no output at all (whereas 'git rev-list master -- COPYING' does show some existing revisions). This simple patch restores the missing file and commit in the fast-export output.
builtin-fast-export.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
builtin-fast-export.c +1 -0
@@ -532,6 +532,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) revs.topo_order =1 ; revs.show_source =1 ; + revs.rewrite_parents =1 ;if (prepare_revision_walk (&revs))die ("revision walk setup failed" ); revs.diffopt.format_callback = show_filemodify;
Signature · 1 line
1.6.3.2.323.gfb84f
PATCH 5/7 fast-export: Add a --tag-of-filtered-object option for newly dangling tags
In reply to [email protected]From: Elijah Newren <[email protected]>
When providing a list of paths to limit what is exported, the object that a tag points to can be filtered out entirely. This new switch allows the user to specify what should happen to the tag in such a case. The default action, 'abort' will exit with an error message. With 'drop', the tag will simply be omitted from the output. With 'rewrite', if the object tagged was a commit, the tag will be modified to tag an ancestor of the removed commit.
---
I had a hard time coming up with a decent option name. If anyone has a better suggestion for the name, I'm all ears.
To see a case where this bug is triggered, run
git fast-export --signed-tag=strip v1.6.3.2 -- COPYING
in git.git and note that the tag that is output points to 'mark :0' (a non-existent mark), which will cause fast-import to crash.
Documentation/git-fast-export.txt | 11 ++++++ builtin-fast-export.c | 64 +++++++++++++++++++++++++++++++++--- revision.c | 10 +----- revision.h | 8 +++++ 4 files changed, 79 insertions(+), 14 deletions(-)
Documentation/git-fast-export.txt +11 -0
@@ -36,6 +36,17 @@ when encountering a signed tag. With 'strip', the tags will be made unsigned, with 'verbatim', they will be silently exported and with 'warn', they will be exported, but you will see a warning. +--tag-of-filtered-object=(abort|drop|rewrite):: + Specify how to handle tags whose tagged objectis filtered out. + Since revisions and files to export can be limited by path, + tagged objects may be filtered completely. ++ +When asking to 'abort' (which is the default), this program will die +when encountering such a tag. With 'drop' it will omit such tags from +the output. With 'rewrite', if the tagged object is a commit, it will +rewrite the tag to tag an ancestor commit (via parent rewriting; see +linkgit:git-rev-list[1]) + -M:: -C:: Perform move and/or copy detection, as described in the
builtin-fast-export.c +58 -6
121 lines not on this page · raw message
revision.c +2 -8
@@ -1601,13 +1601,7 @@ int prepare_revision_walk(struct rev_info *revs)return 0 ; } -enum rewrite_result { - rewrite_one_ok, - rewrite_one_noparents, - rewrite_one_error, -}; - -static enum rewrite_result rewrite_one (struct rev_info *revs,struct commit **pp) +enum rewrite_result rewrite_one_commit (struct rev_info *revs,struct commit **pp) {struct commit_list *cache =NULL ;
@@ -1633,7 +1627,7 @@ static int rewrite_parents(struct rev_info *revs, struct commit *commit)struct commit_list **pp = &commit->parents;while (*pp) {struct commit_list *parent = *pp; -switch (rewrite_one (revs, &parent->item)) { +switch (rewrite_one_commit (revs, &parent->item)) {case rewrite_one_ok:break ;case rewrite_one_noparents:
revision.h +8 -0
@@ -158,6 +158,14 @@ extern void add_pending_object(struct rev_info *revs, struct object *obj, constextern void add_head_to_pending (struct rev_info *); +enum rewrite_result { + rewrite_one_ok, + rewrite_one_noparents, + rewrite_one_error, +}; + +extern enum rewrite_result rewrite_one_commit (struct rev_info *revs,struct commit **pp); +enum commit_action { commit_ignore, commit_show,
Signature · 1 line
1.6.3.2.323.gfb84f
PATCH 6/7 Add new fast-export testcases
In reply to [email protected]From: Elijah Newren <[email protected]>
The testcases test the new --tag-of-filtered-object option, and test the output when limiting what to export by path.
--- t/t9301-fast-export.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-)
t/t9301-fast-export.sh +55 -0
@@ -262,6 +262,61 @@ test_expect_success 'cope with tagger-less tags' ' ' +test_expect_success 'setup for limiting exports by PATH' ' + mkdir limit-by-paths && + cd limit-by-paths && + git init && + echo hi > there && + git add there && + git commit -m "First file" && + echo foo > bar && + git add bar && + git commit -m "Second file" && + git tag -a -m msg mytag && + cd .. +' + +cat > limit-by-paths/expected << EOF +blob +mark :1 +data 3 +hi + +reset refs/tags/mytag +commit refs/tags/mytag +mark :2 +author A U Thor <[email protected]> 1112912713 -0700 +committer C O Mitter <[email protected]> 1112912713 -0700 +data 11 +First file +M 100644 :1 there + +EOF + +test_expect_success 'dropping tag of filtered out object' ' + cd limit-by-paths && + git fast-export --tag-of-filtered-object=drop mytag -- there > output && + test_cmp output expected && + cd .. +' + +cat >> limit-by-paths/expected << EOF +tag mytag +from :2 +tagger C O Mitter <[email protected]> 1112912713 -0700 +data 4 +msg + +EOF + +test_expect_success 'rewriting tag of filtered out object' ' + cd limit-by-paths && + git fast-export --tag-of-filtered-object=rewrite mytag -- there > output && + test_cmp output expected && + cd .. +' + + test_expect_success 'set-up a few more tags for tag export tests' ' git checkout -f master && HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` &&
Signature · 1 line
1.6.3.2.323.gfb84f
PATCH 7/7 fast-export: Document the fact that git-rev-list arguments are accepted
In reply to [email protected]From: Elijah Newren <[email protected]>
--- Documentation/git-fast-export.txt | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
Documentation/git-fast-export.txt +6 -0
@@ -82,6 +82,12 @@ marks the same across runs. allow that. So fake a tagger to be able to fast-import the output. +[git-rev-list-args...]:: + A list of arguments, acceptable to 'git-rev-parse' and + 'git-rev-list', that specifies the specific objects and references + to export. For example, `master\~10..master` causes the + current master reference to be exported along with all objects + added since its 10th ancestor commit. EXAMPLES --------
Signature · 1 line
1.6.3.2.323.gfb84f