fast-export: don't handle uninteresting refs

They have been marked as UNINTERESTING for a reason, lets respect that. Currently the first ref is handled properly, but not the rest. Assuming that all the refs point at the same commit in the following example: % git fast-export master ^uninteresting ^foo ^bar reset refs/heads/bar from :0 reset refs/heads/foo from :0 reset refs/heads/uninteresting from :0 % git fast-export ^uninteresting ^foo ^bar master reset refs/heads/master from :0 reset refs/heads/bar from :0 reset refs/heads/foo from :0 Clearly this is wrong; the negative refs should be ignored. After this patch: % git fast-export ^uninteresting ^foo ^bar master # nothing % git fast-export master ^uninteresting ^foo ^bar # nothing And even more, it would only happen if the ref is pointing to exactly the same commit, but not otherwise: % git fast-export ^next next reset refs/heads/next from :0 % git fast-export ^next next^{commit} # nothing % git fast-export ^next next~0 # nothing % git fast-export ^next next~1 # nothing % git fast-export ^next next~2 # nothing The reason this happens is that before traversing the commits, fast-export checks if any of the refs point to the same object, and any duplicated ref gets added to a list in order to issue 'reset' commands after the traversing. Unfortunately, it's not even checking if the commit is flagged as UNINTERESTING. The fix of course, is to check it. However, in order to do it properly we need to get the UNINTERESTING flag from the command line, not from the commit object, because "^foo bar" will mark the commit 'bar' uninteresting if foo and bar points at the same commit. rev_cmdline_info, which was introduced exactly to handle this situation, contains all the information we need for get_tags_and_duplicates(), plus the ref flag. This way the rest of the positive refs will remain untouched; it's only the negative ones that change in behavior. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Nov 28, 2012 at 23:23 UTC 49266e8a11cffa1bb41217021470e33d26109bb2
3 files changed +45 -4
builtin/fast-export.c
+7 -4
@@ -474,18 +474,21 @@ static void handle_tag(const char *name, struct tag *tag)
474 (int)message_size, (int)message_size, message ? message : "");
475 }
476
477 -static void get_tags_and_duplicates(struct object_array *pending,
477 +static void get_tags_and_duplicates(struct rev_cmdline_info *info,
478 struct string_list *extra_refs)
479 {
480 struct tag *tag;
481 int i;
482
483 - for (i = 0; i < pending->nr; i++) {
484 - struct object_array_entry *e = pending->objects + i;
483 + for (i = 0; i < info->nr; i++) {
484 + struct rev_cmdline_entry *e = info->rev + i;
485 unsigned char sha1[20];
486 struct commit *commit;
487 char *full_name;
488
489 + if (e->flags & UNINTERESTING)
490 + continue;
491 +
492 if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
493 continue;
494
@@ -681,7 +684,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
684 if (import_filename && revs.prune_data.nr)
685 full_tree = 1;
686
684 - get_tags_and_duplicates(&revs.pending, &extra_refs);
687 + get_tags_and_duplicates(&revs.cmdline, &extra_refs);
688
689 if (prepare_revision_walk(&revs))
690 die("revision walk setup failed");
t/t5801-remote-helpers.sh
+8
@@ -162,4 +162,12 @@ test_expect_failure 'pushing without marks' '
162 compare_refs local2 HEAD server HEAD
163 '
164
165 +test_expect_success 'push all with existing object' '
166 + (cd local &&
167 + git branch dup2 master &&
168 + git push origin --all
169 + ) &&
170 + compare_refs local dup2 server dup2
171 +'
172 +
173 test_done
t/t9350-fast-export.sh
+30
@@ -454,4 +454,34 @@ test_expect_success 'test bidirectionality' '
454 git fast-import --export-marks=marks-cur --import-marks=marks-cur
455 '
456
457 +cat > expected << EOF
458 +blob
459 +mark :13
460 +data 5
461 +bump
462 +
463 +commit refs/heads/master
464 +mark :14
465 +author A U Thor <author@example.com> 1112912773 -0700
466 +committer C O Mitter <committer@example.com> 1112912773 -0700
467 +data 5
468 +bump
469 +from :12
470 +M 100644 :13 file
471 +
472 +EOF
473 +
474 +test_expect_success 'avoid uninteresting refs' '
475 + > tmp-marks &&
476 + git fast-export --import-marks=tmp-marks \
477 + --export-marks=tmp-marks master > /dev/null &&
478 + git tag v1.0 &&
479 + git branch uninteresting &&
480 + echo bump > file &&
481 + git commit -a -m bump &&
482 + git fast-export --import-marks=tmp-marks \
483 + --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
484 + test_cmp expected actual
485 +'
486 +
487 test_done