@matheusbsbs / matheus-bagliano / commits / d05ddec51e
Fork 0

git-svn: implement git svn create-ignore

git svn create-ignore (to create one .gitignore per directory from the svn:ignore properties. This has the disadvantage of committing the .gitignore during the next dcommit, but when you import a repo with tons of ignores (>1000), using git svn show-ignore to build .git/info/exclude is *not* a good idea, because things like git-status will end up doing >1000 fnmatch *per file* in the repo, which leads to git-status taking more than 4s on my Core2Duo 2Ghz 2G RAM) * git-svn.perl (%cmd): Add the new command `create-ignore'. (&cmd_create_ignore): New. * t/t9101-git-svn-props.sh: Adjust the test-case for show-ignore and add a test case for create-ignore. [ew: added commit message from <05CAB148-56ED-4FF1-8AAB-4BA2A0B70C2C@lrde.epita.fr> ] Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Benoit Sigoure committed Oct 16, 2007 at 16:36 UTC d05ddec51e4e23923f8f6c633f0a125c9a27a391
2 files changed +52 -3
git-svn.perl
+27
@@ -123,6 +123,10 @@ my %cmd = (
123 'set-tree' => [ \&cmd_set_tree,
124 "Set an SVN repository to a git tree-ish",
125 { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
126 + 'create-ignore' => [ \&cmd_create_ignore,
127 + 'Create a .gitignore per svn:ignore',
128 + { 'revision|r=i' => \$_revision
129 + } ],
130 'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
131 { 'revision|r=i' => \$_revision
132 } ],
@@ -499,6 +503,29 @@ sub cmd_show_ignore {
503 });
504 }
505
506 +sub cmd_create_ignore {
507 + my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
508 + $gs ||= Git::SVN->new;
509 + my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
510 + $gs->prop_walk($gs->{path}, $r, sub {
511 + my ($gs, $path, $props) = @_;
512 + # $path is of the form /path/to/dir/
513 + my $ignore = '.' . $path . '.gitignore';
514 + my $s = $props->{'svn:ignore'} or return;
515 + open(GITIGNORE, '>', $ignore)
516 + or fatal("Failed to open `$ignore' for writing: $!\n");
517 + $s =~ s/[\r\n]+/\n/g;
518 + chomp $s;
519 + # Prefix all patterns so that the ignore doesn't apply
520 + # to sub-directories.
521 + $s =~ s#^#/#gm;
522 + print GITIGNORE "$s\n";
523 + close(GITIGNORE)
524 + or fatal("Failed to close `$ignore': $!\n");
525 + command_noisy('add', $ignore);
526 + });
527 +}
528 +
529 sub cmd_multi_init {
530 my $url = shift;
531 unless (defined $_trunk || defined $_branches || defined $_tags) {
t/t9101-git-svn-props.sh
+25 -3
@@ -126,19 +126,20 @@ cat > show-ignore.expect <<\EOF
126 # /
127 /no-such-file*
128
129 -# deeply
129 +# /deeply/
130 /deeply/no-such-file*
131
132 -# deeply/nested
132 +# /deeply/nested/
133 /deeply/nested/no-such-file*
134
135 -# deeply/nested/directory
135 +# /deeply/nested/directory/
136 /deeply/nested/directory/no-such-file*
137 EOF
138
139 test_expect_success 'test show-ignore' "
140 cd test_wc &&
141 mkdir -p deeply/nested/directory &&
142 + touch deeply/nested/directory/.keep &&
143 svn add deeply &&
144 svn up &&
145 svn propset -R svn:ignore 'no-such-file*' .
@@ -148,4 +149,25 @@ test_expect_success 'test show-ignore' "
149 cmp show-ignore.expect show-ignore.got
150 "
151
152 +cat >create-ignore.expect <<\EOF
153 +/no-such-file*
154 +EOF
155 +
156 +cat >create-ignore-index.expect <<\EOF
157 +100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 .gitignore
158 +100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 deeply/.gitignore
159 +100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 deeply/nested/.gitignore
160 +100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 deeply/nested/directory/.gitignore
161 +EOF
162 +
163 +test_expect_success 'test create-ignore' "
164 + git-svn fetch && git pull . remotes/git-svn &&
165 + git-svn create-ignore &&
166 + cmp ./.gitignore create-ignore.expect &&
167 + cmp ./deeply/.gitignore create-ignore.expect &&
168 + cmp ./deeply/nested/.gitignore create-ignore.expect &&
169 + cmp ./deeply/nested/directory/.gitignore create-ignore.expect &&
170 + git ls-files -s | grep gitignore | cmp - create-ignore-index.expect
171 + "
172 +
173 test_done