From 6aaa65da20a8f0a4c95834f73f0b20d5dc3aa3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Tue, 6 Nov 2007 02:54:01 -0800 Subject: When exec() fails include the failing command in the error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn occasionally fails with no details as to what went wrong - this should help debug those situations. Signed-off-by: Ask Bjørn Hansen Signed-off-by: Junio C Hamano --- perl/Git.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 3f4080cbf8..dca92c8adb 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -812,7 +812,7 @@ sub _cmd_exec { $self->wc_subdir() and chdir($self->wc_subdir()); } _execv_git_cmd(@args); - die "exec failed: $!"; + die qq[exec "@args" failed: $!]; } # Execute the given Git command ($_[0]) with arguments ($_[1..]) -- cgit v1.2.3 From 346d203bc3931c33f2e40093ee9325ab0334b9fe Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 23 Nov 2007 19:04:52 +0100 Subject: Add config_int() method to the Git perl module Integer variables can have optional 'k', 'm' or 'g' suffix. config_int() method will return simple decimal number, taking care of those suffixes. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- perl/Git.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index dca92c8adb..7468460f9a 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -549,6 +549,37 @@ sub config_bool { }; } +=item config_int ( VARIABLE ) + +Retrieve the integer configuration C. The return value +is simple decimal number. An optional value suffix of 'k', 'm', +or 'g' in the config file will cause the value to be multiplied +by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output. +It would return C if configuration variable is not defined, + +Must be called on a repository instance. + +This currently wraps command('config') so it is not so fast. + +=cut + +sub config_int { + my ($self, $var) = @_; + $self->repo_path() + or throw Error::Simple("not a repository"); + + try { + return $self->command_oneline('config', '--int', '--get', $var); + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return undef; + } else { + throw $E; + } + }; +} =item ident ( TYPE | IDENTSTR ) -- cgit v1.2.3 From b4c61ed6d35ea00494f953a27abbc902617972ec Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 5 Dec 2007 00:50:23 -0800 Subject: Color support for "git-add -i" This is mostly lifted from earlier series by Dan Zwell, but updated to use "git config --get-color" and "git config --get-colorbool" to make it simpler and more consistent with commands written in C. A new configuration color.interactive variable is like color.diff and color.status, and controls if "git-add -i" uses color. A set of configuration variables, color.interactive., are used to define what color is used for the prompt, header, and help text. For perl scripts, Git.pm provides $repo->get_color() method, which takes the slot name and the default color, and returns the terminal escape sequence to color the output text. $repo->get_colorbool() method can be used to check if color is set to be used for a given operation. Signed-off-by: Junio C Hamano --- perl/Git.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 7468460f9a..a2812ea612 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -581,6 +581,41 @@ sub config_int { }; } +=item get_colorbool ( NAME ) + +Finds if color should be used for NAMEd operation from the configuration, +and returns boolean (true for "use color", false for "do not use color"). + +=cut + +sub get_colorbool { + my ($self, $var) = @_; + my $stdout_to_tty = (-t STDOUT) ? "true" : "false"; + my $use_color = $self->command_oneline('config', '--get-colorbool', + $var, $stdout_to_tty); + return ($use_color eq 'true'); +} + +=item get_color ( SLOT, COLOR ) + +Finds color for SLOT from the configuration, while defaulting to COLOR, +and returns the ANSI color escape sequence: + + print $repo->get_color("color.interactive.prompt", "underline blue white"); + print "some text"; + print $repo->get_color("", "normal"); + +=cut + +sub get_color { + my ($self, $slot, $default) = @_; + my $color = $self->command_oneline('config', '--get-color', $slot, $default); + if (!defined $color) { + $color = ""; + } + return $color; +} + =item ident ( TYPE | IDENTSTR ) =item ident_person ( TYPE | IDENTSTR | IDENTARRAY ) -- cgit v1.2.3 From 28072a5d303b212695ef8b70f24cfed069ec94b8 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Mon, 10 Dec 2007 09:31:02 +0000 Subject: Don't cache DESTDIR in perl/perl.mak. DESTDIR is supposed to be overridden on 'make install' after doing 'make'. Have the automatically generated perl/perl.mak not cache the value of DESTDIR to support that for the perl/ subdirectory also. Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- perl/Makefile.PL | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'perl') diff --git a/perl/Makefile.PL b/perl/Makefile.PL index 6aecd897f8..320253eb8e 100644 --- a/perl/Makefile.PL +++ b/perl/Makefile.PL @@ -17,9 +17,6 @@ if ($@ || $Error::VERSION < 0.15009) { $pm{'private-Error.pm'} = '$(INST_LIBDIR)/Error.pm'; } -my %extra; -$extra{DESTDIR} = $ENV{DESTDIR} if $ENV{DESTDIR}; - # redirect stdout, otherwise the message "Writing perl.mak for Git" # disrupts the output for the target 'instlibdir' open STDOUT, ">&STDERR"; @@ -29,6 +26,5 @@ WriteMakefile( VERSION_FROM => 'Git.pm', PM => \%pm, MAKEFILE => 'perl.mak', - INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3', - %extra + INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3' ); -- cgit v1.2.3 From c2e357c2fe23ff900de158067ca11e5021e22741 Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Fri, 14 Mar 2008 18:29:28 +0100 Subject: Git.pm: Don't require a repository instance for config git config itself doesn't require to be called in a repository, so don't add arbitrary restrictions. Signed-off-by: Frank Lichtenheld Signed-off-by: Junio C Hamano --- perl/Git.pm | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index a2812ea612..67b3749f0e 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -487,22 +487,20 @@ does. In scalar context requires the variable to be set only one time (exception is thrown otherwise), in array context returns allows the variable to be set multiple times and returns all the values. -Must be called on a repository instance. - This currently wraps command('config') so it is not so fast. =cut sub config { - my ($self, $var) = @_; - $self->repo_path() - or throw Error::Simple("not a repository"); + my ($self, $var) = _maybe_self(@_); try { + my @cmd = ('config'); + unshift @cmd, $self if $self; if (wantarray) { - return $self->command('config', '--get-all', $var); + return command(@cmd, '--get-all', $var); } else { - return $self->command_oneline('config', '--get', $var); + return command_oneline(@cmd, '--get', $var); } } catch Git::Error::Command with { my $E = shift; @@ -522,20 +520,17 @@ Retrieve the bool configuration C. The return value is usable as a boolean in perl (and C if it's not defined, of course). -Must be called on a repository instance. - This currently wraps command('config') so it is not so fast. =cut sub config_bool { - my ($self, $var) = @_; - $self->repo_path() - or throw Error::Simple("not a repository"); + my ($self, $var) = _maybe_self(@_); try { - my $val = $self->command_oneline('config', '--bool', '--get', - $var); + my @cmd = ('config', '--bool', '--get', $var); + unshift @cmd, $self if $self; + my $val = command_oneline(@cmd); return undef unless defined $val; return $val eq 'true'; } catch Git::Error::Command with { @@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output. It would return C if configuration variable is not defined, -Must be called on a repository instance. - This currently wraps command('config') so it is not so fast. =cut sub config_int { - my ($self, $var) = @_; - $self->repo_path() - or throw Error::Simple("not a repository"); + my ($self, $var) = _maybe_self(@_); try { - return $self->command_oneline('config', '--int', '--get', $var); + my @cmd = ('config', '--int', '--get', $var); + unshift @cmd, $self if $self; + return command_oneline(@cmd); } catch Git::Error::Command with { my $E = shift; if ($E->value() == 1) { -- cgit v1.2.3 From 44617928ae4731b6139d87b978ddbc4860154222 Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Fri, 14 Mar 2008 18:29:29 +0100 Subject: Git.pm: Don't require repository instance for ident git var doesn't require to be called in a repository anymore, so don't require it either. Signed-off-by: Frank Lichtenheld Signed-off-by: Junio C Hamano --- perl/Git.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 67b3749f0e..2e7f896bae 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -632,15 +632,15 @@ The synopsis is like: "$name <$email>" eq ident_person($name); $time_tz =~ /^\d+ [+-]\d{4}$/; -Both methods must be called on a repository instance. - =cut sub ident { - my ($self, $type) = @_; + my ($self, $type) = _maybe_self(@_); my $identstr; if (lc $type eq lc 'committer' or lc $type eq lc 'author') { - $identstr = $self->command_oneline('var', 'GIT_'.uc($type).'_IDENT'); + my @cmd = ('var', 'GIT_'.uc($type).'_IDENT'); + unshift @cmd, $self if $self; + $identstr = command_oneline(@cmd); } else { $identstr = $type; } @@ -652,8 +652,8 @@ sub ident { } sub ident_person { - my ($self, @ident) = @_; - $#ident == 0 and @ident = $self->ident($ident[0]); + my ($self, @ident) = _maybe_self(@_); + $#ident == 0 and @ident = $self ? $self->ident($ident[0]) : ident($ident[0]); return "$ident[0] <$ident[1]>"; } -- cgit v1.2.3 From d1a29af98e61de72841657bcaa86a93b38cda1c2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 May 2008 16:19:39 +0200 Subject: Git.pm: Add command_bidi_pipe and command_close_bidi_pipe command_bidi_pipe hands back the stdin and stdout file handles from the executed command. command_close_bidi_pipe closes these handles and terminates the process. Signed-off-by: Adam Roben Signed-off-by: Junio C Hamano --- perl/Git.pm | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 2e7f896bae..d766974c96 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -51,6 +51,7 @@ require Exporter; # Methods which can be called as standalone functions as well: @EXPORT_OK = qw(command command_oneline command_noisy command_output_pipe command_input_pipe command_close_pipe + command_bidi_pipe command_close_bidi_pipe version exec_path hash_object git_cmd_try); @@ -92,6 +93,7 @@ increate nonwithstanding). use Carp qw(carp croak); # but croak is bad - throw instead use Error qw(:try); use Cwd qw(abs_path); +use IPC::Open2 qw(open2); } @@ -375,6 +377,60 @@ sub command_close_pipe { _cmd_close($fh, $ctx); } +=item command_bidi_pipe ( COMMAND [, ARGUMENTS... ] ) + +Execute the given C in the same way as command_output_pipe() +does but return both an input pipe filehandle and an output pipe filehandle. + +The function will return return C<($pid, $pipe_in, $pipe_out, $ctx)>. +See C for details. + +=cut + +sub command_bidi_pipe { + my ($pid, $in, $out); + $pid = open2($in, $out, 'git', @_); + return ($pid, $in, $out, join(' ', @_)); +} + +=item command_close_bidi_pipe ( PID, PIPE_IN, PIPE_OUT [, CTX] ) + +Close the C and C as returned from C, +checking whether the command finished successfully. The optional C +argument is required if you want to see the command name in the error message, +and it is the fourth value returned by C. The call idiom +is: + + my ($pid, $in, $out, $ctx) = $r->command_bidi_pipe('cat-file --batch-check'); + print "000000000\n" $out; + while (<$in>) { ... } + $r->command_close_bidi_pipe($pid, $in, $out, $ctx); + +Note that you should not rely on whatever actually is in C; +currently it is simply the command name but in future the context might +have more complicated structure. + +=cut + +sub command_close_bidi_pipe { + my ($pid, $in, $out, $ctx) = @_; + foreach my $fh ($in, $out) { + unless (close $fh) { + if ($!) { + carp "error closing pipe: $!"; + } elsif ($? >> 8) { + throw Git::Error::Command($ctx, $? >>8); + } + } + } + + waitpid $pid, 0; + + if ($? >> 8) { + throw Git::Error::Command($ctx, $? >>8); + } +} + =item command_noisy ( COMMAND [, ARGUMENTS... ] ) -- cgit v1.2.3 From 7182530d8cad5ffc396bed5d37f97cfb14b7e599 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 May 2008 16:19:40 +0200 Subject: Git.pm: Add hash_and_insert_object and cat_blob These functions are more efficient ways of executing `git hash-object -w` and `git cat-file blob` when you are dealing with many files/objects. Signed-off-by: Adam Roben Signed-off-by: Junio C Hamano --- perl/Git.pm | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index d766974c96..6ba8ee5c0d 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -39,6 +39,10 @@ $VERSION = '0.01'; my $lastrev = $repo->command_oneline( [ 'rev-list', '--all' ], STDERR => 0 ); + my $sha1 = $repo->hash_and_insert_object('file.txt'); + my $tempfile = tempfile(); + my $size = $repo->cat_blob($sha1, $tempfile); + =cut @@ -218,7 +222,6 @@ sub repository { bless $self, $class; } - =back =head1 METHODS @@ -734,6 +737,147 @@ sub hash_object { } +=item hash_and_insert_object ( FILENAME ) + +Compute the SHA1 object id of the given C and add the object to the +object database. + +The function returns the SHA1 hash. + +=cut + +# TODO: Support for passing FILEHANDLE instead of FILENAME +sub hash_and_insert_object { + my ($self, $filename) = @_; + + carp "Bad filename \"$filename\"" if $filename =~ /[\r\n]/; + + $self->_open_hash_and_insert_object_if_needed(); + my ($in, $out) = ($self->{hash_object_in}, $self->{hash_object_out}); + + unless (print $out $filename, "\n") { + $self->_close_hash_and_insert_object(); + throw Error::Simple("out pipe went bad"); + } + + chomp(my $hash = <$in>); + unless (defined($hash)) { + $self->_close_hash_and_insert_object(); + throw Error::Simple("in pipe went bad"); + } + + return $hash; +} + +sub _open_hash_and_insert_object_if_needed { + my ($self) = @_; + + return if defined($self->{hash_object_pid}); + + ($self->{hash_object_pid}, $self->{hash_object_in}, + $self->{hash_object_out}, $self->{hash_object_ctx}) = + command_bidi_pipe(qw(hash-object -w --stdin-paths)); +} + +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}; +} + +=item cat_blob ( SHA1, FILEHANDLE ) + +Prints the contents of the blob identified by C to C and +returns the number of bytes printed. + +=cut + +sub cat_blob { + my ($self, $sha1, $fh) = @_; + + $self->_open_cat_blob_if_needed(); + my ($in, $out) = ($self->{cat_blob_in}, $self->{cat_blob_out}); + + unless (print $out $sha1, "\n") { + $self->_close_cat_blob(); + throw Error::Simple("out pipe went bad"); + } + + my $description = <$in>; + if ($description =~ / missing$/) { + carp "$sha1 doesn't exist in the repository"; + return 0; + } + + if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) { + carp "Unexpected result returned from git cat-file"; + return 0; + } + + my $size = $1; + + my $blob; + my $bytesRead = 0; + + while (1) { + my $bytesLeft = $size - $bytesRead; + last unless $bytesLeft; + + my $bytesToRead = $bytesLeft < 1024 ? $bytesLeft : 1024; + my $read = read($in, $blob, $bytesToRead, $bytesRead); + unless (defined($read)) { + $self->_close_cat_blob(); + throw Error::Simple("in pipe went bad"); + } + + $bytesRead += $read; + } + + # Skip past the trailing newline. + my $newline; + my $read = read($in, $newline, 1); + unless (defined($read)) { + $self->_close_cat_blob(); + throw Error::Simple("in pipe went bad"); + } + unless ($read == 1 && $newline eq "\n") { + $self->_close_cat_blob(); + throw Error::Simple("didn't find newline after blob"); + } + + unless (print $fh $blob) { + $self->_close_cat_blob(); + throw Error::Simple("couldn't write to passed in filehandle"); + } + + return $size; +} + +sub _open_cat_blob_if_needed { + my ($self) = @_; + + return if defined($self->{cat_blob_pid}); + + ($self->{cat_blob_pid}, $self->{cat_blob_in}, + $self->{cat_blob_out}, $self->{cat_blob_ctx}) = + command_bidi_pipe(qw(cat-file --batch)); +} + +sub _close_cat_blob { + my ($self) = @_; + + return unless defined($self->{cat_blob_pid}); + + my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx); + + command_close_bidi_pipe($self->{@vars}); + delete $self->{@vars}; +} =back @@ -951,7 +1095,11 @@ sub _cmd_close { } -sub DESTROY { } +sub DESTROY { + my ($self) = @_; + $self->_close_hash_and_insert_object(); + $self->_close_cat_blob(); +} # Pipe implementation for ActiveState Perl. -- cgit v1.2.3 From d683a0e00cd4734b4fab704baef1ee76205722be Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 27 May 2008 23:33:22 -0700 Subject: Git::cat_blob: allow using an empty blob to fix git-svn breakage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recent "git-svn optimization" series introduced Git::cat_blob() subroutine whose interface was broken in that it returned the size of the blob but signalled an error by returning 0. You can never use an empty blob with such an interface. This fixes the interface to return a negative value to signal an error. Reported by Björn Steinbrink. Signed-off-by: Junio C Hamano --- perl/Git.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 6ba8ee5c0d..d05b633b64 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -811,12 +811,12 @@ sub cat_blob { my $description = <$in>; if ($description =~ / missing$/) { carp "$sha1 doesn't exist in the repository"; - return 0; + return -1; } if ($description !~ /^[0-9a-fA-F]{40} \S+ (\d+)$/) { carp "Unexpected result returned from git cat-file"; - return 0; + return -1; } my $size = $1; -- cgit v1.2.3 From 58c8dd217384b8d1a464a55a98c665ed108c6b15 Mon Sep 17 00:00:00 2001 From: Lea Wiemann Date: Sun, 1 Jun 2008 22:26:25 +0200 Subject: Git.pm: fix documentation of hash_object The documentation of hash_object incorrectly states that it accepts a file handle -- in fact it doesn't, and there is even a TODO comment for this. This fixes the documentation. Signed-off-by: Lea Wiemann Signed-off-by: Junio C Hamano --- perl/Git.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index d05b633b64..e2141b6381 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -719,9 +719,8 @@ sub ident_person { =item hash_object ( TYPE, FILENAME ) -Compute the SHA1 object id of the given C (or data waiting in -C) considering it is of the C object type (C, -C, C). +Compute the SHA1 object id of the given C considering it is +of the C object type (C, C, C). The method can be called without any instance or on a specified Git repository, it makes zero difference. -- cgit v1.2.3 From 32d8050a86f8de0253430b12711354e66a317f29 Mon Sep 17 00:00:00 2001 From: Lea Wiemann Date: Sun, 1 Jun 2008 22:34:47 +0200 Subject: Git.pm: fix return value of config method If config is called in array context, it is supposed to return all values set for the given option key. This works for all cases except if there is no value set at all. In that case, it wrongly returns (undef) instead of (). This fixes the return statement so that it returns undef in scalar context but an empty array in array context. Signed-off-by: Lea Wiemann Signed-off-by: Junio C Hamano --- perl/Git.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index e2141b6381..97e61efaff 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -565,7 +565,7 @@ sub config { my $E = shift; if ($E->value() == 1) { # Key not found. - return undef; + return; } else { throw $E; } -- cgit v1.2.3 From 31a92f6aa47732e93f6685b8d1fd1ac09c1fec44 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Tue, 8 Jul 2008 19:48:04 +0200 Subject: Git.pm: Add remote_refs() git-ls-remote frontend This patch also converts the good ole' git-remote.perl to use it. It is otherwise used in the repo.or.cz machinery and I guess other scripts might find it useful too. Unfortunately, git-ls-remote --heads . is subtly different from git-ls-remote . refs/heads/ (since the second matches anywhere in the string, not just at the beginning) so we have to provide interface for both. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- perl/Git.pm | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 97e61efaff..d99e778200 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -56,7 +56,8 @@ require Exporter; @EXPORT_OK = qw(command command_oneline command_noisy command_output_pipe command_input_pipe command_close_pipe command_bidi_pipe command_close_bidi_pipe - version exec_path hash_object git_cmd_try); + version exec_path hash_object git_cmd_try + remote_refs); =head1 DESCRIPTION @@ -668,6 +669,59 @@ sub get_color { return $color; } +=item remote_refs ( REPOSITORY [, GROUPS [, REFGLOBS ] ] ) + +This function returns a hashref of refs stored in a given remote repository. +The hash is in the format C hash>. For tags, the C entry +contains the tag object while a C entry gives the tagged objects. + +C has the same meaning as the appropriate C +argument; either an URL or a remote name (if called on a repository instance). +C is an optional arrayref that can contain 'tags' to return all the +tags and/or 'heads' to return all the heads. C is an optional array +of strings containing a shell-like glob to further limit the refs returned in +the hash; the meaning is again the same as the appropriate C +argument. + +This function may or may not be called on a repository instance. In the former +case, remote names as defined in the repository are recognized as repository +specifiers. + +=cut + +sub remote_refs { + my ($self, $repo, $groups, $refglobs) = _maybe_self(@_); + my @args; + if (ref $groups eq 'ARRAY') { + foreach (@$groups) { + if ($_ eq 'heads') { + push (@args, '--heads'); + } elsif ($_ eq 'tags') { + push (@args, '--tags'); + } else { + # Ignore unknown groups for future + # compatibility + } + } + } + push (@args, $repo); + if (ref $refglobs eq 'ARRAY') { + push (@args, @$refglobs); + } + + my @self = $self ? ($self) : (); # Ultra trickery + my ($fh, $ctx) = Git::command_output_pipe(@self, 'ls-remote', @args); + my %refs; + while (<$fh>) { + chomp; + my ($hash, $ref) = split(/\t/, $_, 2); + $refs{$ref} = $hash; + } + Git::command_close_pipe(@self, $fh, $ctx); + return \%refs; +} + + =item ident ( TYPE | IDENTSTR ) =item ident_person ( TYPE | IDENTSTR | IDENTARRAY ) -- cgit v1.2.3 From 058fb414804d545cc7dcca1313078d6a7e7bbd37 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Tue, 22 Jul 2008 16:15:41 -0500 Subject: perl/Makefile: update NO_PERL_MAKEMAKER section The perl modules must be copied to blib/lib so they are available for testing. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- perl/Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'perl') diff --git a/perl/Makefile b/perl/Makefile index 5e079ad011..b8547db2c6 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -22,13 +22,18 @@ clean: ifdef NO_PERL_MAKEMAKER instdir_SQ = $(subst ','\'',$(prefix)/lib) $(makfile): ../GIT-CFLAGS Makefile - echo all: > $@ - echo ' :' >> $@ + echo all: private-Error.pm Git.pm > $@ + echo ' mkdir -p blib/lib' >> $@ + echo ' $(RM) blib/lib/Git.pm; cp Git.pm blib/lib/' >> $@ + echo ' $(RM) blib/lib/Error.pm' >> $@ + '$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \ + echo ' cp private-Error.pm blib/lib/Error.pm' >> $@ echo install: >> $@ echo ' mkdir -p $(instdir_SQ)' >> $@ echo ' $(RM) $(instdir_SQ)/Git.pm; cp Git.pm $(instdir_SQ)' >> $@ - echo ' $(RM) $(instdir_SQ)/Error.pm; \ - cp private-Error.pm $(instdir_SQ)/Error.pm' >> $@ + echo ' $(RM) $(instdir_SQ)/Error.pm' >> $@ + '$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \ + echo ' cp private-Error.pm $(instdir_SQ)/Error.pm' >> $@ echo instlibdir: >> $@ echo ' echo $(instdir_SQ)' >> $@ else -- cgit v1.2.3 From 5354a56fe70420c147f930e0f7f1decbae685d19 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Wed, 30 Jul 2008 13:48:33 -0400 Subject: Replace uses of "git-var" with "git var" Signed-off-by: Todd Zullinger Signed-off-by: Junio C Hamano --- perl/Git.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index d99e778200..087d3d0e82 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -730,7 +730,7 @@ This suite of functions retrieves and parses ident information, as stored in the commit and tag objects or produced by C (thus C can be either I or I; case is insignificant). -The C method retrieves the ident information from C +The C method retrieves the ident information from C and either returns it as a scalar string or as an array with the fields parsed. Alternatively, it can take a prepared ident string (e.g. from the commit object) and just parse it. -- cgit v1.2.3 From 108c2aaf7984081daa6aed6d3947c7c0952216c2 Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Mon, 4 Aug 2008 17:08:27 +0530 Subject: Git.pm: localise $? in command_close_bidi_pipe() 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 Signed-off-by: Junio C Hamano --- perl/Git.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 087d3d0e82..faaa19f62e 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) { -- cgit v1.2.3 From 452d36b1f33e10a9492eb2adad357108b26ea381 Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Mon, 4 Aug 2008 10:32:47 +0530 Subject: Fix hash slice syntax error Signed-off-by: Abhijit Menon-Sen Signed-off-by: Junio C Hamano --- perl/Git.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index faaa19f62e..3b6707b051 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -840,8 +840,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 ) @@ -929,8 +929,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 -- cgit v1.2.3 From 9751a32a6b964df11f736f3526bf5453e6b5bc85 Mon Sep 17 00:00:00 2001 From: Abhijit Menon-Sen Date: Tue, 5 Aug 2008 07:36:16 +0530 Subject: Fix typo in perl/Git.pm Signed-off-by: Abhijit Menon-Sen Signed-off-by: Junio C Hamano --- perl/Git.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 3b6707b051..e1ca5b4a22 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -90,7 +90,7 @@ TODO: In the future, we might also do Currently, the module merely wraps calls to external Git tools. In the future, it will provide a much faster way to interact with Git by linking directly to libgit. This should be completely opaque to the user, though (performance -increate nonwithstanding). +increase notwithstanding). =cut -- cgit v1.2.3 From 1fc2cbc1d8614c469d28a5a8f11a904f294245af Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Tue, 5 Aug 2008 18:23:08 -0500 Subject: perl/Makefile: handle paths with spaces in the NO_PERL_MAKEMAKER section Use double quotes to protect against paths which may contain spaces. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- perl/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'perl') diff --git a/perl/Makefile b/perl/Makefile index b8547db2c6..e3dd1a5547 100644 --- a/perl/Makefile +++ b/perl/Makefile @@ -29,11 +29,11 @@ $(makfile): ../GIT-CFLAGS Makefile '$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \ echo ' cp private-Error.pm blib/lib/Error.pm' >> $@ echo install: >> $@ - echo ' mkdir -p $(instdir_SQ)' >> $@ - echo ' $(RM) $(instdir_SQ)/Git.pm; cp Git.pm $(instdir_SQ)' >> $@ - echo ' $(RM) $(instdir_SQ)/Error.pm' >> $@ + echo ' mkdir -p "$(instdir_SQ)"' >> $@ + echo ' $(RM) "$(instdir_SQ)/Git.pm"; cp Git.pm "$(instdir_SQ)"' >> $@ + echo ' $(RM) "$(instdir_SQ)/Error.pm"' >> $@ '$(PERL_PATH_SQ)' -MError -e 'exit($$Error::VERSION < 0.15009)' || \ - echo ' cp private-Error.pm $(instdir_SQ)/Error.pm' >> $@ + echo ' cp private-Error.pm "$(instdir_SQ)/Error.pm"' >> $@ echo instlibdir: >> $@ echo ' echo $(instdir_SQ)' >> $@ else -- cgit v1.2.3 From e41352b24e29eba43d00a3fd117befaef1d594bc Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Tue, 12 Aug 2008 12:00:18 -0400 Subject: Git.pm: Add faculties to allow temp files to be cached This patch offers a generic interface to allow temp files to be cached while using an instance of the 'Git' package. If many temp files are created and destroyed during the execution of a program, this caching mechanism can help reduce the amount of files created and destroyed by the filesystem. The temp_acquire method provides a weak guarantee that a temp file will not be stolen by subsequent requests. If a file is locked when another acquire request is made, a simple error is thrown. Signed-off-by: Marcus Griep Acked-by: Eric Wong --- perl/Git.pm | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index e1ca5b4a22..405f68fc39 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -57,7 +57,8 @@ require Exporter; command_output_pipe command_input_pipe command_close_pipe command_bidi_pipe command_close_bidi_pipe version exec_path hash_object git_cmd_try - remote_refs); + remote_refs + temp_acquire temp_release temp_reset); =head1 DESCRIPTION @@ -99,7 +100,9 @@ use Carp qw(carp croak); # but croak is bad - throw instead use Error qw(:try); use Cwd qw(abs_path); use IPC::Open2 qw(open2); - +use File::Temp (); +require File::Spec; +use Fcntl qw(SEEK_SET SEEK_CUR); } @@ -933,6 +936,124 @@ sub _close_cat_blob { delete @$self{@vars}; } + +{ # %TEMP_* Lexical Context + +my (%TEMP_LOCKS, %TEMP_FILES); + +=item temp_acquire ( NAME ) + +Attempts to retreive the temporary file mapped to the string C. If an +associated temp file has not been created this session or was closed, it is +created, cached, and set for autoflush and binmode. + +Internally locks the file mapped to C. This lock must be released with +C when the temp file is no longer needed. Subsequent attempts +to retrieve temporary files mapped to the same C while still locked will +cause an error. This locking mechanism provides a weak guarantee and is not +threadsafe. It does provide some error checking to help prevent temp file refs +writing over one another. + +In general, the L returned should not be closed by consumers as +it defeats the purpose of this caching mechanism. If you need to close the temp +file handle, then you should use L or another temp file faculty +directly. If a handle is closed and then requested again, then a warning will +issue. + +=cut + +sub temp_acquire { + my ($self, $name) = _maybe_self(@_); + + my $temp_fd = _temp_cache($name); + + $TEMP_LOCKS{$temp_fd} = 1; + $temp_fd; +} + +=item temp_release ( NAME ) + +=item temp_release ( FILEHANDLE ) + +Releases a lock acquired through C. Can be called either with +the C mapping used when acquiring the temp file or with the C +referencing a locked temp file. + +Warns if an attempt is made to release a file that is not locked. + +The temp file will be truncated before being released. This can help to reduce +disk I/O where the system is smart enough to detect the truncation while data +is in the output buffers. Beware that after the temp file is released and +truncated, any operations on that file may fail miserably until it is +re-acquired. All contents are lost between each release and acquire mapped to +the same string. + +=cut + +sub temp_release { + my ($self, $temp_fd, $trunc) = _maybe_self(@_); + + if (ref($temp_fd) ne 'File::Temp') { + $temp_fd = $TEMP_FILES{$temp_fd}; + } + unless ($TEMP_LOCKS{$temp_fd}) { + carp "Attempt to release temp file '", + $temp_fd, "' that has not been locked"; + } + temp_reset($temp_fd) if $trunc and $temp_fd->opened; + + $TEMP_LOCKS{$temp_fd} = 0; + undef; +} + +sub _temp_cache { + my ($name) = @_; + + my $temp_fd = \$TEMP_FILES{$name}; + if (defined $$temp_fd and $$temp_fd->opened) { + if ($TEMP_LOCKS{$$temp_fd}) { + throw Error::Simple("Temp file with moniker '", + $name, "' already in use"); + } + } else { + if (defined $$temp_fd) { + # then we're here because of a closed handle. + carp "Temp file '", $name, + "' was closed. Opening replacement."; + } + $$temp_fd = File::Temp->new( + TEMPLATE => 'Git_XXXXXX', + DIR => File::Spec->tmpdir + ) or throw Error::Simple("couldn't open new temp file"); + $$temp_fd->autoflush; + binmode $$temp_fd; + } + $$temp_fd; +} + +=item temp_reset ( FILEHANDLE ) + +Truncates and resets the position of the C. + +=cut + +sub temp_reset { + my ($self, $temp_fd) = _maybe_self(@_); + + truncate $temp_fd, 0 + or throw Error::Simple("couldn't truncate file"); + sysseek($temp_fd, 0, SEEK_SET) and seek($temp_fd, 0, SEEK_SET) + or throw Error::Simple("couldn't seek to beginning of file"); + sysseek($temp_fd, 0, SEEK_CUR) == 0 and tell($temp_fd) == 0 + or throw Error::Simple("expected file position to be reset"); +} + +sub END { + unlink values %TEMP_FILES if %TEMP_FILES; +} + +} # %TEMP_* Lexical Context + =back =head1 ERROR HANDLING -- cgit v1.2.3 From c14c8ceb13b299892f286757e22e6af4f6cffab5 Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Fri, 15 Aug 2008 15:53:59 -0400 Subject: Git.pm: Make File::Spec and File::Temp requirement lazy This will ensure that the API at large is accessible to nearly all Perl versions, while only the temp file caching API is tied to the File::Temp and File::Spec modules being available. Signed-off-by: Marcus Griep Signed-off-by: Junio C Hamano --- perl/Git.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 405f68fc39..102e6a4ce3 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -100,8 +100,6 @@ use Carp qw(carp croak); # but croak is bad - throw instead use Error qw(:try); use Cwd qw(abs_path); use IPC::Open2 qw(open2); -use File::Temp (); -require File::Spec; use Fcntl qw(SEEK_SET SEEK_CUR); } @@ -1009,6 +1007,8 @@ sub temp_release { sub _temp_cache { my ($name) = @_; + _verify_require(); + my $temp_fd = \$TEMP_FILES{$name}; if (defined $$temp_fd and $$temp_fd->opened) { if ($TEMP_LOCKS{$$temp_fd}) { @@ -1031,6 +1031,11 @@ sub _temp_cache { $$temp_fd; } +sub _verify_require { + eval { require File::Temp; require File::Spec; }; + $@ and throw Error::Simple($@); +} + =item temp_reset ( FILEHANDLE ) Truncates and resets the position of the C. -- cgit v1.2.3 From 836ff95df6de9924cf8cf23515e3779a67a6bdec Mon Sep 17 00:00:00 2001 From: Marcus Griep Date: Mon, 8 Sep 2008 12:53:01 -0400 Subject: Git.pm: Use File::Temp->tempfile instead of ->new Perl 5.8.0 ships with File::Temp 0.13, which does not have the new() interface introduced in 0.14, as pointed out by Tom G. Christensen. This modifies Git.pm to use the more established tempfile() interface and updates 'git svn' to match. Signed-off-by: Marcus Griep Acked-by: Eric Wong Tested-by: Tom G. Christensen Signed-off-by: Junio C Hamano --- perl/Git.pm | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 102e6a4ce3..6aab712e6a 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -58,7 +58,7 @@ require Exporter; command_bidi_pipe command_close_bidi_pipe version exec_path hash_object git_cmd_try remote_refs - temp_acquire temp_release temp_reset); + temp_acquire temp_release temp_reset temp_path); =head1 DESCRIPTION @@ -937,7 +937,7 @@ sub _close_cat_blob { { # %TEMP_* Lexical Context -my (%TEMP_LOCKS, %TEMP_FILES); +my (%TEMP_FILEMAP, %TEMP_FILES); =item temp_acquire ( NAME ) @@ -965,7 +965,7 @@ sub temp_acquire { my $temp_fd = _temp_cache($name); - $TEMP_LOCKS{$temp_fd} = 1; + $TEMP_FILES{$temp_fd}{locked} = 1; $temp_fd; } @@ -991,16 +991,16 @@ the same string. sub temp_release { my ($self, $temp_fd, $trunc) = _maybe_self(@_); - if (ref($temp_fd) ne 'File::Temp') { + if (exists $TEMP_FILEMAP{$temp_fd}) { $temp_fd = $TEMP_FILES{$temp_fd}; } - unless ($TEMP_LOCKS{$temp_fd}) { + unless ($TEMP_FILES{$temp_fd}{locked}) { carp "Attempt to release temp file '", $temp_fd, "' that has not been locked"; } temp_reset($temp_fd) if $trunc and $temp_fd->opened; - $TEMP_LOCKS{$temp_fd} = 0; + $TEMP_FILES{$temp_fd}{locked} = 0; undef; } @@ -1009,9 +1009,9 @@ sub _temp_cache { _verify_require(); - my $temp_fd = \$TEMP_FILES{$name}; + my $temp_fd = \$TEMP_FILEMAP{$name}; if (defined $$temp_fd and $$temp_fd->opened) { - if ($TEMP_LOCKS{$$temp_fd}) { + if ($TEMP_FILES{$$temp_fd}{locked}) { throw Error::Simple("Temp file with moniker '", $name, "' already in use"); } @@ -1021,12 +1021,13 @@ sub _temp_cache { carp "Temp file '", $name, "' was closed. Opening replacement."; } - $$temp_fd = File::Temp->new( - TEMPLATE => 'Git_XXXXXX', - DIR => File::Spec->tmpdir + my $fname; + ($$temp_fd, $fname) = File::Temp->tempfile( + 'Git_XXXXXX', UNLINK => 1 ) or throw Error::Simple("couldn't open new temp file"); $$temp_fd->autoflush; binmode $$temp_fd; + $TEMP_FILES{$$temp_fd}{fname} = $fname; } $$temp_fd; } @@ -1053,8 +1054,25 @@ sub temp_reset { or throw Error::Simple("expected file position to be reset"); } +=item temp_path ( NAME ) + +=item temp_path ( FILEHANDLE ) + +Returns the filename associated with the given tempfile. + +=cut + +sub temp_path { + my ($self, $temp_fd) = _maybe_self(@_); + + if (exists $TEMP_FILEMAP{$temp_fd}) { + $temp_fd = $TEMP_FILEMAP{$temp_fd}; + } + $TEMP_FILES{$temp_fd}{fname}; +} + sub END { - unlink values %TEMP_FILES if %TEMP_FILES; + unlink values %TEMP_FILEMAP if %TEMP_FILEMAP; } } # %TEMP_* Lexical Context -- cgit v1.2.3 From d8b24b930f5b7150e63d989de39eb71bd37e8e63 Mon Sep 17 00:00:00 2001 From: Christian Jaeger Date: Sat, 18 Oct 2008 20:25:12 +0200 Subject: Git.pm: do not break inheritance Make it possible to write subclasses of Git.pm Signed-off-by: Christian Jaeger Signed-off-by: Junio C Hamano --- perl/Git.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 6aab712e6a..ba94453781 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -1203,8 +1203,7 @@ either version 2, or (at your option) any later version. # the method was called upon an instance and (undef, @args) if # it was called directly. sub _maybe_self { - # This breaks inheritance. Oh well. - ref $_[0] eq 'Git' ? @_ : (undef, @_); + UNIVERSAL::isa($_[0], 'Git') ? @_ : (undef, @_); } # Check if the command id is something reasonable. -- cgit v1.2.3 From bcdd1b4456998256df19ea0347bf4a7fa5410eef Mon Sep 17 00:00:00 2001 From: "Marten Svanfeldt (dev)" Date: Thu, 13 Nov 2008 20:04:09 +0800 Subject: Git.pm: Make _temp_cache use the repository directory Update the usage of File::Temp->tempfile to place the temporary files within the repository directory instead of just letting Perl decide what directory to use, given there is a repository specified when requesting the temporary file. This is needed to be able to fix git-svn on msys as msysperl generates paths with UNIX-style paths (/tmp/xxx) while the git tools expect natvie path format (c:/..). The repository dir is stored in native format so by using it as the base directory for temporary files we always get a usable native full path. Signed-off-by: Marten Svanfeldt Acked-by: Eric Wong --- perl/Git.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index ba94453781..dde9105df8 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -961,9 +961,7 @@ issue. =cut sub temp_acquire { - my ($self, $name) = _maybe_self(@_); - - my $temp_fd = _temp_cache($name); + my $temp_fd = _temp_cache(@_); $TEMP_FILES{$temp_fd}{locked} = 1; $temp_fd; @@ -1005,7 +1003,7 @@ sub temp_release { } sub _temp_cache { - my ($name) = @_; + my ($self, $name) = _maybe_self(@_); _verify_require(); @@ -1022,9 +1020,16 @@ sub _temp_cache { "' was closed. Opening replacement."; } my $fname; + + my $tmpdir; + if (defined $self) { + $tmpdir = $self->repo_path(); + } + ($$temp_fd, $fname) = File::Temp->tempfile( - 'Git_XXXXXX', UNLINK => 1 + 'Git_XXXXXX', UNLINK => 1, DIR => $tmpdir, ) or throw Error::Simple("couldn't open new temp file"); + $$temp_fd->autoflush; binmode $$temp_fd; $TEMP_FILES{$$temp_fd}{fname} = $fname; -- cgit v1.2.3 From f66bc5f928194366ee5eb78ef18a3562fb1bb7cf Mon Sep 17 00:00:00 2001 From: Richard Hartmann Date: Mon, 22 Dec 2008 00:17:32 +0100 Subject: Always show which directory is not a git repository Unify all fatal: Not a git repository error messages so they include path information. Signed-off-by: Richard Hartmann Signed-off-by: Junio C Hamano --- perl/Git.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index dde9105df8..8392a68333 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -204,14 +204,14 @@ sub repository { unless (-d "$dir/refs" and -d "$dir/objects" and -e "$dir/HEAD") { # Mimick git-rev-parse --git-dir error message: - throw Error::Simple('fatal: Not a git repository'); + throw Error::Simple("fatal: Not a git repository: $dir"); } my $search = Git->repository(Repository => $dir); try { $search->command('symbolic-ref', 'HEAD'); } catch Git::Error::Command with { # Mimick git-rev-parse --git-dir error message: - throw Error::Simple('fatal: Not a git repository'); + throw Error::Simple("fatal: Not a git repository: $dir"); } $opts{Repository} = abs_path($dir); -- cgit v1.2.3 From 11b8a41c4569e99a57137cb2db4b642b57171797 Mon Sep 17 00:00:00 2001 From: "Philippe Bruhat (BooK)" Date: Mon, 29 Dec 2008 01:25:00 +0100 Subject: Git.pm: correctly handle directory name that evaluates to "false" The repository constructor mistakenly rewrote a Directory parameter that Perl happens to evaluate to false (e.g. "0") to ".". Signed-off-by: Junio C Hamano --- perl/Git.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 8392a68333..ad0f530445 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -166,11 +166,12 @@ sub repository { } } - if (not defined $opts{Repository} and not defined $opts{WorkingCopy}) { - $opts{Directory} ||= '.'; + if (not defined $opts{Repository} and not defined $opts{WorkingCopy} + and not defined $opts{Directory}) { + $opts{Directory} = '.'; } - if ($opts{Directory}) { + if (defined $opts{Directory}) { -d $opts{Directory} or throw Error::Simple("Directory not found: $!"); my $search = Git->repository(WorkingCopy => $opts{Directory}); -- cgit v1.2.3 From 8faea4f3b2f68a6ef168c6ada1627835380a570d Mon Sep 17 00:00:00 2001 From: Jay Soffian Date: Tue, 13 Jan 2009 17:41:35 -0500 Subject: Git.pm: call Error::Simple() properly The error message to Error::Simple() must be passed as a single argument. Signed-off-by: Jay Soffian Signed-off-by: Junio C Hamano --- perl/Git.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index ba94453781..29a17839f3 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -1012,8 +1012,8 @@ sub _temp_cache { my $temp_fd = \$TEMP_FILEMAP{$name}; if (defined $$temp_fd and $$temp_fd->opened) { if ($TEMP_FILES{$$temp_fd}{locked}) { - throw Error::Simple("Temp file with moniker '", - $name, "' already in use"); + throw Error::Simple("Temp file with moniker '" . + $name . "' already in use"); } } else { if (defined $$temp_fd) { -- cgit v1.2.3 From 89a56bfbd3fd855cb0c2a381520e6255de41a55e Mon Sep 17 00:00:00 2001 From: Markus Heidelberg Date: Sun, 5 Apr 2009 04:15:16 +0200 Subject: add --html-path to get the location of installed HTML docs This can be used in GUIs to open installed HTML documentation in the browser. Signed-off-by: Markus Heidelberg Signed-off-by: Junio C Hamano --- perl/Git.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'perl') diff --git a/perl/Git.pm b/perl/Git.pm index 7d7f2b1d36..291ff5b53c 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -56,7 +56,7 @@ require Exporter; @EXPORT_OK = qw(command command_oneline command_noisy command_output_pipe command_input_pipe command_close_pipe command_bidi_pipe command_close_bidi_pipe - version exec_path hash_object git_cmd_try + version exec_path html_path hash_object git_cmd_try remote_refs temp_acquire temp_release temp_reset temp_path); @@ -492,6 +492,16 @@ C). Useful mostly only internally. sub exec_path { command_oneline('--exec-path') } +=item html_path () + +Return path to the Git html documentation (the same as +C). Useful mostly only internally. + +=cut + +sub html_path { command_oneline('--html-path') } + + =item repo_path () Return path to the git repository. Must be called on a repository instance. -- cgit v1.2.3