@matheusbsbs / matheus-bagliano / commits / e82f0d73f0
Fork 0

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>

Pete Harlan committed Jan 17, 2009 at 20:10 UTC e82f0d73f02e89a95d9477911774d314f70f1063
3 files changed +64 -3
Documentation/git-svn.txt
+11
@@ -92,6 +92,17 @@ COMMANDS
92 .git/config file may be specified as an optional command-line
93 argument.
94
95 +--localtime;;
96 + Store Git commit times in the local timezone instead of UTC. This
97 + makes 'git-log' (even without --date=local) show the same times
98 + that `svn log` would in the local timezone.
99 +
100 +This doesn't interfere with interoperating with the Subversion
101 +repository you cloned from, but if you wish for your local Git
102 +repository to be able to interoperate with someone else's local Git
103 +repository, either don't use this option or you should both use it in
104 +the same local timezone.
105 +
106 'clone'::
107 Runs 'init' and 'fetch'. It will automatically create a
108 directory based on the basename of the URL passed to it;
contrib/completion/git-completion.bash
+1 -1
@@ -1576,7 +1576,7 @@ _git_svn ()
1576 --follow-parent --authors-file= --repack=
1577 --no-metadata --use-svm-props --use-svnsync-props
1578 --log-window-size= --no-checkout --quiet
1579 - --repack-flags --user-log-author $remote_opts
1579 + --repack-flags --user-log-author --localtime $remote_opts
1580 "
1581 local init_opts="
1582 --template= --shared= --trunk= --tags=
git-svn.perl
+52 -2
@@ -84,6 +84,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent,
84 \$Git::SVN::_repack_flags,
85 'use-log-author' => \$Git::SVN::_use_log_author,
86 'add-author-from' => \$Git::SVN::_add_author_from,
87 + 'localtime' => \$Git::SVN::_localtime,
88 %remote_opts );
89
90 my ($_trunk, $_tags, $_branches, $_stdlayout);
@@ -1364,7 +1365,7 @@ use constant rev_map_fmt => 'NH40';
1365 use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
1366 $_repack $_repack_flags $_use_svm_props $_head
1367 $_use_svnsync_props $no_reuse_existing $_minimize_url
1367 - $_use_log_author $_add_author_from/;
1368 + $_use_log_author $_add_author_from $_localtime/;
1369 use Carp qw/croak/;
1370 use File::Path qw/mkpath/;
1371 use File::Copy qw/copy/;
@@ -2526,12 +2527,61 @@ sub get_untracked {
2527 \@out;
2528 }
2529
2530 +# parse_svn_date(DATE)
2531 +# --------------------
2532 +# Given a date (in UTC) from Subversion, return a string in the format
2533 +# "<TZ Offset> <local date/time>" that Git will use.
2534 +#
2535 +# By default the parsed date will be in UTC; if $Git::SVN::_localtime
2536 +# is true we'll convert it to the local timezone instead.
2537 sub parse_svn_date {
2538 my $date = shift || return '+0000 1970-01-01 00:00:00';
2539 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T
2540 (\d\d)\:(\d\d)\:(\d\d).\d+Z$/x) or
2541 croak "Unable to parse date: $date\n";
2534 - "+0000 $Y-$m-$d $H:$M:$S";
2542 + my $parsed_date; # Set next.
2543 +
2544 + if ($Git::SVN::_localtime) {
2545 + # Translate the Subversion datetime to an epoch time.
2546 + # Begin by switching ourselves to $date's timezone, UTC.
2547 + my $old_env_TZ = $ENV{TZ};
2548 + $ENV{TZ} = 'UTC';
2549 +
2550 + my $epoch_in_UTC =
2551 + POSIX::strftime('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
2552 +
2553 + # Determine our local timezone (including DST) at the
2554 + # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
2555 + # value of TZ, if any, at the time we were run.
2556 + if (defined $Git::SVN::Log::TZ) {
2557 + $ENV{TZ} = $Git::SVN::Log::TZ;
2558 + } else {
2559 + delete $ENV{TZ};
2560 + }
2561 +
2562 + my $our_TZ =
2563 + POSIX::strftime('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);
2564 +
2565 + # This converts $epoch_in_UTC into our local timezone.
2566 + my ($sec, $min, $hour, $mday, $mon, $year,
2567 + $wday, $yday, $isdst) = localtime($epoch_in_UTC);
2568 +
2569 + $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
2570 + $our_TZ, $year + 1900, $mon + 1,
2571 + $mday, $hour, $min, $sec);
2572 +
2573 + # Reset us to the timezone in effect when we entered
2574 + # this routine.
2575 + if (defined $old_env_TZ) {
2576 + $ENV{TZ} = $old_env_TZ;
2577 + } else {
2578 + delete $ENV{TZ};
2579 + }
2580 + } else {
2581 + $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
2582 + }
2583 +
2584 + return $parsed_date;
2585 }
2586
2587 sub check_author {