git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael G. Schwern" <schwern@pobox.com>
To: git@vger.kernel.org, gitster@pobox.com
Cc: robbat2@gentoo.org, bwalton@artsci.utoronto.ca,
	normalperson@yhbt.net, jrnieder@gmail.com,
	"Michael G. Schwern" <schwern@pobox.com>
Subject: [PATCH 2/4] Prepare Git::SVN for extraction into its own file.
Date: Thu, 26 Jul 2012 16:22:23 -0700	[thread overview]
Message-ID: <1343344945-3717-3-git-send-email-schwern@pobox.com> (raw)
In-Reply-To: <1343344945-3717-1-git-send-email-schwern@pobox.com>

From: "Michael G. Schwern" <schwern@pobox.com>

This means it should be able to load without git-svn being loaded.

* Load Git.pm on its own and all the needed command functions.

* It needs to grab at a git-svn lexical $_prefix representing the --prefix
  option.  Provide opt_prefix() for that.  This is a refactoring artifact.
  The prefix should really be passed into Git::SVN->new.

* Unqualify unnecessarily fully qualified globals like
  $Git::SVN::default_repo_id.

* Lexically isolate the class just to make sure nothing is leaking out.
---
 git-svn.perl | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 79fe4a4..9cdf6fc 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -89,7 +89,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 Git::SVN),
+		for my $package ( qw(Git::SVN::Migration Git::SVN::Log),
 			__PACKAGE__) {
 			*{"${package}::$_"} = \&{"Git::$_"};
 		}
@@ -109,6 +109,10 @@ my ($_stdin, $_help, $_edit,
 	$_merge, $_strategy, $_preserve_merges, $_dry_run, $_local,
 	$_prefix, $_no_checkout, $_url, $_verbose,
 	$_git_format, $_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 || '' }
+
 $Git::SVN::_follow_parent = 1;
 $Git::SVN::Fetcher::_placeholder_filename = ".gitignore";
 $_q ||= 0;
@@ -2038,6 +2042,7 @@ sub gc_directory {
 	}
 }
 
+{
 package Git::SVN;
 use strict;
 use warnings;
@@ -2056,6 +2061,13 @@ use Memoize;  # core since 5.8.0, Jul 2002
 use Memoize::Storable;
 use POSIX qw(:signal_h);
 
+use Git qw(
+    command
+    command_oneline
+    command_noisy
+    command_output_pipe
+    command_close_pipe
+);
 use Git::SVN::Utils qw(fatal can_compress);
 
 my $can_use_yaml;
@@ -4280,12 +4292,13 @@ sub find_rev_after {
 sub _new {
 	my ($class, $repo_id, $ref_id, $path) = @_;
 	unless (defined $repo_id && length $repo_id) {
-		$repo_id = $Git::SVN::default_repo_id;
+		$repo_id = $default_repo_id;
 	}
 	unless (defined $ref_id && length $ref_id) {
-		$_prefix = '' unless defined($_prefix);
+		# Access the prefix option from the git-svn main program if it's loaded.
+		my $prefix = defined &::opt_prefix ? ::opt_prefix() : "";
 		$_[2] = $ref_id =
-		             "refs/remotes/$_prefix$Git::SVN::default_ref_id";
+		             "refs/remotes/$prefix$default_ref_id";
 	}
 	$_[1] = $repo_id;
 	my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
@@ -4347,6 +4360,7 @@ sub uri_decode {
 sub remove_username {
 	$_[0] =~ s{^([^:]*://)[^@]+@}{$1};
 }
+}
 
 package Git::SVN::Log;
 use strict;
-- 
1.7.11.1

  parent reply	other threads:[~2012-07-26 23:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 23:22 Extract Git::SVN from git-svn, take 2 Michael G. Schwern
2012-07-26 23:22 ` [PATCH 1/4] Extract some utilities from git-svn to allow extracting Git::SVN Michael G. Schwern
2012-07-27  5:18   ` Junio C Hamano
2012-07-27  8:19     ` Michael G Schwern
2012-07-27 11:34     ` Eric Wong
2012-07-26 23:22 ` Michael G. Schwern [this message]
2012-07-27  5:18   ` [PATCH 2/4] Prepare Git::SVN for extraction into its own file Junio C Hamano
2012-07-27  5:23     ` Junio C Hamano
2012-07-27  8:16     ` Michael G Schwern
2012-07-27 11:53       ` Eric Wong
2012-07-26 23:22 ` [PATCH 4/4] Move initialization of Git::SVN variables into Git::SVN Michael G. Schwern
2012-07-27  5:18   ` Junio C Hamano
2012-07-27  5:38     ` Jonathan Nieder
2012-07-27  6:07       ` Junio C Hamano
2012-07-27  6:46         ` Junio C Hamano
2012-07-27  7:09           ` Junio C Hamano
2012-07-27 20:07             ` Eric Wong
2012-07-27 20:56               ` Michael G Schwern
2012-07-27 20:59                 ` Eric Wong
2012-07-27 21:31                 ` Junio C Hamano
2012-07-27 21:49               ` Junio C Hamano
2012-07-27 22:07                 ` Eric Wong
2012-07-27 22:19                   ` Eric Wong
2012-07-27 22:37                     ` Junio C Hamano
2012-07-27 22:45                       ` Eric Wong
2012-07-27 22:59                         ` Junio C Hamano
2012-07-27 23:01                           ` Eric Wong
2012-07-27 22:52                     ` Junio C Hamano
2012-07-27 11:59         ` Eric Wong
2012-07-27  8:41     ` Michael G Schwern
  -- strict thread matches above, loose matches on Subject: below --
2012-07-25  6:01 Move Git::SVN into its own .pm file Michael G. Schwern
2012-07-25  6:01 ` [PATCH 2/4] Prepare Git::SVN for extraction into its own file Michael G. Schwern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343344945-3717-3-git-send-email-schwern@pobox.com \
    --to=schwern@pobox.com \
    --cc=bwalton@artsci.utoronto.ca \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=normalperson@yhbt.net \
    --cc=robbat2@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).