fast-export: add support to delete refs

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Apr 20, 2014 at 13:59 UTC 60ed26438c909fd273528e67b399ee6ca4028e1e
2 files changed +25
builtin/fast-export.c
+14
@@ -673,6 +673,19 @@ static void import_marks(char *input_file)
673 fclose(f);
674 }
675
676 +static void handle_deletes(void)
677 +{
678 + int i;
679 + for (i = 0; i < refspecs_nr; i++) {
680 + struct refspec *refspec = &refspecs[i];
681 + if (*refspec->src)
682 + continue;
683 +
684 + printf("reset %s\nfrom %s\n\n",
685 + refspec->dst, sha1_to_hex(null_sha1));
686 + }
687 +}
688 +
689 int cmd_fast_export(int argc, const char **argv, const char *prefix)
690 {
691 struct rev_info revs;
@@ -764,6 +777,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
777 }
778
779 handle_tags_and_duplicates();
780 + handle_deletes();
781
782 if (export_filename && lastimportid != last_idnum)
783 export_marks(export_filename);
t/t9350-fast-export.sh
+11
@@ -511,4 +511,15 @@ test_expect_success 'use refspec' '
511 test_cmp expected actual
512 '
513
514 +test_expect_success 'delete refspec' '
515 + git branch to-delete &&
516 + git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual &&
517 + cat > expected <<-EOF &&
518 + reset refs/heads/to-delete
519 + from 0000000000000000000000000000000000000000
520 +
521 + EOF
522 + test_cmp expected actual
523 +'
524 +
525 test_done