[git/perl] unusual syntax?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[git/perl] unusual syntax?

Tay Ray Chuan
Hi,

i noticed that this doesn't work for me (Perl 5.10):

sub _close_hash_and_insert_object {
        my ($self) = @_;

        return unless defined($self->{hash_object_pid});

        my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);

        command_close_bidi_pipe($self->{@vars});
        delete $self->{@vars};
}


$self->{@vars} evaluates to undef. i can't find any mention of using
arrays to dereference objects in the manual and elsewhere; is this a
mistake?

--
Cheers,
Ray Chuan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH] Fix hash slice syntax error

Abhijit Menon-Sen-4

Signed-off-by: Abhijit Menon-Sen <[hidden email]>
---

At 2008-08-04 12:49:27 +0800, [hidden email] wrote:
>
> $self->{@vars} evaluates to undef. i can't find any mention of using
> arrays to dereference objects in the manual and elsewhere; is this a
> mistake?

Yes, @vars would be interpreted in scalar context, which certainly isn't
the intended effect.

-- ams

 perl/Git.pm |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 087d3d0..2ef437f 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -839,8 +839,8 @@ sub _close_hash_and_insert_object {
 
  my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
 
- command_close_bidi_pipe($self->{@vars});
- delete $self->{@vars};
+ command_close_bidi_pipe(@$self{@vars});
+ delete @$self{@vars};
 }
 
 =item cat_blob ( SHA1, FILEHANDLE )
@@ -928,8 +928,8 @@ sub _close_cat_blob {
 
  my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx);
 
- command_close_bidi_pipe($self->{@vars});
- delete $self->{@vars};
+ command_close_bidi_pipe(@$self{@vars});
+ delete @$self{@vars};
 }
 
 =back
--
1.6.0.rc0.43.g2aa74
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH] Git.pm: Fix internal git_command_bidi_pipe() users

Petr Baudis
In reply to this post by Tay Ray Chuan
The hash_and_insert_object() and cat_blob() helpers were using
an incorrect slice-from-ref Perl syntax. This patch fixes that up
in the _close_*() helpers and make the _open_*() helpers use the
same syntax for consistnecy.

Signed-off-by: Petr Baudis <[hidden email]>
---

  Wow, the command_bidi_pipe API really is dirty. Of course, it is
my fault as anyone's since I didn't get around to review the patches
introducing it.

 perl/Git.pm |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 087d3d0..0624428 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -827,8 +827,7 @@ sub _open_hash_and_insert_object_if_needed {
 
  return if defined($self->{hash_object_pid});
 
- ($self->{hash_object_pid}, $self->{hash_object_in},
- $self->{hash_object_out}, $self->{hash_object_ctx}) =
+ @$self{map { "hash_object_$_" } qw(pid in out ctx)} =
  command_bidi_pipe(qw(hash-object -w --stdin-paths));
 }
 
@@ -837,9 +836,8 @@ sub _close_hash_and_insert_object {
 
  return unless defined($self->{hash_object_pid});
 
- my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
-
- command_close_bidi_pipe($self->{@vars});
+ my @vars = map { "hash_object_$_" } qw(pid in out ctx);
+ command_close_bidi_pipe(@$self{@vars});
  delete $self->{@vars};
 }
 
@@ -916,8 +914,7 @@ sub _open_cat_blob_if_needed {
 
  return if defined($self->{cat_blob_pid});
 
- ($self->{cat_blob_pid}, $self->{cat_blob_in},
- $self->{cat_blob_out}, $self->{cat_blob_ctx}) =
+ @$self{map { "cat_blob_$_" } qw(pid in out ctx)} =
  command_bidi_pipe(qw(cat-file --batch));
 }
 
