All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Barry Wardell <barry.wardell@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH v3 0/2] Make git-svn work with gitdir links
Date: Thu, 24 Jan 2013 10:14:17 +0000	[thread overview]
Message-ID: <20130124101417.GA22138@dcvr.yhbt.net> (raw)
In-Reply-To: <7vehhbdu8y.fsf@alter.siamese.dyndns.org>

Junio C Hamano <gitster@pobox.com> wrote:
> Eric Wong <normalperson@yhbt.net> writes:
> 
> > diff --git a/git-svn.perl b/git-svn.perl
> > index c232798..e5bd292 100755
> > --- a/git-svn.perl
> > +++ b/git-svn.perl
> > @@ -332,11 +332,13 @@ if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
> >  		$ENV{GIT_DIR} = command_oneline([qw/rev-parse --git-dir/]);
> >  	} "Unable to find .git directory\n";
> >  	my $cdup = undef;
> > +	my $git_dir = delete $ENV{GIT_DIR};
> >  	git_cmd_try {
> >  		$cdup = command_oneline(qw/rev-parse --show-cdup/);
> >  		chomp $cdup if ($cdup);
> >  		$cdup = "." unless ($cdup && length $cdup);
> > -	} "Already at toplevel, but $ENV{GIT_DIR} not found\n";
> > +	} "Already at toplevel, but $git_dir not found\n";
> > +	$ENV{GIT_DIR} = $git_dir;
> >  	chdir $cdup or die "Unable to chdir up to '$cdup'\n";
> >  	$_repository = Git->repository(Repository => $ENV{GIT_DIR});
> >  }
> 
> This does not look quite right, though.
> 
> Can't the user have his own $GIT_DIR when this command is invoked?
> The first command_oneline() runs rev-parse with that environment and
> get the user specified value of GIT_DIR in $ENV{GIT_DIR}, but by
> doing a "delete" before running --show-cdup, you are not honoring
> that GIT_DIR (and GIT_WORK_TREE if exists) the user gave you.  You
> already used that GIT_DIR when you asked rev-parse --git-dir to find
> what the GIT_DIR value should be, so you would be operating with
> values of $git_dir and $cdup that you discovered in an inconsistent
> way, no?
> 
> Shouldn't it be more like this instead?
> 
> 	my ($git_dir, $cdup) = undef;
>         try {
> 		$git_dir = command_oneline(qw(rev-parse --git-dir));
> 	} "Unable to ...";
>         try {
> 		$cdup = command_oneline(qw(rev-parse --show-cdup));
> 		... tweak $cdup ...
> 	} "Unable to ...";
> 	if (defined $git_dir) { $ENV{GIT_DIR} = $git_dir; }
> 	chdir $cdup;

Thanks, I'll squash the following and push a new branch.  I don't
believe the (defined $git_dir) check is necessary since we already
checked for errors with git_cmd_try.

diff --git a/git-svn.perl b/git-svn.perl
index e5bd292..b46795f 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -324,19 +324,18 @@ for (my $i = 0; $i < @ARGV; $i++) {
 	}
 };
 
 # make sure we're always running at the top-level working directory
 if ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
 	$ENV{GIT_DIR} ||= ".git";
 } else {
+	my ($git_dir, $cdup);
 	git_cmd_try {
-		$ENV{GIT_DIR} = command_oneline([qw/rev-parse --git-dir/]);
+		$git_dir = command_oneline([qw/rev-parse --git-dir/]);
 	} "Unable to find .git directory\n";
-	my $cdup = undef;
-	my $git_dir = delete $ENV{GIT_DIR};
 	git_cmd_try {
 		$cdup = command_oneline(qw/rev-parse --show-cdup/);
 		chomp $cdup if ($cdup);
 		$cdup = "." unless ($cdup && length $cdup);
 	} "Already at toplevel, but $git_dir not found\n";
 	$ENV{GIT_DIR} = $git_dir;
 	chdir $cdup or die "Unable to chdir up to '$cdup'\n";

-- 
Eric Wong

      reply	other threads:[~2013-01-24 10:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-03 19:53 [PATCH v2] git-svn: Simplify calculation of GIT_DIR Barry Wardell
2012-03-08  0:51 ` 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 [this message]

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=20130124101417.GA22138@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=barry.wardell@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.