Prepare Git::SVN::Log for extraction from git-svn.
authorMichael G. Schwern <schwern@pobox.com>
Fri, 27 Jul 2012 00:26:00 +0000 (17:26 -0700)
committerEric Wong <normalperson@yhbt.net>
Fri, 27 Jul 2012 22:35:26 +0000 (22:35 +0000)
* Load Git command functions itself.

* Can't access the git-svn switch lexical any more, but its only used by
Git::SVN::Log so turn it into a Git::SVN::Log global.

* Load Git::SVN as needed. No need to load it always, its only used twice.

* Moved a state variable to the routine it's used for. (Drive by refactoring)

Signed-off-by: Eric Wong <normalperson@yhbt.net>
git-svn.perl
index 9269d80a6d9a300e27571ae8560f76849ba5f700..48906becb745f04d8fd73f19d0f30ce8b1d0e335 100755 (executable)
@@ -87,7 +87,7 @@ BEGIN
        foreach (qw/command command_oneline command_noisy command_output_pipe
                    command_input_pipe command_close_pipe
                    command_bidi_pipe command_close_bidi_pipe/) {
-               for my $package ( qw(Git::SVN::Migration Git::SVN::Log),
+               for my $package ( qw(Git::SVN::Migration),
                        __PACKAGE__) {
                        *{"${package}::$_"} = \&{"Git::$_"};
                }
@@ -106,7 +106,7 @@ BEGIN
        $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
        $_merge, $_strategy, $_preserve_merges, $_dry_run, $_local,
        $_prefix, $_no_checkout, $_url, $_verbose,
-       $_git_format, $_commit_url, $_tag, $_merge_info, $_interactive);
+       $_commit_url, $_tag, $_merge_info, $_interactive);
 
 # This is a refactoring artifact so Git::SVN can get at this git-svn switch.
 sub opt_prefix { return $_prefix || '' }
@@ -270,7 +270,7 @@ BEGIN
                    { 'url' => \$_url, } ],
        'blame' => [ \&Git::SVN::Log::cmd_blame,
                    "Show what revision and author last modified each line of a file",
-                   { 'git-format' => \$_git_format } ],
+                   { 'git-format' => \$Git::SVN::Log::_git_format } ],
        'reset' => [ \&cmd_reset,
                     "Undo fetches back to the specified SVN revision",
                     { 'revision|r=s' => \$_revision,
@@ -2043,11 +2043,14 @@ package Git::SVN::Log;
 use strict;
 use warnings;
 use Git::SVN::Utils qw(fatal);
+use Git qw(command command_oneline command_output_pipe command_close_pipe);
 use POSIX qw/strftime/;
 use constant commit_log_separator => ('-' x 72) . "\n";
 use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline
             %rusers $show_commit $incremental/;
-my $l_fmt;
+
+# Option set in git-svn
+our $_git_format;
 
 sub cmt_showable {
        my ($c) = @_;
@@ -2093,6 +2096,8 @@ sub git_svn_log_cmd {
        }
 
        my ($url, $rev, $uuid, $gs) = ::working_head_info($head);
+
+       require Git::SVN;
        $gs ||= Git::SVN->_new;
        my @cmd = (qw/log --abbrev-commit --pretty=raw --default/,
                   $gs->refname);
@@ -2154,6 +2159,7 @@ sub run_pager {
 
 sub format_svn_date {
        my $t = shift || time;
+       require Git::SVN;
        my $gmoff = Git::SVN::get_tz($t);
        return strftime("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
 }
@@ -2224,6 +2230,7 @@ sub process_commit {
        return 1;
 }
 
+my $l_fmt;
 sub show_commit {
        my $c = shift;
        if ($oneline) {