git-svn: use `svn:global-ignores` to create .gitignore

`svn:global-ignores` contains a list of file patterns that should not be tracked in version control. The syntax of these patterns is the same as `svn:ignore`. Their semantics differ: patterns in `svn:global-ignores` apply to all paths under the directory where they apply, while `svn:ignore` only applies to the directory's immediate children. Signed-off-by: Alex Galvin <agalvin@comqi.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alex Galvin committed Jul 18, 2024 at 20:47 UTC d7969a51270756b1c3fe192ff9a5f159fe52aeaa
1 file changed +31 -14
git-svn.perl
+31 -14
@@ -1279,12 +1279,20 @@ sub cmd_show_ignore {
1279 $gs->prop_walk($gs->path, $r, sub {
1280 my ($gs, $path, $props) = @_;
1281 print STDOUT "\n# $path\n";
1282 - my $s = $props->{'svn:ignore'} or return;
1283 - $s =~ s/[\r\n]+/\n/g;
1284 - $s =~ s/^\n+//;
1285 - chomp $s;
1286 - $s =~ s#^#$path#gm;
1287 - print STDOUT "$s\n";
1282 + if (my $s = $props->{'svn:ignore'}) {
1283 + $s =~ s/[\r\n]+/\n/g;
1284 + $s =~ s/^\n+//;
1285 + chomp $s;
1286 + $s =~ s#^#$path#gm;
1287 + print STDOUT "$s\n";
1288 + }
1289 + if (my $s = $props->{'svn:global-ignores'}) {
1290 + $s =~ s/[\r\n]+/\n/g;
1291 + $s =~ s/^\n+//;
1292 + chomp $s;
1293 + $s =~ s#^#$path**/#gm;
1294 + print STDOUT "$s\n";
1295 + }
1296 });
1297 }
1298
@@ -1315,16 +1323,25 @@ sub cmd_create_ignore {
1323 # which git won't track
1324 mkpath([$path]) unless -d $path;
1325 my $ignore = $path . '.gitignore';
1318 - my $s = $props->{'svn:ignore'} or return;
1326 open(GITIGNORE, '>', $ignore)
1327 or fatal("Failed to open `$ignore' for writing: $!");
1321 - $s =~ s/[\r\n]+/\n/g;
1322 - $s =~ s/^\n+//;
1323 - chomp $s;
1324 - # Prefix all patterns so that the ignore doesn't apply
1325 - # to sub-directories.
1326 - $s =~ s#^#/#gm;
1327 - print GITIGNORE "$s\n";
1328 + if (my $s = $props->{'svn:ignore'}) {
1329 + $s =~ s/[\r\n]+/\n/g;
1330 + $s =~ s/^\n+//;
1331 + chomp $s;
1332 + # Prefix all patterns so that the ignore doesn't apply
1333 + # to sub-directories.
1334 + $s =~ s#^#/#gm;
1335 + print GITIGNORE "$s\n";
1336 + }
1337 + if (my $s = $props->{'svn:global-ignores'}) {
1338 + $s =~ s/[\r\n]+/\n/g;
1339 + $s =~ s/^\n+//;
1340 + chomp $s;
1341 + # Global ignores apply to sub-directories, so they are
1342 + # not prefixed.
1343 + print GITIGNORE "$s\n";
1344 + }
1345 close(GITIGNORE)
1346 or fatal("Failed to close `$ignore': $!");
1347 command_noisy('add', '-f', $ignore);