@@ -926,9 +923,8 @@ sub _close_cat_blob {
 
  return unless defined($self->{cat_blob_pid});
 
- my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx);
-
- command_close_bidi_pipe($self->{@vars});
+ my @vars = map { "cat_blob_$_" } qw(pid in out ctx);
+ command_close_bidi_pipe(@$self{@vars});
  delete $self->{@vars};
 }
 

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users

Junio C Hamano
Petr Baudis <[hidden email]> writes:

> The hash_and_insert_object() and cat_blob() helpers were using
> an incorrect slice-from-ref Perl syntax. This patch fixes that up
> in the _close_*() helpers and make the _open_*() helpers use the
> same syntax for consistnecy.
>
> Signed-off-by: Petr Baudis <[hidden email]>
> ---
>
>   Wow, the command_bidi_pipe API really is dirty. Of course, it is
> my fault as anyone's since I didn't get around to review the patches
> introducing it.

Sorry, delete is still broken with your patch, isn't it?

The earlier patch from Abhijit Menon-Sen does this properly for
close_hash_and_insert and close_cat_blob, which I've queued already.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users

Petr Baudis
On Mon, Aug 04, 2008 at 01:05:56AM -0700, Junio C Hamano wrote:

> Petr Baudis <[hidden email]> writes:
>
> > The hash_and_insert_object() and cat_blob() helpers were using
> > an incorrect slice-from-ref Perl syntax. This patch fixes that up
> > in the _close_*() helpers and make the _open_*() helpers use the
> > same syntax for consistnecy.
> >
> > Signed-off-by: Petr Baudis <[hidden email]>
> > ---
> >
> >   Wow, the command_bidi_pipe API really is dirty. Of course, it is
> > my fault as anyone's since I didn't get around to review the patches
> > introducing it.
>
> Sorry, delete is still broken with your patch, isn't it?

Oh, right - I forgot that one and it didn't occur to me to test this
part.

> The earlier patch from Abhijit Menon-Sen does this properly for
> close_hash_and_insert and close_cat_blob, which I've queued already.

Abhijit, can you please tag your Git.pm patches so that I actually have
a chance to see and review it?

Thanks,

                                Petr "Pasky" Baudis
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users

Junio C Hamano
Petr Baudis <[hidden email]> writes:

> On Mon, Aug 04, 2008 at 01:05:56AM -0700, Junio C Hamano wrote:
>> Petr Baudis <[hidden email]> writes:
>>
>> > The hash_and_insert_object() and cat_blob() helpers were using
>> > an incorrect slice-from-ref Perl syntax. This patch fixes that up
>> > in the _close_*() helpers and make the _open_*() helpers use the
>> > same syntax for consistnecy.
>> >
>> > Signed-off-by: Petr Baudis <[hidden email]>
>> > ---
>> >
>> >   Wow, the command_bidi_pipe API really is dirty. Of course, it is
>> > my fault as anyone's since I didn't get around to review the patches
>> > introducing it.
>>
>> Sorry, delete is still broken with your patch, isn't it?
>
> Oh, right - I forgot that one and it didn't occur to me to test this
> part.
>
>> The earlier patch from Abhijit Menon-Sen does this properly for
>> close_hash_and_insert and close_cat_blob, which I've queued already.
>
> Abhijit, can you please tag your Git.pm patches so that I actually have
> a chance to see and review it?

It is $gmane/91316, Message-ID: <[hidden email]>

