git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Barry Wardell <barry.wardell@gmail.com>
To: git@vger.kernel.org
Cc: Barry Wardell <barry.wardell@gmail.com>
Subject: [PATCH v2] git-svn: Simplify calculation of GIT_DIR
Date: Sat,  3 Mar 2012 19:53:17 +0000	[thread overview]
Message-ID: <1330804397-43062-1-git-send-email-barry.wardell@gmail.com> (raw)

Since git-rev-parse already checks for the $GIT_DIR environment
variable and that it returns an actual git repository, there is no
need to repeat the checks again here.

This also fixes a problem where git-svn did not work in cases where
.git was a file with a gitdir: link.
---
 git-svn.perl |   33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 4334b95..bbfd351 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -15,8 +15,6 @@ my $cmd_dir_prefix = eval {
 	command_oneline([qw/rev-parse --show-prefix/], STDERR => 0)
 } || '';
 
-my $git_dir_user_set = 1 if defined $ENV{GIT_DIR};
-$ENV{GIT_DIR} ||= '.git';
 $Git::SVN::default_repo_id = 'svn';
 $Git::SVN::default_ref_id = $ENV{GIT_SVN_ID} || 'git-svn';
 $Git::SVN::Ra::_log_window_size = 100;
@@ -292,26 +290,17 @@ for (my $i = 0; $i < @ARGV; $i++) {
 
 # make sure we're always running at the top-level working directory
 unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
-	unless (-d $ENV{GIT_DIR}) {
-		if ($git_dir_user_set) {
-			die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
-			    "but it is not a directory\n";
-		}
-		my $git_dir = delete $ENV{GIT_DIR};
-		my $cdup = undef;
-		git_cmd_try {
-			$cdup = command_oneline(qw/rev-parse --show-cdup/);
-			$git_dir = '.' unless ($cdup);
-			chomp $cdup if ($cdup);
-			$cdup = "." unless ($cdup && length $cdup);
-		} "Already at toplevel, but $git_dir not found\n";
-		chdir $cdup or die "Unable to chdir up to '$cdup'\n";
-		unless (-d $git_dir) {
-			die "$git_dir still not found after going to ",
-			    "'$cdup'\n";
-		}
-		$ENV{GIT_DIR} = $git_dir;
-	}
+	my $toplevel = undef;
+
+	git_cmd_try {
+		$toplevel = command_oneline([qw/rev-parse --show-toplevel/]);
+	} "Unable to find toplevel directory\n";
+
+	git_cmd_try {
+		$ENV{GIT_DIR} = command_oneline([qw/rev-parse --git-dir/]);
+	} "Unable to find .git directory\n";
+
+	chdir $toplevel or die "Unable to chdir to '$toplevel'\n";
 	$_repository = Git->repository(Repository => $ENV{GIT_DIR});
 }
 
-- 
1.7.9.2

             reply	other threads:[~2012-03-03 19:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-03 19:53 Barry Wardell [this message]
2012-03-08  0:51 ` [PATCH v2] git-svn: Simplify calculation of GIT_DIR Eric Wong
2013-01-21  1:22   ` [PATCH v3 0/2] Make git-svn work with gitdir links Barry Wardell
2013-01-21  1:22     ` [PATCH 1/2] git-svn: Add test for git-svn repositories with a gitdir link Barry Wardell
2013-01-21  1:22     ` [PATCH 2/2] git-svn: Simplify calculation of GIT_DIR Barry Wardell
2013-01-21  1:50     ` [PATCH v3 0/2] Make git-svn work with gitdir links Junio C Hamano
2013-01-21 14:19       ` Joachim Schmitz
2013-01-21 21:45         ` Philip Oakley
2013-01-21 22:08           ` Junio C Hamano
2013-01-23  2:32     ` Eric Wong
2013-01-23  2:53       ` Junio C Hamano
2013-01-23 12:08       ` Barry Wardell
     [not found]       ` <CAHrK+Z-uXAEgd_HuisbioO8=D7DEdmceeUEz3A1Jr_rtm7a3WA@mail.gmail.com>
2013-01-24  1:27         ` Eric Wong
2013-01-24  5:29       ` Junio C Hamano
2013-01-24 10:14         ` Eric Wong

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=1330804397-43062-1-git-send-email-barry.wardell@gmail.com \
    --to=barry.wardell@gmail.com \
    --cc=git@vger.kernel.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).