git-svn: Add --localtime option to "fetch"

By default git-svn stores timestamps of fetched commits in
Subversion's UTC format.  Passing --localtime to fetch will convert
them to the timezone of the server on which git-svn is run.

This makes the timestamps of a resulting "git log" agree with what
"svn log" shows for the same repository.

Signed-off-by: Pete Harlan <pgit@pcharlan.com>
Acked-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
Pete Harlan 2009-01-17 20:10:14 -08:00 committed by Eric Wong
parent baf5fa8a7f
commit e82f0d73f0
3 changed files with 64 additions and 3 deletions

View File

@ -92,6 +92,17 @@ COMMANDS
.git/config file may be specified as an optional command-line .git/config file may be specified as an optional command-line
argument. argument.
--localtime;;
Store Git commit times in the local timezone instead of UTC. This
makes 'git-log' (even without --date=local) show the same times
that `svn log` would in the local timezone.
This doesn't interfere with interoperating with the Subversion
repository you cloned from, but if you wish for your local Git
repository to be able to interoperate with someone else's local Git
repository, either don't use this option or you should both use it in
the same local timezone.
'clone':: 'clone'::
Runs 'init' and 'fetch'. It will automatically create a Runs 'init' and 'fetch'. It will automatically create a
directory based on the basename of the URL passed to it; directory based on the basename of the URL passed to it;

View File

@ -1576,7 +1576,7 @@ _git_svn ()
--follow-parent --authors-file= --repack= --follow-parent --authors-file= --repack=
--no-metadata --use-svm-props --use-svnsync-props --no-metadata --use-svm-props --use-svnsync-props
--log-window-size= --no-checkout --quiet --log-window-size= --no-checkout --quiet
--repack-flags --user-log-author $remote_opts --repack-flags --user-log-author --localtime $remote_opts
" "
local init_opts=" local init_opts="
--template= --shared= --trunk= --tags= --template= --shared= --trunk= --tags=

View File

@ -84,6 +84,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
\$Git::SVN::_repack_flags, \$Git::SVN::_repack_flags,
'use-log-author' => \$Git::SVN::_use_log_author, 'use-log-author' => \$Git::SVN::_use_log_author,
'add-author-from' => \$Git::SVN::_add_author_from, 'add-author-from' => \$Git::SVN::_add_author_from,
'localtime' => \$Git::SVN::_localtime,
%remote_opts ); %remote_opts );
my ($_trunk, $_tags, $_branches, $_stdlayout); my ($_trunk, $_tags, $_branches, $_stdlayout);
@ -1364,7 +1365,7 @@ use constant rev_map_fmt => 'NH40';
use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
$_repack $_repack_flags $_use_svm_props $_head $_repack $_repack_flags $_use_svm_props $_head
$_use_svnsync_props $no_reuse_existing $_minimize_url $_use_svnsync_props $no_reuse_existing $_minimize_url
$_use_log_author $_add_author_from/; $_use_log_author $_add_author_from $_localtime/;
use Carp qw/croak/; use Carp qw/croak/;
use File::Path qw/mkpath/; use File::Path qw/mkpath/;
use File::Copy qw/copy/; use File::Copy qw/copy/;
@ -2526,12 +2527,61 @@ sub get_untracked {
\@out; \@out;
} }
# parse_svn_date(DATE)
# --------------------
# Given a date (in UTC) from Subversion, return a string in the format
# "<TZ Offset> <local date/time>" that Git will use.
#
# By default the parsed date will be in UTC; if $Git::SVN::_localtime
# is true we'll convert it to the local timezone instead.
sub parse_svn_date { sub parse_svn_date {
my $date = shift || return '+0000 1970-01-01 00:00:00'; my $date = shift || return '+0000 1970-01-01 00:00:00';
my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T
(\d\d)\:(\d\d)\:(\d\d).\d+Z$/x) or (\d\d)\:(\d\d)\:(\d\d).\d+Z$/x) or
croak "Unable to parse date: $date\n"; croak "Unable to parse date: $date\n";
"+0000 $Y-$m-$d $H:$M:$S"; my $parsed_date; # Set next.
if ($Git::SVN::_localtime) {
# Translate the Subversion datetime to an epoch time.
# Begin by switching ourselves to $date's timezone, UTC.
my $old_env_TZ = $ENV{TZ};
$ENV{TZ} = 'UTC';
my $epoch_in_UTC =
POSIX::strftime('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
# Determine our local timezone (including DST) at the
# time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
# value of TZ, if any, at the time we were run.
if (defined $Git::SVN::Log::TZ) {
$ENV{TZ} = $Git::SVN::Log::TZ;
} else {
delete $ENV{TZ};
}
my $our_TZ =
POSIX::strftime('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);
# This converts $epoch_in_UTC into our local timezone.
my ($sec, $min, $hour, $mday, $mon, $year,
$wday, $yday, $isdst) = localtime($epoch_in_UTC);
$parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
$our_TZ, $year + 1900, $mon + 1,
$mday, $hour, $min, $sec);
# Reset us to the timezone in effect when we entered
# this routine.
if (defined $old_env_TZ) {
$ENV{TZ} = $old_env_TZ;
} else {
delete $ENV{TZ};
}
} else {
$parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
}
return $parsed_date;
} }
sub check_author { sub check_author {