* [PATCH] git-svn: Simplify calculation of GIT_DIR
@ 2012-03-03 18:08 Barry Wardell
2012-03-03 18:27 ` Carlos Martín Nieto
0 siblings, 1 reply; 3+ messages in thread
From: Barry Wardell @ 2012-03-03 18:08 UTC (permalink / raw)
To: git; +Cc: Barry Wardell
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 | 25 ++-----------------------
1 file changed, 2 insertions(+), 23 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 4334b95..cf2cef8 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;
@@ -290,28 +288,9 @@ for (my $i = 0; $i < @ARGV; $i++) {
}
};
-# make sure we're always running at the top-level working directory
+# Access an existing repository
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;
- }
+ $ENV{GIT_DIR} = command_oneline([qw/rev-parse --git-dir/]);
$_repository = Git->repository(Repository => $ENV{GIT_DIR});
}
--
1.7.9.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] git-svn: Simplify calculation of GIT_DIR
2012-03-03 18:08 [PATCH] git-svn: Simplify calculation of GIT_DIR Barry Wardell
@ 2012-03-03 18:27 ` Carlos Martín Nieto
2012-03-03 19:45 ` Barry Wardell
0 siblings, 1 reply; 3+ messages in thread
From: Carlos Martín Nieto @ 2012-03-03 18:27 UTC (permalink / raw)
To: Barry Wardell; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 2392 bytes --]
On Sat, 2012-03-03 at 18:08 +0000, Barry Wardell wrote:
> 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 | 25 ++-----------------------
> 1 file changed, 2 insertions(+), 23 deletions(-)
>
> diff --git a/git-svn.perl b/git-svn.perl
> index 4334b95..cf2cef8 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;
> @@ -290,28 +288,9 @@ for (my $i = 0; $i < @ARGV; $i++) {
> }
> };
>
> -# make sure we're always running at the top-level working directory
> +# Access an existing repository
Is there a reason making sure we're at the top-level dir isn't necessary
anymore?
> 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";
Here you delete a chdir to the top-level directory, just as you deleted
the comment above, yet in the commit message you don't explain why this
isn't necessary anymore. Doesn't the rest of the code still assume that
it's running at the top-level dir?
> - unless (-d $git_dir) {
> - die "$git_dir still not found after going to ",
> - "'$cdup'\n";
> - }
> - $ENV{GIT_DIR} = $git_dir;
> - }
> + $ENV{GIT_DIR} = command_oneline([qw/rev-parse --git-dir/]);
> $_repository = Git->repository(Repository => $ENV{GIT_DIR});
> }
>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] git-svn: Simplify calculation of GIT_DIR
2012-03-03 18:27 ` Carlos Martín Nieto
@ 2012-03-03 19:45 ` Barry Wardell
0 siblings, 0 replies; 3+ messages in thread
From: Barry Wardell @ 2012-03-03 19:45 UTC (permalink / raw)
To: git
On Sat, Mar 3, 2012 at 6:27 PM, Carlos Martín Nieto <cmn@elego.de> wrote:
>
> > -# make sure we're always running at the top-level working directory
> > +# Access an existing repository
>
> Is there a reason making sure we're at the top-level dir isn't necessary
> anymore?
No, in fact it is still necessary.
> > 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";
>
> Here you delete a chdir to the top-level directory, just as you deleted
> the comment above, yet in the commit message you don't explain why this
> isn't necessary anymore. Doesn't the rest of the code still assume that
> it's running at the top-level dir?
Yes, you're right. I will restore the chdir and submit a new patch.
Barry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-03 19:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-03 18:08 [PATCH] git-svn: Simplify calculation of GIT_DIR Barry Wardell
2012-03-03 18:27 ` Carlos Martín Nieto
2012-03-03 19:45 ` Barry Wardell
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).