git-svn: extra safety for noMetadata and useSvmProps users
Make sure we flush our userspace buffers and and fsync(2) .rev_db information to disk if we use these options because we really don't want to lose this information. Also, disallow --use-svm-props and --no-metadata from the command-line because history will be inconsistent if they're only used occasionally. If a user wants to use these options, they must be set in the config so they're always on. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 11, 2007 at 15:21 UTC
97ae091169b233ecd80eb5ef2da80145f8c724f7
2 files changed
+43
-12
Documentation/git-svn.txt
+21
-5
@@ -316,17 +316,33 @@ for more information on using GIT_SVN_ID.
316
317
config key: svn.followparent
318
319
---no-metadata::
319
+svn.noMetadata:
320
+svn-remote.<name>.noMetadata:
321
This gets rid of the git-svn-id: lines at the end of every commit.
322
323
If you lose your .git/svn/git-svn/.rev_db file, git-svn will not
324
be able to rebuild it and you won't be able to fetch again,
325
either. This is fine for one-shot imports.
326
326
- The 'git-svn log' command will not work on repositories using this,
327
- either.
328
-
329
-config key: svn.nometadata
327
+ The 'git-svn log' command will not work on repositories using
328
+ this, either. Using this conflicts with the 'useSvmProps'
329
+ option for (hopefully) obvious reasons.
330
+
331
+svn.useSvmProps:
332
+svn-remote.<name>.useSvmProps:
333
+ This allows git-svn to re-map repository URLs and UUIDs from
334
+ mirrors created using SVN::Mirror (or svk) for metadata.
335
+
336
+ If an SVN revision has a property, "svm:headrev", it is likely
337
+ that the revision was created by SVN::Mirror (also used by SVK).
338
+ The property contains a repository UUID and a revision. We want
339
+ to make it look like we are mirroring the original URL, so
340
+ introduce a helper function that returns the original identity
341
+ URL and UUID, and use it when generating metadata in commit
342
+ messages.
343
+
344
+ Using this conflicts with the 'noMetadata' option for
345
+ (hopefully) obvious reasons.
346
347
--
348
git-svn.perl
+22
-7
@@ -63,8 +63,8 @@ my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username,
63
my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
64
'authors-file|A=s' => \$_authors,
65
'repack:i' => \$Git::SVN::_repack,
66
- 'no-metadata' => \$Git::SVN::_no_metadata,
67
- 'use-svm-props|svm-props' => \$Git::SVN::_use_svm_props,
66
+ 'noMetadata' => \$Git::SVN::_no_metadata,
67
+ 'useSvmProps' => \$Git::SVN::_use_svm_props,
68
'quiet|q' => \$_q,
69
'repack-flags|repack-args|repack-opts=s' =>
70
\$Git::SVN::_repack_flags,
@@ -606,9 +606,14 @@ sub load_authors {
606
sub read_repo_config {
607
return unless -d $ENV{GIT_DIR};
608
my $opts = shift;
609
+ my @config_only;
610
foreach my $o (keys %$opts) {
611
+ # if we have mixedCase and a long option-only, then
612
+ # it's a config-only variable that we don't need for
613
+ # the command-line.
614
+ push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
615
my $v = $opts->{$o};
611
- my ($key) = ($o =~ /^([a-z\-]+)/);
616
+ my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
617
$key =~ s/-//g;
618
my $arg = 'git-config';
619
$arg .= ' --int' if ($o =~ /[:=]i$/);
@@ -623,6 +628,7 @@ sub read_repo_config {
628
}
629
}
630
}
631
+ delete @$opts{@config_only} if @config_only;
632
}
633
634
sub extract_metadata {
@@ -983,8 +989,8 @@ sub ra {
989
my $ra = Git::SVN::Ra->new($self->{url});
990
if ($self->use_svm_props && !$self->{svm}) {
991
if ($self->no_metadata) {
986
- die "Can't have both --no-metadata and ",
987
- "--use-svm-props options set!\n";
992
+ die "Can't have both 'noMetadata' and ",
993
+ "'useSvmProps' options set!\n";
994
}
995
$ra = $self->set_svm_vars($ra);
996
$self->{-want_revprops} = 1;
@@ -1566,7 +1572,7 @@ sub rebuild {
1572
# to a revision: (41 * rev) is the byte offset.
1573
# A record of 40 0s denotes an empty revision.
1574
# And yes, it's still pretty fast (faster than Tie::File).
1569
-# These files are disposable unless --no-metadata is set
1575
+# These files are disposable unless noMetadata or useSvmProps is set
1576
1577
sub rev_db_set {
1578
my ($self, $rev, $commit, $update_ref) = @_;
@@ -1578,7 +1584,12 @@ sub rev_db_set {
1584
$SIG{USR1} = $SIG{USR2} = sub { $sig = $_[0] };
1585
}
1586
$LOCKFILES{$db_lock} = 1;
1581
- if ($self->no_metadata) {
1587
+ my $sync;
1588
+
1589
+ # both of these options make our .rev_db file very, very important
1590
+ # and we can't afford to lose it because rebuild() won't work
1591
+ if ($self->use_svm_props || $self->no_metadata) {
1592
+ $sync = 1;
1593
copy($db, $db_lock) or die "rev_db_set(@_): ",
1594
"Failed to copy: ",
1595
"$db => $db_lock ($!)\n";
@@ -1599,6 +1610,10 @@ sub rev_db_set {
1610
}
1611
seek $fh, $offset, 0 or croak $!;
1612
print $fh $commit,"\n" or croak $!;
1613
+ if ($sync) {
1614
+ $fh->flush or die "Couldn't flush $db_lock: $!\n";
1615
+ $fh->sync or die "Couldn't sync $db_lock: $!\n";
1616
+ }
1617
close $fh or croak $!;
1618
if ($update_ref) {
1619
command_noisy('update-ref', '-m', "r$rev",