After queueing it, I actually had to revert it, because it seems to break
git-svn (t9106-git-svn-commit-diff-clobber.sh, test #8), and I am about to
go to bed.  If you did not see the same breakage with your patch that does
not "fix" delete, it could be that the git-svn uses some of the resources
that are released by the delete actually doing what it is asked to do.

---

At 2008-08-04 12:49:27 +0800, [hidden email] wrote:
>
> $self->{@vars} evaluates to undef. i can't find any mention of using
> arrays to dereference objects in the manual and elsewhere; is this a
> mistake?

Yes, @vars would be interpreted in scalar context, which certainly isn't
the intended effect.

-- ams

 perl/Git.pm |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 087d3d0..2ef437f 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -839,8 +839,8 @@ sub _close_hash_and_insert_object {
 
  my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
 
- command_close_bidi_pipe($self->{@vars});
- delete $self->{@vars};
+ command_close_bidi_pipe(@$self{@vars});
+ delete @$self{@vars};
 }
 
 =item cat_blob ( SHA1, FILEHANDLE )
@@ -928,8 +928,8 @@ sub _close_cat_blob {
 
  my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx);
 
- command_close_bidi_pipe($self->{@vars});
- delete $self->{@vars};
+ command_close_bidi_pipe(@$self{@vars});
+ delete @$self{@vars};
 }
 
 =back
--
1.6.0.rc0.43.g2aa74
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

[PATCH] Git.pm: localise $? in command_close_bidi_pipe()

Abhijit Menon-Sen-4
Git::DESTROY calls _close_cat_blob and _close_hash_and_insert_object,
which in turn call command_close_bidi_pipe, which calls waitpid, which
alters $?. If this happens during global destruction, it may alter the
program's exit status unexpectedly. Making $? local to the function
solves the problem.

(The problem was discovered due to a failure of test #8 in
t9106-git-svn-commit-diff-clobber.sh.)

Signed-off-by: Abhijit Menon-Sen <[hidden email]>
---

At 2008-08-04 01:37:06 -0700, [hidden email] wrote:
>
> After queueing it, I actually had to revert it, because it seems to
> break git-svn (t9106-git-svn-commit-diff-clobber.sh, test #8), and I
> am about to go to bed.

This patch in addition to my earlier one should solve the problem.

For test #8 to fail, the "git svn dcommit" must succeed, but in both
cases (i.e. without my patch applied, or with), the rebase fails:

    rebase refs/remotes/git-svn: command returned error: 1

This results in a call to "fatal $@" on git-svn.perl:254, which calls
"exit 1", and test_must_fail is happy.

With my patch, however, Git::DESTROY calls the two _close functions
during global destruction, which in turn call command_close_bidi_pipe,
which calls waitpid with sensible arguments this time, which alters $?,
thus altering the exit status of the dcommit itself to 0. Oops.

All of "make test" passes for me after this change.

-- ams

 perl/Git.pm |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 2ef437f..3b6707b 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -417,6 +417,7 @@ have more complicated structure.
 =cut
 
 sub command_close_bidi_pipe {
+ local $?;
  my ($pid, $in, $out, $ctx) = @_;
  foreach my $fh ($in, $out) {
  unless (close $fh) {
--
1.6.0.rc0.43.g2aa74
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [git/perl] unusual syntax?

David Christensen
In reply to this post by Tay Ray Chuan
> sub _close_hash_and_insert_object {
> my ($self) = @_;
>
> return unless defined($self->{hash_object_pid});
>
> my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
>
> command_close_bidi_pipe($self->{@vars});
> delete $self->{@vars};
> }
> $self->{@vars} evaluates to undef. i can't find any mention of using
> arrays to dereference objects in the manual and elsewhere; is this a
> mistake?


This is a hash slice notation, returning an array of hash values  
matching the corresponding keys.  5.10 removed some syntax warts in  
the case of hash slices; this is more portably expressed as @{$self}
{@vars}; this should work in 5.10 and earlier versions, and so is the  
preferred syntax.

Regards,

David
--
David Christensen
End Point Corporation
[hidden email]



--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Git.pm: localise $? in command_close_bidi_pipe()

Junio C Hamano
In reply to this post by Abhijit Menon-Sen-4
Abhijit Menon-Sen <[hidden email]> writes:

> With my patch, however, Git::DESTROY calls the two _close functions
> during global destruction, which in turn call command_close_bidi_pipe,
> which calls waitpid with sensible arguments this time, which alters $?,
> thus altering the exit status of the dcommit itself to 0. Oops.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html