Skip to content

Commit 2da9ee0

Browse files
razehEric Wong
authored andcommitted
git svn: add gc command
Add a git svn gc command that gzips all unhandled.log files, and removes all index files under .git/svn. Signed-off-by: Robert Allan Zeh <[email protected]> Signed-off-by: Eric Wong <[email protected]>
1 parent 6517452 commit 2da9ee0

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

Documentation/git-svn.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ Any other arguments are passed directly to 'git log'
338338
Shows the Subversion externals. Use -r/--revision to specify a
339339
specific revision.
340340

341+
'gc'::
342+
Compress $GIT_DIR/svn/<refname>/unhandled.log files in .git/svn
343+
and remove $GIT_DIR/svn/<refname>index files in .git/svn.
344+
341345
'reset'::
342346
Undoes the effects of 'fetch' back to the specified revision.
343347
This allows you to re-'fetch' an SVN revision. Normally the

git-svn.perl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
if ($SVN::Core::VERSION lt '1.1.0') {
3232
fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
3333
}
34+
my $can_compress = eval { require Compress::Zlib; 1};
3435
push @Git::SVN::Ra::ISA, 'SVN::Ra';
3536
push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor';
3637
push @SVN::Git::Fetcher::ISA, 'SVN::Delta::Editor';
@@ -40,6 +41,7 @@
4041
use File::Basename qw/dirname basename/;
4142
use File::Path qw/mkpath/;
4243
use File::Spec;
44+
use File::Find;
4345
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
4446
use IPC::Open3;
4547
use Git;
@@ -217,6 +219,10 @@ BEGIN
217219
"Undo fetches back to the specified SVN revision",
218220
{ 'revision|r=s' => \$_revision,
219221
'parent|p' => \$_fetch_parent } ],
222+
'gc' => [ \&cmd_gc,
223+
"Compress unhandled.log files in .git/svn and remove " .
224+
"index files in .git/svn",
225+
{} ],
220226
);
221227

222228
my $cmd;
@@ -1107,6 +1113,14 @@ sub cmd_reset {
11071113
print "r$r = $c ($gs->{ref_id})\n";
11081114
}
11091115

1116+
sub cmd_gc {
1117+
if (!$can_compress) {
1118+
warn "Compress::Zlib could not be found; unhandled.log " .
1119+
"files will not be compressed.\n";
1120+
}
1121+
find({ wanted => \&gc_directory, no_chdir => 1}, "$ENV{GIT_DIR}/svn");
1122+
}
1123+
11101124
########################### utility functions #########################
11111125

11121126
sub rebase_cmd {
@@ -1527,6 +1541,25 @@ sub md5sum {
15271541
return $md5->hexdigest();
15281542
}
15291543

1544+
sub gc_directory {
1545+
if ($can_compress && -f $_ && basename($_) eq "unhandled.log") {
1546+
my $out_filename = $_ . ".gz";
1547+
open my $in_fh, "<", $_ or die "Unable to open $_: $!\n";
1548+
binmode $in_fh;
1549+
my $gz = Compress::Zlib::gzopen($out_filename, "ab") or
1550+
die "Unable to open $out_filename: $!\n";
1551+
1552+
my $res;
1553+
while ($res = sysread($in_fh, my $str, 1024)) {
1554+
$gz->gzwrite($str) or
1555+
die "Unable to write: ".$gz->gzerror()."!\n";
1556+
}
1557+
unlink $_ or die "unlink $File::Find::name: $!\n";
1558+
} elsif (-f $_ && basename($_) eq "index") {
1559+
unlink $_ or die "unlink $_: $!\n";
1560+
}
1561+
}
1562+
15301563
package Git::SVN;
15311564
use strict;
15321565
use warnings;

t/t9143-git-svn-gc.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Robert Allan Zeh
4+
5+
test_description='git svn gc basic tests'
6+
7+
. ./lib-git-svn.sh
8+
9+
test_expect_success 'setup directories and test repo' '
10+
mkdir import &&
11+
mkdir tmp &&
12+
echo "Sample text for Subversion repository." > import/test.txt &&
13+
svn_cmd import -m "import for git svn" import "$svnrepo" > /dev/null
14+
'
15+
16+
test_expect_success 'checkout working copy from svn' \
17+
'svn_cmd co "$svnrepo" test_wc'
18+
19+
test_expect_success 'set some properties to create an unhandled.log file' '
20+
(
21+
cd test_wc &&
22+
svn_cmd propset foo bar test.txt &&
23+
svn_cmd commit -m "property set"
24+
)'
25+
26+
test_expect_success 'Setup repo' 'git svn init "$svnrepo"'
27+
28+
test_expect_success 'Fetch repo' 'git svn fetch'
29+
30+
test_expect_success 'make backup copy of unhandled.log' '
31+
cp .git/svn/git-svn/unhandled.log tmp
32+
'
33+
34+
test_expect_success 'git svn gc runs' 'git svn gc'
35+
36+
test_expect_success 'git svn gc produces a valid gzip file' '
37+
gunzip .git/svn/git-svn/unhandled.log.gz
38+
'
39+
40+
test_expect_success 'git svn gc does not change unhandled.log files' '
41+
test_cmp .git/svn/git-svn/unhandled.log tmp/unhandled.log
42+
'
43+
44+
test_done

0 commit comments

Comments
 (0)