Skip to content

Commit 55f9d7a

Browse files
mhaggergitster
authored andcommitted
git-svn: add an option to skip the creation of empty directories
"git svn mkdirs" (which creates empty directories in the current working copy) can be very slow and is often unnecessary. Provide a config file option "svn-remote.<name>.automkdirs" that prevents empty directories from being created automatically. (They are still created if "git svn mkdirs" is invoked explicitly.) Based-on-patch-by: Junio C Hamano <[email protected]> Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6acef04 commit 55f9d7a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

Documentation/git-svn.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ Any other arguments are passed directly to 'git log'
343343
Empty directories are automatically recreated when using
344344
"git svn clone" and "git svn rebase", so "mkdirs" is intended
345345
for use after commands like "git checkout" or "git reset".
346+
(See the svn-remote.<name>.automkdirs config file option for
347+
more information.)
346348

347349
'commit-diff'::
348350
Commits the diff of two tree-ish arguments from the
@@ -663,6 +665,14 @@ svn.pathnameencoding::
663665
locales to avoid corrupted file names with non-ASCII characters.
664666
Valid encodings are the ones supported by Perl's Encode module.
665667

668+
svn-remote.<name>.automkdirs::
669+
Normally, the "git svn clone" and "git svn rebase" commands
670+
attempt to recreate empty directories that are in the
671+
Subversion repository. If this option is set to "false", then
672+
empty directories will only be created if the "git svn mkdirs"
673+
command is run explicitly. If unset, 'git svn' assumes this
674+
option to be "true".
675+
666676
Since the noMetadata, rewriteRoot, rewriteUUID, useSvnsyncProps and useSvmProps
667677
options all affect the metadata generated and used by 'git svn'; they
668678
*must* be set in the configuration file before any history is imported

git-svn.perl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,15 @@ sub cmd_find_rev {
781781
print "$result\n" if $result;
782782
}
783783

784+
sub auto_create_empty_directories {
785+
my ($gs) = @_;
786+
my $var = eval { command_oneline('config', '--get', '--bool',
787+
"svn-remote.$gs->{repo_id}.automkdirs") };
788+
# By default, create empty directories by consulting the unhandled log,
789+
# but allow setting it to 'false' to skip it.
790+
return !($var && $var eq 'false');
791+
}
792+
784793
sub cmd_rebase {
785794
command_noisy(qw/update-index --refresh/);
786795
my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
@@ -804,7 +813,9 @@ sub cmd_rebase {
804813
$_fetch_all ? $gs->fetch_all : $gs->fetch;
805814
}
806815
command_noisy(rebase_cmd(), $gs->refname);
807-
$gs->mkemptydirs;
816+
if (auto_create_empty_directories($gs)) {
817+
$gs->mkemptydirs;
818+
}
808819
}
809820

810821
sub cmd_show_ignore {
@@ -1242,7 +1253,9 @@ sub post_fetch_checkout {
12421253
command_noisy(qw/read-tree -m -u -v HEAD HEAD/);
12431254
print STDERR "Checked out HEAD:\n ",
12441255
$gs->full_url, " r", $gs->last_rev, "\n";
1245-
$gs->mkemptydirs($gs->last_rev);
1256+
if (auto_create_empty_directories($gs)) {
1257+
$gs->mkemptydirs($gs->last_rev);
1258+
}
12461259
}
12471260

12481261
sub complete_svn_url {

t/t9146-git-svn-empty-dirs.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ test_expect_success 'empty directories exist' '
2828
)
2929
'
3030

31+
test_expect_success 'option automkdirs set to false' '
32+
(
33+
git svn init "$svnrepo" cloned-no-mkdirs &&
34+
cd cloned-no-mkdirs &&
35+
git config svn-remote.svn.automkdirs false &&
36+
git svn fetch &&
37+
for i in a b c d d/e d/e/f "weird file name"
38+
do
39+
if test -d "$i"
40+
then
41+
echo >&2 "$i exists"
42+
exit 1
43+
fi
44+
done
45+
)
46+
'
47+
3148
test_expect_success 'more emptiness' '
3249
svn_cmd mkdir -m "bang bang" "$svnrepo"/"! !"
3350
'

0 commit comments

Comments
 (0)