{"thread":{"id":"4646","subject":"[PATCH 01/12] Introduce Git.pm (v4)","startedAt":"2006-06-24T02:34:29Z","lastAt":"2006-06-25T03:12:59Z","messageCount":25,"participants":["Petr Baudis","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"22400","messageId":"20060624023429.32751.80619.stgit@machine.or.cz","threadId":"4646","inReplyTo":null,"subject":"[PATCH 01/12] Introduce Git.pm (v4)","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:29Z","receivedAt":"2006-06-24T02:34:29Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch introduces a very basic and barebone Git.pm module\nwith a sketch of how the generic interface would look like;\nmost functions are missing, but this should give some good base.\nI will continue expanding it.\n\nMost desirable now is more careful error reporting, generic_in() for feeding\ninput to Git commands and the repository() constructor doing some poking\nwith git-rev-parse to get the git directory and subdirectory prefix.\nThose three are basically the prerequisities for converting git-mv.\nI will send them as follow-ups to this patch.\n\nCurrently Git.pm just wraps up exec()s of Git commands, but even that\nis not trivial to get right and various Git perl scripts do it in\nvarious inconsistent ways. In addition to Git.pm, there is now also\nGit.xs which provides barebone Git.xs for directly interfacing with\nlibgit.a, and as an example providing the hash_object() function using\nlibgit.\n\nThis adds the Git module, integrates it to the build system and as\nan example converts the git-fmt-merge-msg.perl script to it (the result\nis not very impressive since its advantage is not quite apparent in this\none, but I just picked up the simplest Git user around).\n\nCompared to v3, only very minor things were fixed in this patch (some\nwhitespaces, a missing export, tiny bug in git-fmt-merge-msg.perl);\nat first I wanted to post them as a separate patch but since this\nis still only in pu, I decided that it will be cleaner to just resend\nthe patch.\n\nMy current working state is available all the time at\n\n\thttp://pasky.or.cz/~xpasky/git-perl/Git.pm\n\nand an irregularily updated API documentation is at\n\n\thttp://pasky.or.cz/~xpasky/git-perl/Git.html\n\nMany thanks to Jakub Narebski, Junio and others for their feedback.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n Makefile               |   12 +\n git-fmt-merge-msg.perl |   13 +-\n perl/.gitignore        |    7 +\n perl/Git.pm            |  408 ++++++++++++++++++++++++++++++++++++++++++++++++\n perl/Git.xs            |   64 ++++++++\n perl/Makefile.PL       |   21 ++\n 6 files changed, 516 insertions(+), 9 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex a5b6784..4d20b22 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -476,7 +476,8 @@ ### Build rules\n \n all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk\n \n-all:\n+all: perl/Makefile\n+\t$(MAKE) -C perl\n \t$(MAKE) -C templates\n \n strip: $(PROGRAMS) git$X\n@@ -508,7 +509,7 @@ common-cmds.h: Documentation/git-*.txt\n \n $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl\n \trm -f $@ $@+\n-\tsed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \\\n+\tsed -e '1s|#!.*perl\\(.*\\)|#!$(PERL_PATH_SQ)\\1 -I'\"$$(make -s -C perl instlibdir)\"'|' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    $@.perl >$@+\n \tchmod +x $@+\n@@ -594,6 +595,9 @@ XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare\n \trm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS)\n \n \n+perl/Makefile:\tperl/Git.pm perl/Makefile.PL\n+\t(cd perl && $(PERL_PATH) Makefile.PL PREFIX=\"$(prefix)\" DEFINE=\"$(ALL_CFLAGS)\" LIBS=\"$(LIBS)\")\n+\n doc:\n \t$(MAKE) -C Documentation all\n \n@@ -649,6 +653,7 @@ install: all\n \t$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'\n \t$(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)'\n \t$(MAKE) -C templates install\n+\t$(MAKE) -C perl install\n \t$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'\n \t$(INSTALL) $(PYMODULES) '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'\n \tif test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \\\n@@ -716,7 +721,8 @@ clean:\n \trm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz\n \trm -f $(htmldocs).tar.gz $(manpages).tar.gz\n \t$(MAKE) -C Documentation/ clean\n-\t$(MAKE) -C templates clean\n+\t[ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean\n+\t$(MAKE) -C templates/ clean\n \t$(MAKE) -C t/ clean\n \trm -f GIT-VERSION-FILE GIT-CFLAGS\n \ndiff --git a/git-fmt-merge-msg.perl b/git-fmt-merge-msg.perl\nindex 5986e54..be2a48c 100755\n--- a/git-fmt-merge-msg.perl\n+++ b/git-fmt-merge-msg.perl\n@@ -6,6 +6,9 @@ # Read .git/FETCH_HEAD and make a human \n # by grouping branches and tags together to form a single line.\n \n use strict;\n+use Git;\n+\n+my $repo = Git->repository();\n \n my @src;\n my %src;\n@@ -28,13 +31,12 @@ sub andjoin {\n }\n \n sub repoconfig {\n-\tmy ($val) = qx{git-repo-config --get merge.summary};\n+\tmy ($val) = $repo->command_oneline('repo-config', '--get', 'merge.summary');\n \treturn $val;\n }\n \n sub current_branch {\n-\tmy ($bra) = qx{git-symbolic-ref HEAD};\n-\tchomp($bra);\n+\tmy ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD');\n \t$bra =~ s|^refs/heads/||;\n \tif ($bra ne 'master') {\n \t\t$bra = \" into $bra\";\n@@ -47,11 +49,10 @@ sub current_branch {\n sub shortlog {\n \tmy ($tip) = @_;\n \tmy @result;\n-\tforeach ( qx{git-log --no-merges --topo-order --pretty=oneline $tip ^HEAD} ) {\n+\tforeach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) {\n \t\ts/^[0-9a-f]{40}\\s+//;\n \t\tpush @result, $_;\n \t}\n-\tdie \"git-log failed\\n\" if $?;\n \treturn @result;\n }\n \n@@ -168,6 +169,6 @@ for (@origin) {\n \t\t\tprint \"  ...\\n\";\n \t\t\tlast;\n \t\t}\n-\t\tprint \"  $log\";\n+\t\tprint \"  $log\\n\";\n \t}\n }\ndiff --git a/perl/.gitignore b/perl/.gitignore\nnew file mode 100644\nindex 0000000..6d778f3\n--- /dev/null\n+++ b/perl/.gitignore\n@@ -0,0 +1,7 @@\n+Git.bs\n+Git.c\n+Makefile\n+blib\n+blibdirs\n+pm_to_blib\n+ppport.h\ndiff --git a/perl/Git.pm b/perl/Git.pm\nnew file mode 100644\nindex 0000000..8fff785\n--- /dev/null\n+++ b/perl/Git.pm\n@@ -0,0 +1,408 @@\n+=head1 NAME\n+\n+Git - Perl interface to the Git version control system\n+\n+=cut\n+\n+\n+package Git;\n+\n+use strict;\n+\n+\n+BEGIN {\n+\n+our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);\n+\n+# Totally unstable API.\n+$VERSION = '0.01';\n+\n+\n+=head1 SYNOPSIS\n+\n+  use Git;\n+\n+  my $version = Git::command_oneline('version');\n+\n+  Git::command_noisy('update-server-info');\n+\n+  my $repo = Git->repository (Directory => '/srv/git/cogito.git');\n+\n+\n+  my @revs = $repo->command('rev-list', '--since=last monday', '--all');\n+\n+  my $fh = $repo->command_pipe('rev-list', '--since=last monday', '--all');\n+  my $lastrev = <$fh>; chomp $lastrev;\n+  close $fh; # You may want to test rev-list exit status here\n+\n+  my $lastrev = $repo->command_oneline('rev-list', '--all');\n+\n+=cut\n+\n+\n+require Exporter;\n+\n+@ISA = qw(Exporter);\n+\n+@EXPORT = qw();\n+\n+# Methods which can be called as standalone functions as well:\n+@EXPORT_OK = qw(command command_oneline command_pipe command_noisy\n+                hash_object);\n+\n+\n+=head1 DESCRIPTION\n+\n+This module provides Perl scripts easy way to interface the Git version control\n+system. The modules have an easy and well-tested way to call arbitrary Git\n+commands; in the future, the interface will also provide specialized methods\n+for doing easily operations which are not totally trivial to do over\n+the generic command interface.\n+\n+While some commands can be executed outside of any context (e.g. 'version'\n+or 'init-db'), most operations require a repository context, which in practice\n+means getting an instance of the Git object using the repository() constructor.\n+(In the future, we will also get a new_repository() constructor.) All commands\n+called as methods of the object are then executed in the context of the\n+repository.\n+\n+TODO: In the future, we might also do\n+\n+\tmy $subdir = $repo->subdir('Documentation');\n+\t# Gets called in the subdirectory context:\n+\t$subdir->command('status');\n+\n+\tmy $remoterepo = $repo->remote_repository (Name => 'cogito', Branch => 'master');\n+\t$remoterepo ||= Git->remote_repository ('http://git.or.cz/cogito.git/');\n+\tmy @refs = $remoterepo->refs();\n+\n+So far, all functions just die if anything goes wrong. If you don't want that,\n+make appropriate provisions to catch the possible deaths. Better error recovery\n+mechanisms will be provided in the future.\n+\n+Currently, the module merely wraps calls to external Git tools. In the future,\n+it will provide a much faster way to interact with Git by linking directly\n+to libgit. This should be completely opaque to the user, though (performance\n+increate nonwithstanding).\n+\n+=cut\n+\n+\n+use Carp qw(carp croak);\n+\n+require XSLoader;\n+XSLoader::load('Git', $VERSION);\n+\n+}\n+\n+\n+=head1 CONSTRUCTORS\n+\n+=over 4\n+\n+=item repository ( OPTIONS )\n+\n+=item repository ( DIRECTORY )\n+\n+=item repository ()\n+\n+Construct a new repository object.\n+C<OPTIONS> are passed in a hash like fashion, using key and value pairs.\n+Possible options are:\n+\n+B<Repository> - Path to the Git repository.\n+\n+B<WorkingCopy> - Path to the associated working copy; not strictly required\n+as many commands will happily crunch on a bare repository.\n+\n+B<Directory> - Path to the Git working directory in its usual setup. This\n+is just for convenient setting of both C<Repository> and C<WorkingCopy>\n+at once: If the directory as a C<.git> subdirectory, C<Repository> is pointed\n+to the subdirectory and the directory is assumed to be the working copy.\n+If the directory does not have the subdirectory, C<WorkingCopy> is left\n+undefined and C<Repository> is pointed to the directory itself.\n+\n+B<GitPath> - Path to the C<git> binary executable. By default the C<$PATH>\n+is searched for it.\n+\n+You should not use both C<Directory> and either of C<Repository> and\n+C<WorkingCopy> - the results of that are undefined.\n+\n+Alternatively, a directory path may be passed as a single scalar argument\n+to the constructor; it is equivalent to setting only the C<Directory> option\n+field.\n+\n+Calling the constructor with no options whatsoever is equivalent to\n+calling it with C<< Directory => '.' >>.\n+\n+=cut\n+\n+sub repository {\n+\tmy $class = shift;\n+\tmy @args = @_;\n+\tmy %opts = ();\n+\tmy $self;\n+\n+\tif (defined $args[0]) {\n+\t\tif ($#args % 2 != 1) {\n+\t\t\t# Not a hash.\n+\t\t\t$#args == 0 or croak \"bad usage\";\n+\t\t\t%opts = (Directory => $args[0]);\n+\t\t} else {\n+\t\t\t%opts = @args;\n+\t\t}\n+\n+\t\tif ($opts{Directory}) {\n+\t\t\t-d $opts{Directory} or croak \"Directory not found: $!\";\n+\t\t\tif (-d $opts{Directory}.\"/.git\") {\n+\t\t\t\t# TODO: Might make this more clever\n+\t\t\t\t$opts{WorkingCopy} = $opts{Directory};\n+\t\t\t\t$opts{Repository} = $opts{Directory}.\"/.git\";\n+\t\t\t} else {\n+\t\t\t\t$opts{Repository} = $opts{Directory};\n+\t\t\t}\n+\t\t\tdelete $opts{Directory};\n+\t\t}\n+\t}\n+\n+\t$self = { opts => \\%opts };\n+\tbless $self, $class;\n+}\n+\n+\n+=back\n+\n+=head1 METHODS\n+\n+=over 4\n+\n+=item command ( COMMAND [, ARGUMENTS... ] )\n+\n+Execute the given Git C<COMMAND> (specify it without the 'git-'\n+prefix), optionally with the specified extra C<ARGUMENTS>.\n+\n+The method can be called without any instance or on a specified Git repository\n+(in that case the command will be run in the repository context).\n+\n+In scalar context, it returns all the command output in a single string\n+(verbatim).\n+\n+In array context, it returns an array containing lines printed to the\n+command's stdout (without trailing newlines).\n+\n+In both cases, the command's stdin and stderr are the same as the caller's.\n+\n+=cut\n+\n+sub command {\n+\tmy $fh = command_pipe(@_);\n+\n+\tif (not defined wantarray) {\n+\t\t_cmd_close($fh);\n+\n+\t} elsif (not wantarray) {\n+\t\tlocal $/;\n+\t\tmy $text = <$fh>;\n+\t\t_cmd_close($fh);\n+\t\treturn $text;\n+\n+\t} else {\n+\t\tmy @lines = <$fh>;\n+\t\t_cmd_close($fh);\n+\t\tchomp @lines;\n+\t\treturn @lines;\n+\t}\n+}\n+\n+\n+=item command_oneline ( COMMAND [, ARGUMENTS... ] )\n+\n+Execute the given C<COMMAND> in the same way as command()\n+does but always return a scalar string containing the first line\n+of the command's standard output.\n+\n+=cut\n+\n+sub command_oneline {\n+\tmy $fh = command_pipe(@_);\n+\n+\tmy $line = <$fh>;\n+\t_cmd_close($fh);\n+\n+\tchomp $line;\n+\treturn $line;\n+}\n+\n+\n+=item command_pipe ( COMMAND [, ARGUMENTS... ] )\n+\n+Execute the given C<COMMAND> in the same way as command()\n+does but return a pipe filehandle from which the command output can be\n+read.\n+\n+=cut\n+\n+sub command_pipe {\n+\tmy ($self, $cmd, @args) = _maybe_self(@_);\n+\n+\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or croak \"bad command: $cmd\";\n+\n+\tmy $pid = open(my $fh, \"-|\");\n+\tif (not defined $pid) {\n+\t\tcroak \"open failed: $!\";\n+\t} elsif ($pid == 0) {\n+\t\t_cmd_exec($self, $cmd, @args);\n+\t}\n+\treturn $fh;\n+}\n+\n+\n+=item command_noisy ( COMMAND [, ARGUMENTS... ] )\n+\n+Execute the given C<COMMAND> in the same way as command() does but do not\n+capture the command output - the standard output is not redirected and goes\n+to the standard output of the caller application.\n+\n+While the method is called command_noisy(), you might want to as well use\n+it for the most silent Git commands which you know will never pollute your\n+stdout but you want to avoid the overhead of the pipe setup when calling them.\n+\n+The function returns only after the command has finished running.\n+\n+=cut\n+\n+sub command_noisy {\n+\tmy ($self, $cmd, @args) = _maybe_self(@_);\n+\n+\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or croak \"bad command: $cmd\";\n+\n+\tmy $pid = fork;\n+\tif (not defined $pid) {\n+\t\tcroak \"fork failed: $!\";\n+\t} elsif ($pid == 0) {\n+\t\t_cmd_exec($self, $cmd, @args);\n+\t}\n+\tif (waitpid($pid, 0) > 0 and $? != 0) {\n+\t\tcroak \"exit status: $?\";\n+\t}\n+}\n+\n+\n+=item hash_object ( FILENAME [, TYPE ] )\n+\n+=item hash_object ( FILEHANDLE [, TYPE ] )\n+\n+Compute the SHA1 object id of the given C<FILENAME> (or data waiting in\n+C<FILEHANDLE>) considering it is of the C<TYPE> object type (C<blob>\n+(default), C<commit>, C<tree>).\n+\n+In case of C<FILEHANDLE> passed instead of file name, all the data\n+available are read and hashed, and the filehandle is automatically\n+closed. The file handle should be freshly opened - if you have already\n+read anything from the file handle, the results are undefined (since\n+this function works directly with the file descriptor and internal\n+PerlIO buffering might have messed things up).\n+\n+The method can be called without any instance or on a specified Git repository,\n+it makes zero difference.\n+\n+The function returns the SHA1 hash.\n+\n+Implementation of this function is very fast; no external command calls\n+are involved.\n+\n+=cut\n+\n+# Implemented in Git.xs.\n+\n+\n+=back\n+\n+=head1 TODO\n+\n+This is still fairly crude.\n+We need some good way to report errors back except just dying.\n+\n+=head1 COPYRIGHT\n+\n+Copyright 2006 by Petr Baudis E<lt>pasky@suse.czE<gt>.\n+\n+This module is free software; it may be used, copied, modified\n+and distributed under the terms of the GNU General Public Licence,\n+either version 2, or (at your option) any later version.\n+\n+=cut\n+\n+\n+# Take raw method argument list and return ($obj, @args) in case\n+# the method was called upon an instance and (undef, @args) if\n+# it was called directly.\n+sub _maybe_self {\n+\t# This breaks inheritance. Oh well.\n+\tref $_[0] eq 'Git' ? @_ : (undef, @_);\n+}\n+\n+# When already in the subprocess, set up the appropriate state\n+# for the given repository and execute the git command.\n+sub _cmd_exec {\n+\tmy ($self, @args) = @_;\n+\tif ($self) {\n+\t\t$self->{opts}->{Repository} and $ENV{'GIT_DIR'} = $self->{opts}->{Repository};\n+\t\t$self->{opts}->{WorkingCopy} and chdir($self->{opts}->{WorkingCopy});\n+\t}\n+\tmy $git = $self->{opts}->{GitPath};\n+\t$git ||= 'git';\n+\texec ($git, @args) or croak \"exec failed: $!\";\n+}\n+\n+# Close pipe to a subprocess.\n+sub _cmd_close {\n+\tmy ($fh) = @_;\n+\tif (not close $fh) {\n+\t\tif ($!) {\n+\t\t\t# It's just close, no point in fatalities\n+\t\t\tcarp \"error closing pipe: $!\";\n+\t\t} elsif ($? >> 8) {\n+\t\t\tcroak \"exit status: \".($? >> 8);\n+\t\t}\n+\t\t# else we might e.g. closed a live stream; the command\n+\t\t# dying of SIGPIPE would drive us here.\n+\t}\n+}\n+\n+\n+# Trickery for .xs routines: In order to avoid having some horrid\n+# C code trying to do stuff with undefs and hashes, we gate all\n+# xs calls through the following and in case we are being ran upon\n+# an instance call a C part of the gate which will set up the\n+# environment properly.\n+sub _call_gate {\n+\tmy $xsfunc = shift;\n+\tmy ($self, @args) = _maybe_self(@_);\n+\n+\tif (defined $self) {\n+\t\t# XXX: We ignore the WorkingCopy! To properly support\n+\t\t# that will require heavy changes in libgit.\n+\n+\t\t# XXX: And we ignore everything else as well. libgit\n+\t\t# at least needs to be extended to let us specify\n+\t\t# the $GIT_DIR instead of looking it up in environment.\n+\t\t#xs_call_gate($self->{opts}->{Repository});\n+\t}\n+\n+\t&$xsfunc(@args);\n+}\n+\n+sub AUTOLOAD {\n+\tmy $xsname;\n+\tour $AUTOLOAD;\n+\t($xsname = $AUTOLOAD) =~ s/.*:://;\n+\tcroak \"&Git::$xsname not defined\" if $xsname =~ /^xs_/;\n+\t$xsname = 'xs_'.$xsname;\n+\t_call_gate(\\&$xsname, @_);\n+}\n+\n+sub DESTROY { }\n+\n+\n+1; # Famous last words\ndiff --git a/perl/Git.xs b/perl/Git.xs\nnew file mode 100644\nindex 0000000..9885e2c\n--- /dev/null\n+++ b/perl/Git.xs\n@@ -0,0 +1,64 @@\n+/* By carefully stacking #includes here (even if WE don't really need them)\n+ * we strive to make the thing actually compile. Git header files aren't very\n+ * nice. Perl headers are one of the signs of the coming apocalypse. */\n+#include <ctype.h>\n+/* Ok, it hasn't been so bad so far. */\n+\n+/* libgit interface */\n+#include \"../cache.h\"\n+\n+/* XS and Perl interface */\n+#include \"EXTERN.h\"\n+#include \"perl.h\"\n+#include \"XSUB.h\"\n+\n+#include \"ppport.h\"\n+\n+\n+MODULE = Git\t\tPACKAGE = Git\t\t\n+\n+PROTOTYPES: DISABLE\n+\n+# /* TODO: xs_call_gate(). See Git.pm. */\n+\n+char *\n+xs_hash_object(file, type = \"blob\")\n+\tSV *file;\n+\tchar *type;\n+CODE:\n+{\n+\tunsigned char sha1[20];\n+\n+\tif (SvTYPE(file) == SVt_RV)\n+\t\tfile = SvRV(file);\n+\n+\tif (SvTYPE(file) == SVt_PVGV) {\n+\t\t/* Filehandle */\n+\t\tPerlIO *pio;\n+\n+\t\tpio = IoIFP(sv_2io(file));\n+\t\tif (!pio)\n+\t\t\tcroak(\"You passed me something weird - a dir glob?\");\n+\t\t/* XXX: I just hope PerlIO didn't read anything from it yet.\n+\t\t * --pasky */\n+\t\tif (index_pipe(sha1, PerlIO_fileno(pio), type, 0))\n+\t\t\tcroak(\"Unable to hash given filehandle\");\n+\t\t/* Avoid any nasty surprises. */\n+\t\tPerlIO_close(pio);\n+\n+\t} else {\n+\t\t/* String */\n+\t\tchar *path = SvPV_nolen(file);\n+\t\tint fd = open(path, O_RDONLY);\n+\t\tstruct stat st;\n+\n+\t\tif (fd < 0 ||\n+\t\t    fstat(fd, &st) < 0 ||\n+\t\t    index_fd(sha1, fd, &st, 0, type))\n+\t\t\tcroak(\"Unable to hash %s\", path);\n+\t\tclose(fd);\n+\t}\n+\tRETVAL = sha1_to_hex(sha1);\n+}\n+OUTPUT:\n+\tRETVAL\ndiff --git a/perl/Makefile.PL b/perl/Makefile.PL\nnew file mode 100644\nindex 0000000..dd61056\n--- /dev/null\n+++ b/perl/Makefile.PL\n@@ -0,0 +1,21 @@\n+use ExtUtils::MakeMaker;\n+\n+sub MY::postamble {\n+\treturn <<'MAKE_FRAG';\n+instlibdir:\n+\t@echo $(INSTALLSITELIB)\n+\n+MAKE_FRAG\n+}\n+\n+WriteMakefile(\n+\tNAME            => 'Git',\n+\tVERSION_FROM    => 'Git.pm',\n+\tMYEXTLIB        => '../libgit.a',\n+\tINC             => '-I. -I..',\n+);\n+\n+\n+use Devel::PPPort;\n+\n+-s 'ppport.h' or Devel::PPPort::WriteFile();\n"},{"id":"22401","messageId":"20060624023431.32751.75101.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 02/12] Git.pm: Implement Git::exec_path()","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:31Z","receivedAt":"2006-06-24T02:34:31Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch implements Git::exec_path() (as a direct XS call).\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |   15 ++++++++++++++-\n perl/Git.xs |   12 ++++++++++++\n 2 files changed, 26 insertions(+), 1 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 8fff785..5c5ae12 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -48,7 +48,7 @@ require Exporter;\n \n # Methods which can be called as standalone functions as well:\n @EXPORT_OK = qw(command command_oneline command_pipe command_noisy\n-                hash_object);\n+                exec_path hash_object);\n \n \n =head1 DESCRIPTION\n@@ -288,6 +288,19 @@ sub command_noisy {\n }\n \n \n+=item exec_path ()\n+\n+Return path to the git sub-command executables (the same as\n+C<git --exec-path>). Useful mostly only internally.\n+\n+Implementation of this function is very fast; no external command calls\n+are involved.\n+\n+=cut\n+\n+# Implemented in Git.xs.\n+\n+\n =item hash_object ( FILENAME [, TYPE ] )\n \n =item hash_object ( FILEHANDLE [, TYPE ] )\ndiff --git a/perl/Git.xs b/perl/Git.xs\nindex 9885e2c..b6f6d13 100644\n--- a/perl/Git.xs\n+++ b/perl/Git.xs\n@@ -6,6 +6,7 @@ #include <ctype.h>\n \n /* libgit interface */\n #include \"../cache.h\"\n+#include \"../exec_cmd.h\"\n \n /* XS and Perl interface */\n #include \"EXTERN.h\"\n@@ -21,6 +22,17 @@ PROTOTYPES: DISABLE\n \n # /* TODO: xs_call_gate(). See Git.pm. */\n \n+\n+const char *\n+xs_exec_path()\n+CODE:\n+{\n+\tRETVAL = git_exec_path();\n+}\n+OUTPUT:\n+\tRETVAL\n+\n+\n char *\n xs_hash_object(file, type = \"blob\")\n \tSV *file;\n"},{"id":"22403","messageId":"20060624023433.32751.68321.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 03/12] Git.pm: Call external commands using execv_git_cmd()","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:34Z","receivedAt":"2006-06-24T02:34:34Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Instead of explicitly using the git wrapper to call external commands,\nuse the execv_git_cmd() function which will directly call whatever\nneeds to be called. GitBin option becomes useless so drop it.\n\nThis actually means the exec_path() thing I planned to use worthless\ninternally, but Jakub wants it in anyway and I don't mind, so...\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |   12 ++++++------\n perl/Git.xs |   22 ++++++++++++++++++++++\n 2 files changed, 28 insertions(+), 6 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 5c5ae12..212337e 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -122,9 +122,6 @@ to the subdirectory and the directory is\n If the directory does not have the subdirectory, C<WorkingCopy> is left\n undefined and C<Repository> is pointed to the directory itself.\n \n-B<GitPath> - Path to the C<git> binary executable. By default the C<$PATH>\n-is searched for it.\n-\n You should not use both C<Directory> and either of C<Repository> and\n C<WorkingCopy> - the results of that are undefined.\n \n@@ -363,11 +360,14 @@ sub _cmd_exec {\n \t\t$self->{opts}->{Repository} and $ENV{'GIT_DIR'} = $self->{opts}->{Repository};\n \t\t$self->{opts}->{WorkingCopy} and chdir($self->{opts}->{WorkingCopy});\n \t}\n-\tmy $git = $self->{opts}->{GitPath};\n-\t$git ||= 'git';\n-\texec ($git, @args) or croak \"exec failed: $!\";\n+\txs__execv_git_cmd(@args);\n+\tcroak \"exec failed: $!\";\n }\n \n+# Execute the given Git command ($_[0]) with arguments ($_[1..])\n+# by searching for it at proper places.\n+# _execv_git_cmd(), implemented in Git.xs.\n+\n # Close pipe to a subprocess.\n sub _cmd_close {\n \tmy ($fh) = @_;\ndiff --git a/perl/Git.xs b/perl/Git.xs\nindex b6f6d13..c8220e2 100644\n--- a/perl/Git.xs\n+++ b/perl/Git.xs\n@@ -33,6 +33,28 @@ OUTPUT:\n \tRETVAL\n \n \n+void\n+xs__execv_git_cmd(...)\n+CODE:\n+{\n+\tconst char **argv;\n+\tint i;\n+\n+\targv = malloc(sizeof(const char *) * (items + 1));\n+\tif (!argv)\n+\t\tcroak(\"malloc failed\");\n+\tfor (i = 0; i < items; i++)\n+\t\targv[i] = strdup(SvPV_nolen(ST(i)));\n+\targv[i] = NULL;\n+\n+\texecv_git_cmd(argv);\n+\n+\tfor (i = 0; i < items; i++)\n+\t\tif (argv[i])\n+\t\t\tfree((char *) argv[i]);\n+\tfree((char **) argv);\n+}\n+\n char *\n xs_hash_object(file, type = \"blob\")\n \tSV *file;\n"},{"id":"22404","messageId":"20060624023436.32751.67240.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 04/12] Git.pm: Implement Git::version()","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:36Z","receivedAt":"2006-06-24T02:34:36Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Git::version() returns the Git version string.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n Makefile    |    5 ++++-\n perl/Git.pm |   14 +++++++++++++-\n perl/Git.xs |   10 ++++++++++\n 3 files changed, 27 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 4d20b22..7842195 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -596,7 +596,10 @@ XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare\n \n \n perl/Makefile:\tperl/Git.pm perl/Makefile.PL\n-\t(cd perl && $(PERL_PATH) Makefile.PL PREFIX=\"$(prefix)\" DEFINE=\"$(ALL_CFLAGS)\" LIBS=\"$(LIBS)\")\n+\t(cd perl && $(PERL_PATH) Makefile.PL \\\n+\t\tPREFIX=\"$(prefix)\" \\\n+\t\tDEFINE=\"$(ALL_CFLAGS) -DGIT_VERSION=\\\\\\\"$(GIT_VERSION)\\\\\\\"\" \\\n+\t\tLIBS=\"$(LIBS)\")\n \n doc:\n \t$(MAKE) -C Documentation all\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 212337e..dcd769b 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -48,7 +48,7 @@ require Exporter;\n \n # Methods which can be called as standalone functions as well:\n @EXPORT_OK = qw(command command_oneline command_pipe command_noisy\n-                exec_path hash_object);\n+                version exec_path hash_object);\n \n \n =head1 DESCRIPTION\n@@ -285,6 +285,18 @@ sub command_noisy {\n }\n \n \n+=item version ()\n+\n+Return the Git version in use.\n+\n+Implementation of this function is very fast; no external command calls\n+are involved.\n+\n+=cut\n+\n+# Implemented in Git.xs.\n+\n+\n =item exec_path ()\n \n Return path to the git sub-command executables (the same as\ndiff --git a/perl/Git.xs b/perl/Git.xs\nindex c8220e2..9623fdd 100644\n--- a/perl/Git.xs\n+++ b/perl/Git.xs\n@@ -24,6 +24,16 @@ # /* TODO: xs_call_gate(). See Git.pm. *\n \n \n const char *\n+xs_version()\n+CODE:\n+{\n+\tRETVAL = GIT_VERSION;\n+}\n+OUTPUT:\n+\tRETVAL\n+\n+\n+const char *\n xs_exec_path()\n CODE:\n {\n"},{"id":"22402","messageId":"20060624023438.32751.46867.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 05/12] Customizable error handlers","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:38Z","receivedAt":"2006-06-24T02:34:38Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch makes the usage(), die() and error() handlers customizable.\nNothing in the git code itself uses that but many other libgit users\n(like Git.pm) will.\n\nThis is implemented using the mutator functions primarily because you\ncannot directly modifying global variables of libgit from a program that\ndlopen()ed it, apparently. But having functions for that is a better API\nanyway.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n git-compat-util.h |    4 ++++\n usage.c           |   46 ++++++++++++++++++++++++++++++++++++++++++----\n 2 files changed, 46 insertions(+), 4 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 5d543d2..b3d4cf5 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -40,6 +40,10 @@ extern void usage(const char *err) NORET\n extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));\n extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n \n+extern void set_usage_routine(void (*routine)(const char *err) NORETURN);\n+extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);\n+extern void set_error_routine(void (*routine)(const char *err, va_list params));\n+\n #ifdef NO_MMAP\n \n #ifndef PROT_READ\ndiff --git a/usage.c b/usage.c\nindex 1fa924c..b781b00 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -12,20 +12,58 @@ static void report(const char *prefix, c\n \tfputs(\"\\n\", stderr);\n }\n \n-void usage(const char *err)\n+void usage_builtin(const char *err)\n {\n \tfprintf(stderr, \"usage: %s\\n\", err);\n \texit(129);\n }\n \n+void die_builtin(const char *err, va_list params)\n+{\n+\treport(\"fatal: \", err, params);\n+\texit(128);\n+}\n+\n+void error_builtin(const char *err, va_list params)\n+{\n+\treport(\"error: \", err, params);\n+}\n+\n+\n+/* If we are in a dlopen()ed .so write to a global variable would segfault\n+ * (ugh), so keep things static. */\n+static void (*usage_routine)(const char *err) NORETURN = usage_builtin;\n+static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;\n+static void (*error_routine)(const char *err, va_list params) = error_builtin;\n+\n+void set_usage_routine(void (*routine)(const char *err) NORETURN)\n+{\n+\tusage_routine = routine;\n+}\n+\n+void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN)\n+{\n+\tdie_routine = routine;\n+}\n+\n+void set_error_routine(void (*routine)(const char *err, va_list params))\n+{\n+\terror_routine = routine;\n+}\n+\n+\n+void usage(const char *err)\n+{\n+\tusage_routine(err);\n+}\n+\n void die(const char *err, ...)\n {\n \tva_list params;\n \n \tva_start(params, err);\n-\treport(\"fatal: \", err, params);\n+\tdie_routine(err, params);\n \tva_end(params);\n-\texit(128);\n }\n \n int error(const char *err, ...)\n@@ -33,7 +71,7 @@ int error(const char *err, ...)\n \tva_list params;\n \n \tva_start(params, err);\n-\treport(\"error: \", err, params);\n+\terror_routine(err, params);\n \tva_end(params);\n \treturn -1;\n }\n"},{"id":"22405","messageId":"20060624023440.32751.11661.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 06/12] Add Error.pm to the distribution","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:40Z","receivedAt":"2006-06-24T02:34:40Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"I have been thinking about how to do the error reporting the best\nway and after scraping various overcomplicated concepts, I have\ndecided that by far the most elegant way is to throw Error exceptions;\nthe closest sane alternative is to catch the dies in Git.pm by\nenclosing the calls in eval{}s and that's really _quite_ ugly.\n\nThe only \"small\" trouble is that Error.pm turns out sadly not to be\npart of the standard distribution, and installation from CPAN is\na bother, especially if you can't install it system-wide. But since\nit is very small, I've decided to just bundle it.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Error.pm    |  821 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n perl/Makefile.PL |   10 +\n 2 files changed, 831 insertions(+), 0 deletions(-)\n\ndiff --git a/perl/Error.pm b/perl/Error.pm\nnew file mode 100644\nindex 0000000..17ad70a\n--- /dev/null\n+++ b/perl/Error.pm\n@@ -0,0 +1,821 @@\n+# Error.pm\n+#\n+# Copyright (c) 1997-8 Graham Barr <gbarr@ti.com>. All rights reserved.\n+# This program is free software; you can redistribute it and/or\n+# modify it under the same terms as Perl itself.\n+#\n+# Based on my original Error.pm, and Exceptions.pm by Peter Seibel\n+# <peter@weblogic.com> and adapted by Jesse Glick <jglick@sig.bsh.com>.\n+#\n+# but modified ***significantly***\n+\n+package Error;\n+\n+use strict;\n+use vars qw($VERSION);\n+use 5.004;\n+\n+$VERSION = \"0.15009\"; \n+\n+use overload (\n+\t'\"\"'\t   =>\t'stringify',\n+\t'0+'\t   =>\t'value',\n+\t'bool'     =>\tsub { return 1; },\n+\t'fallback' =>\t1\n+);\n+\n+$Error::Depth = 0;\t# Depth to pass to caller()\n+$Error::Debug = 0;\t# Generate verbose stack traces\n+@Error::STACK = ();\t# Clause stack for try\n+$Error::THROWN = undef;\t# last error thrown, a workaround until die $ref works\n+\n+my $LAST;\t\t# Last error created\n+my %ERROR;\t\t# Last error associated with package\n+\n+sub throw_Error_Simple\n+{\n+    my $args = shift;\n+    return Error::Simple->new($args->{'text'});\n+}\n+\n+$Error::ObjectifyCallback = \\&throw_Error_Simple;\n+\n+\n+# Exported subs are defined in Error::subs\n+\n+use Scalar::Util ();\n+\n+sub import {\n+    shift;\n+    local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;\n+    Error::subs->import(@_);\n+}\n+\n+# I really want to use last for the name of this method, but it is a keyword\n+# which prevent the syntax  last Error\n+\n+sub prior {\n+    shift; # ignore\n+\n+    return $LAST unless @_;\n+\n+    my $pkg = shift;\n+    return exists $ERROR{$pkg} ? $ERROR{$pkg} : undef\n+\tunless ref($pkg);\n+\n+    my $obj = $pkg;\n+    my $err = undef;\n+    if($obj->isa('HASH')) {\n+\t$err = $obj->{'__Error__'}\n+\t    if exists $obj->{'__Error__'};\n+    }\n+    elsif($obj->isa('GLOB')) {\n+\t$err = ${*$obj}{'__Error__'}\n+\t    if exists ${*$obj}{'__Error__'};\n+    }\n+\n+    $err;\n+}\n+\n+sub flush {\n+    shift; #ignore\n+    \n+    unless (@_) {\n+       $LAST = undef;\n+       return;\n+    }\n+    \n+    my $pkg = shift;\n+    return unless ref($pkg);\n+   \n+    undef $ERROR{$pkg} if defined $ERROR{$pkg}; \n+} \n+\n+# Return as much information as possible about where the error\n+# happened. The -stacktrace element only exists if $Error::DEBUG\n+# was set when the error was created\n+\n+sub stacktrace {\n+    my $self = shift;\n+\n+    return $self->{'-stacktrace'}\n+\tif exists $self->{'-stacktrace'};\n+\n+    my $text = exists $self->{'-text'} ? $self->{'-text'} : \"Died\";\n+\n+    $text .= sprintf(\" at %s line %d.\\n\", $self->file, $self->line)\n+\tunless($text =~ /\\n$/s);\n+\n+    $text;\n+}\n+\n+# Allow error propagation, ie\n+#\n+# $ber->encode(...) or\n+#    return Error->prior($ber)->associate($ldap);\n+\n+sub associate {\n+    my $err = shift;\n+    my $obj = shift;\n+\n+    return unless ref($obj);\n+\n+    if($obj->isa('HASH')) {\n+\t$obj->{'__Error__'} = $err;\n+    }\n+    elsif($obj->isa('GLOB')) {\n+\t${*$obj}{'__Error__'} = $err;\n+    }\n+    $obj = ref($obj);\n+    $ERROR{ ref($obj) } = $err;\n+\n+    return;\n+}\n+\n+sub new {\n+    my $self = shift;\n+    my($pkg,$file,$line) = caller($Error::Depth);\n+\n+    my $err = bless {\n+\t'-package' => $pkg,\n+\t'-file'    => $file,\n+\t'-line'    => $line,\n+\t@_\n+    }, $self;\n+\n+    $err->associate($err->{'-object'})\n+\tif(exists $err->{'-object'});\n+\n+    # To always create a stacktrace would be very inefficient, so\n+    # we only do it if $Error::Debug is set\n+\n+    if($Error::Debug) {\n+\trequire Carp;\n+\tlocal $Carp::CarpLevel = $Error::Depth;\n+\tmy $text = defined($err->{'-text'}) ? $err->{'-text'} : \"Error\";\n+\tmy $trace = Carp::longmess($text);\n+\t# Remove try calls from the trace\n+\t$trace =~ s/(\\n\\s+\\S+__ANON__[^\\n]+)?\\n\\s+eval[^\\n]+\\n\\s+Error::subs::try[^\\n]+(?=\\n)//sog;\n+\t$trace =~ s/(\\n\\s+\\S+__ANON__[^\\n]+)?\\n\\s+eval[^\\n]+\\n\\s+Error::subs::run_clauses[^\\n]+\\n\\s+Error::subs::try[^\\n]+(?=\\n)//sog;\n+\t$err->{'-stacktrace'} = $trace\n+    }\n+\n+    $@ = $LAST = $ERROR{$pkg} = $err;\n+}\n+\n+# Throw an error. this contains some very gory code.\n+\n+sub throw {\n+    my $self = shift;\n+    local $Error::Depth = $Error::Depth + 1;\n+\n+    # if we are not rethrow-ing then create the object to throw\n+    $self = $self->new(@_) unless ref($self);\n+    \n+    die $Error::THROWN = $self;\n+}\n+\n+# syntactic sugar for\n+#\n+#    die with Error( ... );\n+\n+sub with {\n+    my $self = shift;\n+    local $Error::Depth = $Error::Depth + 1;\n+\n+    $self->new(@_);\n+}\n+\n+# syntactic sugar for\n+#\n+#    record Error( ... ) and return;\n+\n+sub record {\n+    my $self = shift;\n+    local $Error::Depth = $Error::Depth + 1;\n+\n+    $self->new(@_);\n+}\n+\n+# catch clause for\n+#\n+# try { ... } catch CLASS with { ... }\n+\n+sub catch {\n+    my $pkg = shift;\n+    my $code = shift;\n+    my $clauses = shift || {};\n+    my $catch = $clauses->{'catch'} ||= [];\n+\n+    unshift @$catch,  $pkg, $code;\n+\n+    $clauses;\n+}\n+\n+# Object query methods\n+\n+sub object {\n+    my $self = shift;\n+    exists $self->{'-object'} ? $self->{'-object'} : undef;\n+}\n+\n+sub file {\n+    my $self = shift;\n+    exists $self->{'-file'} ? $self->{'-file'} : undef;\n+}\n+\n+sub line {\n+    my $self = shift;\n+    exists $self->{'-line'} ? $self->{'-line'} : undef;\n+}\n+\n+sub text {\n+    my $self = shift;\n+    exists $self->{'-text'} ? $self->{'-text'} : undef;\n+}\n+\n+# overload methods\n+\n+sub stringify {\n+    my $self = shift;\n+    defined $self->{'-text'} ? $self->{'-text'} : \"Died\";\n+}\n+\n+sub value {\n+    my $self = shift;\n+    exists $self->{'-value'} ? $self->{'-value'} : undef;\n+}\n+\n+package Error::Simple;\n+\n+@Error::Simple::ISA = qw(Error);\n+\n+sub new {\n+    my $self  = shift;\n+    my $text  = \"\" . shift;\n+    my $value = shift;\n+    my(@args) = ();\n+\n+    local $Error::Depth = $Error::Depth + 1;\n+\n+    @args = ( -file => $1, -line => $2)\n+\tif($text =~ s/\\s+at\\s+(\\S+)\\s+line\\s+(\\d+)(?:,\\s*<[^>]*>\\s+line\\s+\\d+)?\\.?\\n?$//s);\n+    push(@args, '-value', 0 + $value)\n+\tif defined($value);\n+\n+    $self->SUPER::new(-text => $text, @args);\n+}\n+\n+sub stringify {\n+    my $self = shift;\n+    my $text = $self->SUPER::stringify;\n+    $text .= sprintf(\" at %s line %d.\\n\", $self->file, $self->line)\n+\tunless($text =~ /\\n$/s);\n+    $text;\n+}\n+\n+##########################################################################\n+##########################################################################\n+\n+# Inspired by code from Jesse Glick <jglick@sig.bsh.com> and\n+# Peter Seibel <peter@weblogic.com>\n+\n+package Error::subs;\n+\n+use Exporter ();\n+use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS);\n+\n+@EXPORT_OK   = qw(try with finally except otherwise);\n+%EXPORT_TAGS = (try => \\@EXPORT_OK);\n+\n+@ISA = qw(Exporter);\n+\n+sub run_clauses ($$$\\@) {\n+    my($clauses,$err,$wantarray,$result) = @_;\n+    my $code = undef;\n+\n+    $err = $Error::ObjectifyCallback->({'text' =>$err}) unless ref($err);\n+\n+    CATCH: {\n+\n+\t# catch\n+\tmy $catch;\n+\tif(defined($catch = $clauses->{'catch'})) {\n+\t    my $i = 0;\n+\n+\t    CATCHLOOP:\n+\t    for( ; $i < @$catch ; $i += 2) {\n+\t\tmy $pkg = $catch->[$i];\n+\t\tunless(defined $pkg) {\n+\t\t    #except\n+\t\t    splice(@$catch,$i,2,$catch->[$i+1]->());\n+\t\t    $i -= 2;\n+\t\t    next CATCHLOOP;\n+\t\t}\n+\t\telsif(Scalar::Util::blessed($err) && $err->isa($pkg)) {\n+\t\t    $code = $catch->[$i+1];\n+\t\t    while(1) {\n+\t\t\tmy $more = 0;\n+\t\t\tlocal($Error::THROWN);\n+\t\t\tmy $ok = eval {\n+\t\t\t    if($wantarray) {\n+\t\t\t\t@{$result} = $code->($err,\\$more);\n+\t\t\t    }\n+\t\t\t    elsif(defined($wantarray)) {\n+\t\t\t        @{$result} = ();\n+\t\t\t\t$result->[0] = $code->($err,\\$more);\n+\t\t\t    }\n+\t\t\t    else {\n+\t\t\t\t$code->($err,\\$more);\n+\t\t\t    }\n+\t\t\t    1;\n+\t\t\t};\n+\t\t\tif( $ok ) {\n+\t\t\t    next CATCHLOOP if $more;\n+\t\t\t    undef $err;\n+\t\t\t}\n+\t\t\telse {\n+\t\t\t    $err = defined($Error::THROWN)\n+\t\t\t\t    ? $Error::THROWN : $@;\n+                $err = $Error::ObjectifyCallback->({'text' =>$err})\n+                    unless ref($err);\n+\t\t\t}\n+\t\t\tlast CATCH;\n+\t\t    };\n+\t\t}\n+\t    }\n+\t}\n+\n+\t# otherwise\n+\tmy $owise;\n+\tif(defined($owise = $clauses->{'otherwise'})) {\n+\t    my $code = $clauses->{'otherwise'};\n+\t    my $more = 0;\n+\t    my $ok = eval {\n+\t\tif($wantarray) {\n+\t\t    @{$result} = $code->($err,\\$more);\n+\t\t}\n+\t\telsif(defined($wantarray)) {\n+\t\t    @{$result} = ();\n+\t\t    $result->[0] = $code->($err,\\$more);\n+\t\t}\n+\t\telse {\n+\t\t    $code->($err,\\$more);\n+\t\t}\n+\t\t1;\n+\t    };\n+\t    if( $ok ) {\n+\t\tundef $err;\n+\t    }\n+\t    else {\n+\t\t$err = defined($Error::THROWN)\n+\t\t\t? $Error::THROWN : $@;\n+            \n+        $err = $Error::ObjectifyCallback->({'text' =>$err}) \n+            unless ref($err);\n+\t    }\n+\t}\n+    }\n+    $err;\n+}\n+\n+sub try (&;$) {\n+    my $try = shift;\n+    my $clauses = @_ ? shift : {};\n+    my $ok = 0;\n+    my $err = undef;\n+    my @result = ();\n+\n+    unshift @Error::STACK, $clauses;\n+\n+    my $wantarray = wantarray();\n+\n+    do {\n+\tlocal $Error::THROWN = undef;\n+    local $@ = undef;\n+\n+\t$ok = eval {\n+\t    if($wantarray) {\n+\t\t@result = $try->();\n+\t    }\n+\t    elsif(defined $wantarray) {\n+\t\t$result[0] = $try->();\n+\t    }\n+\t    else {\n+\t\t$try->();\n+\t    }\n+\t    1;\n+\t};\n+\n+\t$err = defined($Error::THROWN) ? $Error::THROWN : $@\n+\t    unless $ok;\n+    };\n+\n+    shift @Error::STACK;\n+\n+    $err = run_clauses($clauses,$err,wantarray,@result)\n+\tunless($ok);\n+\n+    $clauses->{'finally'}->()\n+\tif(defined($clauses->{'finally'}));\n+\n+    if (defined($err))\n+    {\n+        if (Scalar::Util::blessed($err) && $err->can('throw'))\n+        {\n+            throw $err;\n+        }\n+        else\n+        {\n+            die $err;\n+        }\n+    }\n+\n+    wantarray ? @result : $result[0];\n+}\n+\n+# Each clause adds a sub to the list of clauses. The finally clause is\n+# always the last, and the otherwise clause is always added just before\n+# the finally clause.\n+#\n+# All clauses, except the finally clause, add a sub which takes one argument\n+# this argument will be the error being thrown. The sub will return a code ref\n+# if that clause can handle that error, otherwise undef is returned.\n+#\n+# The otherwise clause adds a sub which unconditionally returns the users\n+# code reference, this is why it is forced to be last.\n+#\n+# The catch clause is defined in Error.pm, as the syntax causes it to\n+# be called as a method\n+\n+sub with (&;$) {\n+    @_\n+}\n+\n+sub finally (&) {\n+    my $code = shift;\n+    my $clauses = { 'finally' => $code };\n+    $clauses;\n+}\n+\n+# The except clause is a block which returns a hashref or a list of\n+# key-value pairs, where the keys are the classes and the values are subs.\n+\n+sub except (&;$) {\n+    my $code = shift;\n+    my $clauses = shift || {};\n+    my $catch = $clauses->{'catch'} ||= [];\n+    \n+    my $sub = sub {\n+\tmy $ref;\n+\tmy(@array) = $code->($_[0]);\n+\tif(@array == 1 && ref($array[0])) {\n+\t    $ref = $array[0];\n+\t    $ref = [ %$ref ]\n+\t\tif(UNIVERSAL::isa($ref,'HASH'));\n+\t}\n+\telse {\n+\t    $ref = \\@array;\n+\t}\n+\t@$ref\n+    };\n+\n+    unshift @{$catch}, undef, $sub;\n+\n+    $clauses;\n+}\n+\n+sub otherwise (&;$) {\n+    my $code = shift;\n+    my $clauses = shift || {};\n+\n+    if(exists $clauses->{'otherwise'}) {\n+\trequire Carp;\n+\tCarp::croak(\"Multiple otherwise clauses\");\n+    }\n+\n+    $clauses->{'otherwise'} = $code;\n+\n+    $clauses;\n+}\n+\n+1;\n+__END__\n+\n+=head1 NAME\n+\n+Error - Error/exception handling in an OO-ish way\n+\n+=head1 SYNOPSIS\n+\n+    use Error qw(:try);\n+\n+    throw Error::Simple( \"A simple error\");\n+\n+    sub xyz {\n+        ...\n+\trecord Error::Simple(\"A simple error\")\n+\t    and return;\n+    }\n+ \n+    unlink($file) or throw Error::Simple(\"$file: $!\",$!);\n+\n+    try {\n+\tdo_some_stuff();\n+\tdie \"error!\" if $condition;\n+\tthrow Error::Simple -text => \"Oops!\" if $other_condition;\n+    }\n+    catch Error::IO with {\n+\tmy $E = shift;\n+\tprint STDERR \"File \", $E->{'-file'}, \" had a problem\\n\";\n+    }\n+    except {\n+\tmy $E = shift;\n+\tmy $general_handler=sub {send_message $E->{-description}};\n+\treturn {\n+\t    UserException1 => $general_handler,\n+\t    UserException2 => $general_handler\n+\t};\n+    }\n+    otherwise {\n+\tprint STDERR \"Well I don't know what to say\\n\";\n+    }\n+    finally {\n+\tclose_the_garage_door_already(); # Should be reliable\n+    }; # Don't forget the trailing ; or you might be surprised\n+\n+=head1 DESCRIPTION\n+\n+The C<Error> package provides two interfaces. Firstly C<Error> provides\n+a procedural interface to exception handling. Secondly C<Error> is a\n+base class for errors/exceptions that can either be thrown, for\n+subsequent catch, or can simply be recorded.\n+\n+Errors in the class C<Error> should not be thrown directly, but the\n+user should throw errors from a sub-class of C<Error>.\n+\n+=head1 PROCEDURAL INTERFACE\n+\n+C<Error> exports subroutines to perform exception handling. These will\n+be exported if the C<:try> tag is used in the C<use> line.\n+\n+=over 4\n+\n+=item try BLOCK CLAUSES\n+\n+C<try> is the main subroutine called by the user. All other subroutines\n+exported are clauses to the try subroutine.\n+\n+The BLOCK will be evaluated and, if no error is throw, try will return\n+the result of the block.\n+\n+C<CLAUSES> are the subroutines below, which describe what to do in the\n+event of an error being thrown within BLOCK.\n+\n+=item catch CLASS with BLOCK\n+\n+This clauses will cause all errors that satisfy C<$err-E<gt>isa(CLASS)>\n+to be caught and handled by evaluating C<BLOCK>.\n+\n+C<BLOCK> will be passed two arguments. The first will be the error\n+being thrown. The second is a reference to a scalar variable. If this\n+variable is set by the catch block then, on return from the catch\n+block, try will continue processing as if the catch block was never\n+found.\n+\n+To propagate the error the catch block may call C<$err-E<gt>throw>\n+\n+If the scalar reference by the second argument is not set, and the\n+error is not thrown. Then the current try block will return with the\n+result from the catch block.\n+\n+=item except BLOCK\n+\n+When C<try> is looking for a handler, if an except clause is found\n+C<BLOCK> is evaluated. The return value from this block should be a\n+HASHREF or a list of key-value pairs, where the keys are class names\n+and the values are CODE references for the handler of errors of that\n+type.\n+\n+=item otherwise BLOCK\n+\n+Catch any error by executing the code in C<BLOCK>\n+\n+When evaluated C<BLOCK> will be passed one argument, which will be the\n+error being processed.\n+\n+Only one otherwise block may be specified per try block\n+\n+=item finally BLOCK\n+\n+Execute the code in C<BLOCK> either after the code in the try block has\n+successfully completed, or if the try block throws an error then\n+C<BLOCK> will be executed after the handler has completed.\n+\n+If the handler throws an error then the error will be caught, the\n+finally block will be executed and the error will be re-thrown.\n+\n+Only one finally block may be specified per try block\n+\n+=back\n+\n+=head1 CLASS INTERFACE\n+\n+=head2 CONSTRUCTORS\n+\n+The C<Error> object is implemented as a HASH. This HASH is initialized\n+with the arguments that are passed to it's constructor. The elements\n+that are used by, or are retrievable by the C<Error> class are listed\n+below, other classes may add to these.\n+\n+\t-file\n+\t-line\n+\t-text\n+\t-value\n+\t-object\n+\n+If C<-file> or C<-line> are not specified in the constructor arguments\n+then these will be initialized with the file name and line number where\n+the constructor was called from.\n+\n+If the error is associated with an object then the object should be\n+passed as the C<-object> argument. This will allow the C<Error> package\n+to associate the error with the object.\n+\n+The C<Error> package remembers the last error created, and also the\n+last error associated with a package. This could either be the last\n+error created by a sub in that package, or the last error which passed\n+an object blessed into that package as the C<-object> argument.\n+\n+=over 4\n+\n+=item throw ( [ ARGS ] )\n+\n+Create a new C<Error> object and throw an error, which will be caught\n+by a surrounding C<try> block, if there is one. Otherwise it will cause\n+the program to exit.\n+\n+C<throw> may also be called on an existing error to re-throw it.\n+\n+=item with ( [ ARGS ] )\n+\n+Create a new C<Error> object and returns it. This is defined for\n+syntactic sugar, eg\n+\n+    die with Some::Error ( ... );\n+\n+=item record ( [ ARGS ] )\n+\n+Create a new C<Error> object and returns it. This is defined for\n+syntactic sugar, eg\n+\n+    record Some::Error ( ... )\n+\tand return;\n+\n+=back\n+\n+=head2 STATIC METHODS\n+\n+=over 4\n+\n+=item prior ( [ PACKAGE ] )\n+\n+Return the last error created, or the last error associated with\n+C<PACKAGE>\n+\n+=item flush ( [ PACKAGE ] )\n+\n+Flush the last error created, or the last error associated with\n+C<PACKAGE>.It is necessary to clear the error stack before exiting the\n+package or uncaught errors generated using C<record> will be reported.\n+\n+     $Error->flush;\n+\n+=cut\n+\n+=back\n+\n+=head2 OBJECT METHODS\n+\n+=over 4\n+\n+=item stacktrace\n+\n+If the variable C<$Error::Debug> was non-zero when the error was\n+created, then C<stacktrace> returns a string created by calling\n+C<Carp::longmess>. If the variable was zero the C<stacktrace> returns\n+the text of the error appended with the filename and line number of\n+where the error was created, providing the text does not end with a\n+newline.\n+\n+=item object\n+\n+The object this error was associated with\n+\n+=item file\n+\n+The file where the constructor of this error was called from\n+\n+=item line\n+\n+The line where the constructor of this error was called from\n+\n+=item text\n+\n+The text of the error\n+\n+=back\n+\n+=head2 OVERLOAD METHODS\n+\n+=over 4\n+\n+=item stringify\n+\n+A method that converts the object into a string. This method may simply\n+return the same as the C<text> method, or it may append more\n+information. For example the file name and line number.\n+\n+By default this method returns the C<-text> argument that was passed to\n+the constructor, or the string C<\"Died\"> if none was given.\n+\n+=item value\n+\n+A method that will return a value that can be associated with the\n+error. For example if an error was created due to the failure of a\n+system call, then this may return the numeric value of C<$!> at the\n+time.\n+\n+By default this method returns the C<-value> argument that was passed\n+to the constructor.\n+\n+=back\n+\n+=head1 PRE-DEFINED ERROR CLASSES\n+\n+=over 4\n+\n+=item Error::Simple\n+\n+This class can be used to hold simple error strings and values. It's\n+constructor takes two arguments. The first is a text value, the second\n+is a numeric value. These values are what will be returned by the\n+overload methods.\n+\n+If the text value ends with C<at file line 1> as $@ strings do, then\n+this infomation will be used to set the C<-file> and C<-line> arguments\n+of the error object.\n+\n+This class is used internally if an eval'd block die's with an error\n+that is a plain string. (Unless C<$Error::ObjectifyCallback> is modified)\n+\n+=back\n+\n+=head1 $Error::ObjectifyCallback\n+\n+This variable holds a reference to a subroutine that converts errors that\n+are plain strings to objects. It is used by Error.pm to convert textual\n+errors to objects, and can be overrided by the user.\n+\n+It accepts a single argument which is a hash reference to named parameters. \n+Currently the only named parameter passed is C<'text'> which is the text\n+of the error, but others may be available in the future.\n+\n+For example the following code will cause Error.pm to throw objects of the\n+class MyError::Bar by default:\n+\n+    sub throw_MyError_Bar\n+    {\n+        my $args = shift;\n+        my $err = MyError::Bar->new();\n+        $err->{'MyBarText'} = $args->{'text'};\n+        return $err;\n+    }\n+\n+    {\n+        local $Error::ObjectifyCallback = \\&throw_MyError_Bar;\n+\n+        # Error handling here.\n+    }\n+\n+=head1 KNOWN BUGS\n+\n+None, but that does not mean there are not any.\n+\n+=head1 AUTHORS\n+\n+Graham Barr <gbarr@pobox.com>\n+\n+The code that inspired me to write this was originally written by\n+Peter Seibel <peter@weblogic.com> and adapted by Jesse Glick\n+<jglick@sig.bsh.com>.\n+\n+=head1 MAINTAINER\n+\n+Shlomi Fish <shlomif@iglu.org.il>\n+\n+=head1 PAST MAINTAINERS\n+\n+Arun Kumar U <u_arunkumar@yahoo.com>\n+\n+=cut\ndiff --git a/perl/Makefile.PL b/perl/Makefile.PL\nindex dd61056..54e8b20 100644\n--- a/perl/Makefile.PL\n+++ b/perl/Makefile.PL\n@@ -8,9 +8,19 @@ instlibdir:\n MAKE_FRAG\n }\n \n+my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');\n+\n+# We come with our own bundled Error.pm. It's not in the set of default\n+# Perl modules so install it if it's not available on the system yet.\n+eval { require 'Error' };\n+if ($@) {\n+\t$pm{'Error.pm'} = '$(INST_LIBDIR)/Error.pm';\n+}\n+\n WriteMakefile(\n \tNAME            => 'Git',\n \tVERSION_FROM    => 'Git.pm',\n+\tPM\t\t=> \\%pm,\n \tMYEXTLIB        => '../libgit.a',\n \tINC             => '-I. -I..',\n );\n"},{"id":"22406","messageId":"20060624023442.32751.28342.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 07/12] Git.pm: Better error handling","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:42Z","receivedAt":"2006-06-24T02:34:42Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"So far, errors just killed the whole program and in case of an error\ninside of libgit it would be totally uncatchable. This patch makes\nGit.pm throw standard Perl exceptions instead. In the future we might\nsubclass Error to Git::Error or something but for now Error::Simple\nis more than enough.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |   37 +++++++++++++++++++++----------------\n perl/Git.xs |   39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 60 insertions(+), 16 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex dcd769b..733fec9 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -88,7 +88,8 @@ increate nonwithstanding).\n =cut\n \n \n-use Carp qw(carp croak);\n+use Carp qw(carp); # croak is bad - throw instead\n+use Error qw(:try);\n \n require XSLoader;\n XSLoader::load('Git', $VERSION);\n@@ -143,14 +144,14 @@ sub repository {\n \tif (defined $args[0]) {\n \t\tif ($#args % 2 != 1) {\n \t\t\t# Not a hash.\n-\t\t\t$#args == 0 or croak \"bad usage\";\n-\t\t\t%opts = (Directory => $args[0]);\n+\t\t\t$#args == 0 or throw Error::Simple(\"bad usage\");\n+\t\t\t%opts = ( Directory => $args[0] );\n \t\t} else {\n \t\t\t%opts = @args;\n \t\t}\n \n \t\tif ($opts{Directory}) {\n-\t\t\t-d $opts{Directory} or croak \"Directory not found: $!\";\n+\t\t\t-d $opts{Directory} or throw Error::Simple(\"Directory not found: $!\");\n \t\t\tif (-d $opts{Directory}.\"/.git\") {\n \t\t\t\t# TODO: Might make this more clever\n \t\t\t\t$opts{WorkingCopy} = $opts{Directory};\n@@ -242,11 +243,11 @@ read.\n sub command_pipe {\n \tmy ($self, $cmd, @args) = _maybe_self(@_);\n \n-\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or croak \"bad command: $cmd\";\n+\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple(\"bad command: $cmd\");\n \n \tmy $pid = open(my $fh, \"-|\");\n \tif (not defined $pid) {\n-\t\tcroak \"open failed: $!\";\n+\t\tthrow Error::Simple(\"open failed: $!\");\n \t} elsif ($pid == 0) {\n \t\t_cmd_exec($self, $cmd, @args);\n \t}\n@@ -271,16 +272,17 @@ The function returns only after the comm\n sub command_noisy {\n \tmy ($self, $cmd, @args) = _maybe_self(@_);\n \n-\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or croak \"bad command: $cmd\";\n+\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple(\"bad command: $cmd\");\n \n \tmy $pid = fork;\n \tif (not defined $pid) {\n-\t\tcroak \"fork failed: $!\";\n+\t\tthrow Error::Simple(\"fork failed: $!\");\n \t} elsif ($pid == 0) {\n \t\t_cmd_exec($self, $cmd, @args);\n \t}\n \tif (waitpid($pid, 0) > 0 and $? != 0) {\n-\t\tcroak \"exit status: $?\";\n+\t\t# This is the best candidate for a custom exception class.\n+\t\tthrow Error::Simple(\"exit status: $?\");\n \t}\n }\n \n@@ -340,10 +342,10 @@ # Implemented in Git.xs.\n \n =back\n \n-=head1 TODO\n+=head1 ERROR HANDLING\n \n-This is still fairly crude.\n-We need some good way to report errors back except just dying.\n+All functions are supposed to throw Perl exceptions in case of errors.\n+See L<Error>.\n \n =head1 COPYRIGHT\n \n@@ -372,8 +374,8 @@ sub _cmd_exec {\n \t\t$self->{opts}->{Repository} and $ENV{'GIT_DIR'} = $self->{opts}->{Repository};\n \t\t$self->{opts}->{WorkingCopy} and chdir($self->{opts}->{WorkingCopy});\n \t}\n-\txs__execv_git_cmd(@args);\n-\tcroak \"exec failed: $!\";\n+\t_execv_git_cmd(@args);\n+\tdie \"exec failed: $!\";\n }\n \n # Execute the given Git command ($_[0]) with arguments ($_[1..])\n@@ -388,7 +390,8 @@ sub _cmd_close {\n \t\t\t# It's just close, no point in fatalities\n \t\t\tcarp \"error closing pipe: $!\";\n \t\t} elsif ($? >> 8) {\n-\t\t\tcroak \"exit status: \".($? >> 8);\n+\t\t\t# This is the best candidate for a custom exception class.\n+\t\t\tthrow Error::Simple(\"exit status: \".($? >> 8));\n \t\t}\n \t\t# else we might e.g. closed a live stream; the command\n \t\t# dying of SIGPIPE would drive us here.\n@@ -415,6 +418,8 @@ sub _call_gate {\n \t\t#xs_call_gate($self->{opts}->{Repository});\n \t}\n \n+\t# Having to call throw from the C code is a sure path to insanity.\n+\tlocal $SIG{__DIE__} = sub { throw Error::Simple(\"@_\"); };\n \t&$xsfunc(@args);\n }\n \n@@ -422,7 +427,7 @@ sub AUTOLOAD {\n \tmy $xsname;\n \tour $AUTOLOAD;\n \t($xsname = $AUTOLOAD) =~ s/.*:://;\n-\tcroak \"&Git::$xsname not defined\" if $xsname =~ /^xs_/;\n+\tthrow Error::Simple(\"&Git::$xsname not defined\") if $xsname =~ /^xs_/;\n \t$xsname = 'xs_'.$xsname;\n \t_call_gate(\\&$xsname, @_);\n }\ndiff --git a/perl/Git.xs b/perl/Git.xs\nindex 9623fdd..ebaac4b 100644\n--- a/perl/Git.xs\n+++ b/perl/Git.xs\n@@ -8,6 +8,8 @@ #include <ctype.h>\n #include \"../cache.h\"\n #include \"../exec_cmd.h\"\n \n+#define die perlyshadow_die__\n+\n /* XS and Perl interface */\n #include \"EXTERN.h\"\n #include \"perl.h\"\n@@ -15,11 +17,48 @@ #include \"XSUB.h\"\n \n #include \"ppport.h\"\n \n+#undef die\n+\n+\n+static char *\n+report_xs(const char *prefix, const char *err, va_list params)\n+{\n+\tstatic char buf[4096];\n+\tstrcpy(buf, prefix);\n+\tvsnprintf(buf + strlen(prefix), 4096 - strlen(prefix), err, params);\n+\treturn buf;\n+}\n+\n+void\n+die_xs(const char *err, va_list params)\n+{\n+\tchar *str;\n+\tstr = report_xs(\"fatal: \", err, params);\n+\tcroak(str);\n+}\n+\n+int\n+error_xs(const char *err, va_list params)\n+{\n+\tchar *str;\n+\tstr = report_xs(\"error: \", err, params);\n+\twarn(str);\n+\treturn -1;\n+}\n+\n \n MODULE = Git\t\tPACKAGE = Git\t\t\n \n PROTOTYPES: DISABLE\n \n+\n+BOOT:\n+{\n+\tset_error_routine(error_xs);\n+\tset_die_routine(die_xs);\n+}\n+\n+\n # /* TODO: xs_call_gate(). See Git.pm. */\n \n \n"},{"id":"22410","messageId":"20060624023444.32751.77423.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 08/12] Git.pm: Handle failed commands' output","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:44Z","receivedAt":"2006-06-24T02:34:44Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Currently if an external command returns error exit code, a generic exception\nis thrown and there is no chance for the caller to retrieve the command's\noutput.\n\nThis patch introduces a Git::Error::Command exception class which is thrown\nin this case and contains both the error code and the captured command output.\nYou can use the new git_cmd_try statement to fatally catch the exception\nwhile producing a user-friendly message.\n\nIt also adds command_close_pipe() for easier checking of exit status of\na command we have just a pipe handle of. It has partial forward dependency\non the next patch, but basically only in the area of documentation.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n git-fmt-merge-msg.perl |   13 +++\n perl/Git.pm            |  192 +++++++++++++++++++++++++++++++++++++++++++-----\n 2 files changed, 183 insertions(+), 22 deletions(-)\n\ndiff --git a/git-fmt-merge-msg.perl b/git-fmt-merge-msg.perl\nindex be2a48c..f86231e 100755\n--- a/git-fmt-merge-msg.perl\n+++ b/git-fmt-merge-msg.perl\n@@ -7,6 +7,7 @@ # by grouping branches and tags together\n \n use strict;\n use Git;\n+use Error qw(:try);\n \n my $repo = Git->repository();\n \n@@ -31,7 +32,17 @@ sub andjoin {\n }\n \n sub repoconfig {\n-\tmy ($val) = $repo->command_oneline('repo-config', '--get', 'merge.summary');\n+\tmy $val;\n+\ttry {\n+\t\t$val = $repo->command_oneline('repo-config', '--get', 'merge.summary');\n+\t} catch Git::Error::Command with {\n+\t\tmy ($E) = shift;\n+\t\tif ($E->value() == 1) {\n+\t\t\treturn undef;\n+\t\t} else {\n+\t\t\tthrow $E;\n+\t\t}\n+\t};\n \treturn $val;\n }\n \ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 733fec9..4205ac5 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -24,16 +24,17 @@ # Totally unstable API.\n \n   my $version = Git::command_oneline('version');\n \n-  Git::command_noisy('update-server-info');\n+  git_cmd_try { Git::command_noisy('update-server-info') }\n+              '%s failed w/ code %d';\n \n   my $repo = Git->repository (Directory => '/srv/git/cogito.git');\n \n \n   my @revs = $repo->command('rev-list', '--since=last monday', '--all');\n \n-  my $fh = $repo->command_pipe('rev-list', '--since=last monday', '--all');\n+  my ($fh, $c) = $repo->command_pipe('rev-list', '--since=last monday', '--all');\n   my $lastrev = <$fh>; chomp $lastrev;\n-  close $fh; # You may want to test rev-list exit status here\n+  $repo->command_close_pipe($fh, $c);\n \n   my $lastrev = $repo->command_oneline('rev-list', '--all');\n \n@@ -44,11 +45,11 @@ require Exporter;\n \n @ISA = qw(Exporter);\n \n-@EXPORT = qw();\n+@EXPORT = qw(git_cmd_try);\n \n # Methods which can be called as standalone functions as well:\n @EXPORT_OK = qw(command command_oneline command_pipe command_noisy\n-                version exec_path hash_object);\n+                version exec_path hash_object git_cmd_try);\n \n \n =head1 DESCRIPTION\n@@ -88,7 +89,7 @@ increate nonwithstanding).\n =cut\n \n \n-use Carp qw(carp); # croak is bad - throw instead\n+use Carp qw(carp croak); # but croak is bad - throw instead\n use Error qw(:try);\n \n require XSLoader;\n@@ -193,21 +194,35 @@ In both cases, the command's stdin and s\n =cut\n \n sub command {\n-\tmy $fh = command_pipe(@_);\n+\tmy ($fh, $ctx) = command_pipe(@_);\n \n \tif (not defined wantarray) {\n-\t\t_cmd_close($fh);\n+\t\t# Nothing to pepper the possible exception with.\n+\t\t_cmd_close($fh, $ctx);\n \n \t} elsif (not wantarray) {\n \t\tlocal $/;\n \t\tmy $text = <$fh>;\n-\t\t_cmd_close($fh);\n+\t\ttry {\n+\t\t\t_cmd_close($fh, $ctx);\n+\t\t} catch Git::Error::Command with {\n+\t\t\t# Pepper with the output:\n+\t\t\tmy $E = shift;\n+\t\t\t$E->{'-outputref'} = \\$text;\n+\t\t\tthrow $E;\n+\t\t};\n \t\treturn $text;\n \n \t} else {\n \t\tmy @lines = <$fh>;\n-\t\t_cmd_close($fh);\n \t\tchomp @lines;\n+\t\ttry {\n+\t\t\t_cmd_close($fh, $ctx);\n+\t\t} catch Git::Error::Command with {\n+\t\t\tmy $E = shift;\n+\t\t\t$E->{'-outputref'} = \\@lines;\n+\t\t\tthrow $E;\n+\t\t};\n \t\treturn @lines;\n \t}\n }\n@@ -222,12 +237,18 @@ of the command's standard output.\n =cut\n \n sub command_oneline {\n-\tmy $fh = command_pipe(@_);\n+\tmy ($fh, $ctx) = command_pipe(@_);\n \n \tmy $line = <$fh>;\n-\t_cmd_close($fh);\n-\n \tchomp $line;\n+\ttry {\n+\t\t_cmd_close($fh, $ctx);\n+\t} catch Git::Error::Command with {\n+\t\t# Pepper with the output:\n+\t\tmy $E = shift;\n+\t\t$E->{'-outputref'} = \\$line;\n+\t\tthrow $E;\n+\t};\n \treturn $line;\n }\n \n@@ -251,7 +272,32 @@ sub command_pipe {\n \t} elsif ($pid == 0) {\n \t\t_cmd_exec($self, $cmd, @args);\n \t}\n-\treturn $fh;\n+\treturn wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;\n+}\n+\n+\n+=item command_close_pipe ( PIPE [, CTX ] )\n+\n+Close the C<PIPE> as returned from C<command_pipe()>, checking\n+whether the command finished successfuly. The optional C<CTX> argument\n+is required if you want to see the command name in the error message,\n+and it is the second value returned by C<command_pipe()> when\n+called in array context. The call idiom is:\n+\n+       my ($fh, $ctx) = $r->command_pipe('status');\n+       while (<$fh>) { ... }\n+       $r->command_close_pipe($fh, $ctx);\n+\n+Note that you should not rely on whatever actually is in C<CTX>;\n+currently it is simply the command name but in future the context might\n+have more complicated structure.\n+\n+=cut\n+\n+sub command_close_pipe {\n+\tmy ($self, $fh, $ctx) = _maybe_self(@_);\n+\t$ctx ||= '<unknown>';\n+\t_cmd_close($fh, $ctx);\n }\n \n \n@@ -280,9 +326,8 @@ sub command_noisy {\n \t} elsif ($pid == 0) {\n \t\t_cmd_exec($self, $cmd, @args);\n \t}\n-\tif (waitpid($pid, 0) > 0 and $? != 0) {\n-\t\t# This is the best candidate for a custom exception class.\n-\t\tthrow Error::Simple(\"exit status: $?\");\n+\tif (waitpid($pid, 0) > 0 and $?>>8 != 0) {\n+\t\tthrow Git::Error::Command(join(' ', $cmd, @args), $? >> 8);\n \t}\n }\n \n@@ -340,12 +385,117 @@ are involved.\n # Implemented in Git.xs.\n \n \n+\n =back\n \n =head1 ERROR HANDLING\n \n All functions are supposed to throw Perl exceptions in case of errors.\n-See L<Error>.\n+See the L<Error> module on how to catch those. Most exceptions are mere\n+L<Error::Simple> instances.\n+\n+However, the C<command()>, C<command_oneline()> and C<command_noisy()>\n+functions suite can throw C<Git::Error::Command> exceptions as well: those are\n+thrown when the external command returns an error code and contain the error\n+code as well as access to the captured command's output. The exception class\n+provides the usual C<stringify> and C<value> (command's exit code) methods and\n+in addition also a C<cmd_output> method that returns either an array or a\n+string with the captured command output (depending on the original function\n+call context; C<command_noisy()> returns C<undef>) and $<cmdline> which\n+returns the command and its arguments (but without proper quoting).\n+\n+Note that the C<command_pipe()> function cannot throw this exception since\n+it has no idea whether the command failed or not. You will only find out\n+at the time you C<close> the pipe; if you want to have that automated,\n+use C<command_close_pipe()>, which can throw the exception.\n+\n+=cut\n+\n+{\n+\tpackage Git::Error::Command;\n+\n+\t@Git::Error::Command::ISA = qw(Error);\n+\n+\tsub new {\n+\t\tmy $self = shift;\n+\t\tmy $cmdline = '' . shift;\n+\t\tmy $value = 0 + shift;\n+\t\tmy $outputref = shift;\n+\t\tmy(@args) = ();\n+\n+\t\tlocal $Error::Depth = $Error::Depth + 1;\n+\n+\t\tpush(@args, '-cmdline', $cmdline);\n+\t\tpush(@args, '-value', $value);\n+\t\tpush(@args, '-outputref', $outputref);\n+\n+\t\t$self->SUPER::new(-text => 'command returned error', @args);\n+\t}\n+\n+\tsub stringify {\n+\t\tmy $self = shift;\n+\t\tmy $text = $self->SUPER::stringify;\n+\t\t$self->cmdline() . ': ' . $text . ': ' . $self->value() . \"\\n\";\n+\t}\n+\n+\tsub cmdline {\n+\t\tmy $self = shift;\n+\t\t$self->{'-cmdline'};\n+\t}\n+\n+\tsub cmd_output {\n+\t\tmy $self = shift;\n+\t\tmy $ref = $self->{'-outputref'};\n+\t\tdefined $ref or undef;\n+\t\tif (ref $ref eq 'ARRAY') {\n+\t\t\treturn @$ref;\n+\t\t} else { # SCALAR\n+\t\t\treturn $$ref;\n+\t\t}\n+\t}\n+}\n+\n+=over 4\n+\n+=item git_cmd_try { CODE } ERRMSG\n+\n+This magical statement will automatically catch any C<Git::Error::Command>\n+exceptions thrown by C<CODE> and make your program die with C<ERRMSG>\n+on its lips; the message will have %s substituted for the command line\n+and %d for the exit status. This statement is useful mostly for producing\n+more user-friendly error messages.\n+\n+In case of no exception caught the statement returns C<CODE>'s return value.\n+\n+Note that this is the only auto-exported function.\n+\n+=cut\n+\n+sub git_cmd_try(&$) {\n+\tmy ($code, $errmsg) = @_;\n+\tmy @result;\n+\tmy $err;\n+\tmy $array = wantarray;\n+\ttry {\n+\t\tif ($array) {\n+\t\t\t@result = &$code;\n+\t\t} else {\n+\t\t\t$result[0] = &$code;\n+\t\t}\n+\t} catch Git::Error::Command with {\n+\t\tmy $E = shift;\n+\t\t$err = $errmsg;\n+\t\t$err =~ s/\\%s/$E->cmdline()/ge;\n+\t\t$err =~ s/\\%d/$E->value()/ge;\n+\t\t# We can't croak here since Error.pm would mangle\n+\t\t# that to Error::Simple.\n+\t};\n+\t$err and croak $err;\n+\treturn $array ? @result : $result[0];\n+}\n+\n+\n+=back\n \n =head1 COPYRIGHT\n \n@@ -384,14 +534,14 @@ # _execv_git_cmd(), implemented in Git.x\n \n # Close pipe to a subprocess.\n sub _cmd_close {\n-\tmy ($fh) = @_;\n+\tmy ($fh, $ctx) = @_;\n \tif (not close $fh) {\n \t\tif ($!) {\n \t\t\t# It's just close, no point in fatalities\n \t\t\tcarp \"error closing pipe: $!\";\n \t\t} elsif ($? >> 8) {\n-\t\t\t# This is the best candidate for a custom exception class.\n-\t\t\tthrow Error::Simple(\"exit status: \".($? >> 8));\n+\t\t\t# The caller should pepper this.\n+\t\t\tthrow Git::Error::Command($ctx, $? >> 8);\n \t\t}\n \t\t# else we might e.g. closed a live stream; the command\n \t\t# dying of SIGPIPE would drive us here.\n"},{"id":"22408","messageId":"20060624023447.32751.71482.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 09/12] Git.pm: Enhance the command_pipe() mechanism","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:47Z","receivedAt":"2006-06-24T02:34:47Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Rename command_pipe() to command_output_pipe(), outsource\nthe functionality to _command_common_pipe().\n\nAdd command_input_pipe().\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |   76 +++++++++++++++++++++++++++++++++++++++++------------------\n 1 files changed, 53 insertions(+), 23 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 4205ac5..11ec62d 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -32,7 +32,7 @@ # Totally unstable API.\n \n   my @revs = $repo->command('rev-list', '--since=last monday', '--all');\n \n-  my ($fh, $c) = $repo->command_pipe('rev-list', '--since=last monday', '--all');\n+  my ($fh, $c) = $repo->command_output_pipe('rev-list', '--since=last monday', '--all');\n   my $lastrev = <$fh>; chomp $lastrev;\n   $repo->command_close_pipe($fh, $c);\n \n@@ -48,7 +48,8 @@ require Exporter;\n @EXPORT = qw(git_cmd_try);\n \n # Methods which can be called as standalone functions as well:\n-@EXPORT_OK = qw(command command_oneline command_pipe command_noisy\n+@EXPORT_OK = qw(command command_oneline command_noisy\n+                command_output_pipe command_input_pipe command_close_pipe\n                 version exec_path hash_object git_cmd_try);\n \n \n@@ -194,7 +195,7 @@ In both cases, the command's stdin and s\n =cut\n \n sub command {\n-\tmy ($fh, $ctx) = command_pipe(@_);\n+\tmy ($fh, $ctx) = command_output_pipe(@_);\n \n \tif (not defined wantarray) {\n \t\t# Nothing to pepper the possible exception with.\n@@ -237,7 +238,7 @@ of the command's standard output.\n =cut\n \n sub command_oneline {\n-\tmy ($fh, $ctx) = command_pipe(@_);\n+\tmy ($fh, $ctx) = command_output_pipe(@_);\n \n \tmy $line = <$fh>;\n \tchomp $line;\n@@ -253,40 +254,49 @@ sub command_oneline {\n }\n \n \n-=item command_pipe ( COMMAND [, ARGUMENTS... ] )\n+=item command_output_pipe ( COMMAND [, ARGUMENTS... ] )\n \n Execute the given C<COMMAND> in the same way as command()\n does but return a pipe filehandle from which the command output can be\n read.\n \n+The function can return C<($pipe, $ctx)> in array context.\n+See C<command_close_pipe()> for details.\n+\n =cut\n \n-sub command_pipe {\n-\tmy ($self, $cmd, @args) = _maybe_self(@_);\n+sub command_output_pipe {\n+\t_command_common_pipe('-|', @_);\n+}\n \n-\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple(\"bad command: $cmd\");\n \n-\tmy $pid = open(my $fh, \"-|\");\n-\tif (not defined $pid) {\n-\t\tthrow Error::Simple(\"open failed: $!\");\n-\t} elsif ($pid == 0) {\n-\t\t_cmd_exec($self, $cmd, @args);\n-\t}\n-\treturn wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;\n+=item command_input_pipe ( COMMAND [, ARGUMENTS... ] )\n+\n+Execute the given C<COMMAND> in the same way as command_output_pipe()\n+does but return an input pipe filehandle instead; the command output\n+is not captured.\n+\n+The function can return C<($pipe, $ctx)> in array context.\n+See C<command_close_pipe()> for details.\n+\n+=cut\n+\n+sub command_input_pipe {\n+\t_command_common_pipe('|-', @_);\n }\n \n \n =item command_close_pipe ( PIPE [, CTX ] )\n \n-Close the C<PIPE> as returned from C<command_pipe()>, checking\n+Close the C<PIPE> as returned from C<command_*_pipe()>, checking\n whether the command finished successfuly. The optional C<CTX> argument\n is required if you want to see the command name in the error message,\n-and it is the second value returned by C<command_pipe()> when\n+and it is the second value returned by C<command_*_pipe()> when\n called in array context. The call idiom is:\n \n-       my ($fh, $ctx) = $r->command_pipe('status');\n-       while (<$fh>) { ... }\n-       $r->command_close_pipe($fh, $ctx);\n+\tmy ($fh, $ctx) = $r->command_output_pipe('status');\n+\twhile (<$fh>) { ... }\n+\t$r->command_close_pipe($fh, $ctx);\n \n Note that you should not rely on whatever actually is in C<CTX>;\n currently it is simply the command name but in future the context might\n@@ -317,8 +327,7 @@ The function returns only after the comm\n \n sub command_noisy {\n \tmy ($self, $cmd, @args) = _maybe_self(@_);\n-\n-\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple(\"bad command: $cmd\");\n+\t_check_valid_cmd($cmd);\n \n \tmy $pid = fork;\n \tif (not defined $pid) {\n@@ -404,7 +413,7 @@ string with the captured command output \n call context; C<command_noisy()> returns C<undef>) and $<cmdline> which\n returns the command and its arguments (but without proper quoting).\n \n-Note that the C<command_pipe()> function cannot throw this exception since\n+Note that the C<command_*_pipe()> functions cannot throw this exception since\n it has no idea whether the command failed or not. You will only find out\n at the time you C<close> the pipe; if you want to have that automated,\n use C<command_close_pipe()>, which can throw the exception.\n@@ -516,6 +525,27 @@ sub _maybe_self {\n \tref $_[0] eq 'Git' ? @_ : (undef, @_);\n }\n \n+# Check if the command id is something reasonable.\n+sub _check_valid_cmd {\n+\tmy ($cmd) = @_;\n+\t$cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple(\"bad command: $cmd\");\n+}\n+\n+# Common backend for the pipe creators.\n+sub _command_common_pipe {\n+\tmy $direction = shift;\n+\tmy ($self, $cmd, @args) = _maybe_self(@_);\n+\t_check_valid_cmd($cmd);\n+\n+\tmy $pid = open(my $fh, $direction);\n+\tif (not defined $pid) {\n+\t\tthrow Error::Simple(\"open failed: $!\");\n+\t} elsif ($pid == 0) {\n+\t\t_cmd_exec($self, $cmd, @args);\n+\t}\n+\treturn wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;\n+}\n+\n # When already in the subprocess, set up the appropriate state\n # for the given repository and execute the git command.\n sub _cmd_exec {\n"},{"id":"22407","messageId":"20060624023449.32751.90490.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 10/12] Git.pm: Implement options for the command interface","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:49Z","receivedAt":"2006-06-24T02:34:49Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This gives the user a way to easily pass options to the command routines.\nCurrently only the STDERR option is implemented and can be used to adjust\nwhat shall be done with error output of the called command (most usefully,\nit can be used to silence it).\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |   37 +++++++++++++++++++++++++++++++++++--\n 1 files changed, 35 insertions(+), 2 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 11ec62d..e2b66c4 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -36,7 +36,8 @@ # Totally unstable API.\n   my $lastrev = <$fh>; chomp $lastrev;\n   $repo->command_close_pipe($fh, $c);\n \n-  my $lastrev = $repo->command_oneline('rev-list', '--all');\n+  my $lastrev = $repo->command_oneline( [ 'rev-list', '--all' ],\n+                                        STDERR => 0 );\n \n =cut\n \n@@ -178,9 +179,21 @@ sub repository {\n \n =item command ( COMMAND [, ARGUMENTS... ] )\n \n+=item command ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } )\n+\n Execute the given Git C<COMMAND> (specify it without the 'git-'\n prefix), optionally with the specified extra C<ARGUMENTS>.\n \n+The second more elaborate form can be used if you want to further adjust\n+the command execution. Currently, only one option is supported:\n+\n+B<STDERR> - How to deal with the command's error output. By default (C<undef>)\n+it is delivered to the caller's C<STDERR>. A false value (0 or '') will cause\n+it to be thrown away. If you want to process it, you can get it in a filehandle\n+you specify, but you must be extremely careful; if the error output is not\n+very short and you want to read it in the same process as where you called\n+C<command()>, you are set up for a nice deadlock!\n+\n The method can be called without any instance or on a specified Git repository\n (in that case the command will be run in the repository context).\n \n@@ -231,6 +244,8 @@ sub command {\n \n =item command_oneline ( COMMAND [, ARGUMENTS... ] )\n \n+=item command_oneline ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } )\n+\n Execute the given C<COMMAND> in the same way as command()\n does but always return a scalar string containing the first line\n of the command's standard output.\n@@ -256,6 +271,8 @@ sub command_oneline {\n \n =item command_output_pipe ( COMMAND [, ARGUMENTS... ] )\n \n+=item command_output_pipe ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } )\n+\n Execute the given C<COMMAND> in the same way as command()\n does but return a pipe filehandle from which the command output can be\n read.\n@@ -272,6 +289,8 @@ sub command_output_pipe {\n \n =item command_input_pipe ( COMMAND [, ARGUMENTS... ] )\n \n+=item command_input_pipe ( [ COMMAND, ARGUMENTS... ], { Opt => Val ... } )\n+\n Execute the given C<COMMAND> in the same way as command_output_pipe()\n does but return an input pipe filehandle instead; the command output\n is not captured.\n@@ -534,13 +553,27 @@ sub _check_valid_cmd {\n # Common backend for the pipe creators.\n sub _command_common_pipe {\n \tmy $direction = shift;\n-\tmy ($self, $cmd, @args) = _maybe_self(@_);\n+\tmy ($self, @p) = _maybe_self(@_);\n+\tmy (%opts, $cmd, @args);\n+\tif (ref $p[0]) {\n+\t\t($cmd, @args) = @{shift @p};\n+\t\t%opts = ref $p[0] ? %{$p[0]} : @p;\n+\t} else {\n+\t\t($cmd, @args) = @p;\n+\t}\n \t_check_valid_cmd($cmd);\n \n \tmy $pid = open(my $fh, $direction);\n \tif (not defined $pid) {\n \t\tthrow Error::Simple(\"open failed: $!\");\n \t} elsif ($pid == 0) {\n+\t\tif (defined $opts{STDERR}) {\n+\t\t\tclose STDERR;\n+\t\t}\n+\t\tif ($opts{STDERR}) {\n+\t\t\topen (STDERR, '>&', $opts{STDERR})\n+\t\t\t\tor die \"dup failed: $!\";\n+\t\t}\n \t\t_cmd_exec($self, $cmd, @args);\n \t}\n \treturn wantarray ? ($fh, join(' ', $cmd, @args)) : $fh;\n"},{"id":"22409","messageId":"20060624023451.32751.16021.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 11/12] Git.pm: Add support for subdirectories inside of working copies","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:51Z","receivedAt":"2006-06-24T02:34:51Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This patch adds support for subdirectories inside of working copies;\nyou can specify them in the constructor either as the Directory\noption (it will just get autodetected using rev-parse) or explicitly\nusing the WorkingSubdir option. This makes Git->repository() do the\nexact same path setup and repository lookup as the Git porcelain\ndoes.\n\nThis patch also introduces repo_path(), wc_path() and wc_subdir()\naccessor methods and wc_chdir() mutator.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |  157 ++++++++++++++++++++++++++++++++++++++++++++++++-----------\n 1 files changed, 129 insertions(+), 28 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex e2b66c4..7bbb5be 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -69,20 +69,18 @@ (In the future, we will also get a new_r\n called as methods of the object are then executed in the context of the\n repository.\n \n-TODO: In the future, we might also do\n+Part of the \"repository state\" is also information about path to the attached\n+working copy (unless you work with a bare repository). You can also navigate\n+inside of the working copy using the C<wc_chdir()> method. (Note that\n+the repository object is self-contained and will not change working directory\n+of your process.)\n \n-\tmy $subdir = $repo->subdir('Documentation');\n-\t# Gets called in the subdirectory context:\n-\t$subdir->command('status');\n+TODO: In the future, we might also do\n \n \tmy $remoterepo = $repo->remote_repository (Name => 'cogito', Branch => 'master');\n \t$remoterepo ||= Git->remote_repository ('http://git.or.cz/cogito.git/');\n \tmy @refs = $remoterepo->refs();\n \n-So far, all functions just die if anything goes wrong. If you don't want that,\n-make appropriate provisions to catch the possible deaths. Better error recovery\n-mechanisms will be provided in the future.\n-\n Currently, the module merely wraps calls to external Git tools. In the future,\n it will provide a much faster way to interact with Git by linking directly\n to libgit. This should be completely opaque to the user, though (performance\n@@ -93,6 +91,7 @@ increate nonwithstanding).\n \n use Carp qw(carp croak); # but croak is bad - throw instead\n use Error qw(:try);\n+use Cwd qw(abs_path);\n \n require XSLoader;\n XSLoader::load('Git', $VERSION);\n@@ -119,12 +118,17 @@ B<Repository> - Path to the Git reposito\n B<WorkingCopy> - Path to the associated working copy; not strictly required\n as many commands will happily crunch on a bare repository.\n \n-B<Directory> - Path to the Git working directory in its usual setup. This\n-is just for convenient setting of both C<Repository> and C<WorkingCopy>\n-at once: If the directory as a C<.git> subdirectory, C<Repository> is pointed\n-to the subdirectory and the directory is assumed to be the working copy.\n-If the directory does not have the subdirectory, C<WorkingCopy> is left\n-undefined and C<Repository> is pointed to the directory itself.\n+B<WorkingSubdir> - Subdirectory in the working copy to work inside.\n+Just left undefined if you do not want to limit the scope of operations.\n+\n+B<Directory> - Path to the Git working directory in its usual setup.\n+The C<.git> directory is searched in the directory and all the parent\n+directories; if found, C<WorkingCopy> is set to the directory containing\n+it and C<Repository> to the C<.git> directory itself. If no C<.git>\n+directory was found, the C<Directory> is assumed to be a bare repository,\n+C<Repository> is set to point at it and C<WorkingCopy> is left undefined.\n+If the C<$GIT_DIR> environment variable is set, things behave as expected\n+as well.\n \n You should not use both C<Directory> and either of C<Repository> and\n C<WorkingCopy> - the results of that are undefined.\n@@ -134,7 +138,10 @@ to the constructor; it is equivalent to \n field.\n \n Calling the constructor with no options whatsoever is equivalent to\n-calling it with C<< Directory => '.' >>.\n+calling it with C<< Directory => '.' >>. In general, if you are building\n+a standard porcelain command, simply doing C<< Git->repository() >> should\n+do the right thing and setup the object to reflect exactly where the user\n+is right now.\n \n =cut\n \n@@ -152,18 +159,59 @@ sub repository {\n \t\t} else {\n \t\t\t%opts = @args;\n \t\t}\n+\t}\n+\n+\tif (not defined $opts{Repository} and not defined $opts{WorkingCopy}) {\n+\t\t$opts{Directory} ||= '.';\n+\t}\n+\n+\tif ($opts{Directory}) {\n+\t\t-d $opts{Directory} or throw Error::Simple(\"Directory not found: $!\");\n+\n+\t\tmy $search = Git->repository(WorkingCopy => $opts{Directory});\n+\t\tmy $dir;\n+\t\ttry {\n+\t\t\t$dir = $search->command_oneline(['rev-parse', '--git-dir'],\n+\t\t\t                                STDERR => 0);\n+\t\t} catch Git::Error::Command with {\n+\t\t\t$dir = undef;\n+\t\t};\n \n-\t\tif ($opts{Directory}) {\n-\t\t\t-d $opts{Directory} or throw Error::Simple(\"Directory not found: $!\");\n-\t\t\tif (-d $opts{Directory}.\"/.git\") {\n-\t\t\t\t# TODO: Might make this more clever\n-\t\t\t\t$opts{WorkingCopy} = $opts{Directory};\n-\t\t\t\t$opts{Repository} = $opts{Directory}.\"/.git\";\n-\t\t\t} else {\n-\t\t\t\t$opts{Repository} = $opts{Directory};\n+\t\tif ($dir) {\n+\t\t\t$opts{Repository} = abs_path($dir);\n+\n+\t\t\t# If --git-dir went ok, this shouldn't die either.\n+\t\t\tmy $prefix = $search->command_oneline('rev-parse', '--show-prefix');\n+\t\t\t$dir = abs_path($opts{Directory}) . '/';\n+\t\t\tif ($prefix) {\n+\t\t\t\tif (substr($dir, -length($prefix)) ne $prefix) {\n+\t\t\t\t\tthrow Error::Simple(\"rev-parse confused me - $dir does not have trailing $prefix\");\n+\t\t\t\t}\n+\t\t\t\tsubstr($dir, -length($prefix)) = '';\n \t\t\t}\n-\t\t\tdelete $opts{Directory};\n+\t\t\t$opts{WorkingCopy} = $dir;\n+\t\t\t$opts{WorkingSubdir} = $prefix;\n+\n+\t\t} else {\n+\t\t\t# A bare repository? Let's see...\n+\t\t\t$dir = $opts{Directory};\n+\n+\t\t\tunless (-d \"$dir/refs\" and -d \"$dir/objects\" and -e \"$dir/HEAD\") {\n+\t\t\t\t# Mimick git-rev-parse --git-dir error message:\n+\t\t\t\tthrow Error::Simple('fatal: Not a git repository');\n+\t\t\t}\n+\t\t\tmy $search = Git->repository(Repository => $dir);\n+\t\t\ttry {\n+\t\t\t\t$search->command('symbolic-ref', 'HEAD');\n+\t\t\t} catch Git::Error::Command with {\n+\t\t\t\t# Mimick git-rev-parse --git-dir error message:\n+\t\t\t\tthrow Error::Simple('fatal: Not a git repository');\n+\t\t\t}\n+\n+\t\t\t$opts{Repository} = abs_path($dir);\n \t\t}\n+\n+\t\tdelete $opts{Directory};\n \t}\n \n \t$self = { opts => \\%opts };\n@@ -256,7 +304,7 @@ sub command_oneline {\n \tmy ($fh, $ctx) = command_output_pipe(@_);\n \n \tmy $line = <$fh>;\n-\tchomp $line;\n+\tdefined $line and chomp $line;\n \ttry {\n \t\t_cmd_close($fh, $ctx);\n \t} catch Git::Error::Command with {\n@@ -374,7 +422,7 @@ # Implemented in Git.xs.\n \n =item exec_path ()\n \n-Return path to the git sub-command executables (the same as\n+Return path to the Git sub-command executables (the same as\n C<git --exec-path>). Useful mostly only internally.\n \n Implementation of this function is very fast; no external command calls\n@@ -385,6 +433,58 @@ are involved.\n # Implemented in Git.xs.\n \n \n+=item repo_path ()\n+\n+Return path to the git repository. Must be called on a repository instance.\n+\n+=cut\n+\n+sub repo_path { $_[0]->{opts}->{Repository} }\n+\n+\n+=item wc_path ()\n+\n+Return path to the working copy. Must be called on a repository instance.\n+\n+=cut\n+\n+sub wc_path { $_[0]->{opts}->{WorkingCopy} }\n+\n+\n+=item wc_subdir ()\n+\n+Return path to the subdirectory inside of a working copy. Must be called\n+on a repository instance.\n+\n+=cut\n+\n+sub wc_subdir { $_[0]->{opts}->{WorkingSubdir} ||= '' }\n+\n+\n+=item wc_chdir ( SUBDIR )\n+\n+Change the working copy subdirectory to work within. The C<SUBDIR> is\n+relative to the working copy root directory (not the current subdirectory).\n+Must be called on a repository instance attached to a working copy\n+and the directory must exist.\n+\n+=cut\n+\n+sub wc_chdir {\n+\tmy ($self, $subdir) = @_;\n+\n+\t$self->wc_path()\n+\t\tor throw Error::Simple(\"bare repository\");\n+\n+\t-d $self->wc_path().'/'.$subdir\n+\t\tor throw Error::Simple(\"subdir not found: $!\");\n+\t# Of course we will not \"hold\" the subdirectory so anyone\n+\t# can delete it now and we will never know. But at least we tried.\n+\n+\t$self->{opts}->{WorkingSubdir} = $subdir;\n+}\n+\n+\n =item hash_object ( FILENAME [, TYPE ] )\n \n =item hash_object ( FILEHANDLE [, TYPE ] )\n@@ -584,8 +684,9 @@ # for the given repository and execute t\n sub _cmd_exec {\n \tmy ($self, @args) = @_;\n \tif ($self) {\n-\t\t$self->{opts}->{Repository} and $ENV{'GIT_DIR'} = $self->{opts}->{Repository};\n-\t\t$self->{opts}->{WorkingCopy} and chdir($self->{opts}->{WorkingCopy});\n+\t\t$self->repo_path() and $ENV{'GIT_DIR'} = $self->repo_path();\n+\t\t$self->wc_path() and chdir($self->wc_path());\n+\t\t$self->wc_subdir() and chdir($self->wc_subdir());\n \t}\n \t_execv_git_cmd(@args);\n \tdie \"exec failed: $!\";\n"},{"id":"22411","messageId":"20060624023453.32751.73126.stgit@machine.or.cz","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"[PATCH 12/12] Convert git-mv to use Git.pm","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:34:53Z","receivedAt":"2006-06-24T02:34:53Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Fairly straightforward.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n git-mv.perl |   46 ++++++++++++++++++++++------------------------\n 1 files changed, 22 insertions(+), 24 deletions(-)\n\ndiff --git a/git-mv.perl b/git-mv.perl\nindex 75aa8fe..b9e3537 100755\n--- a/git-mv.perl\n+++ b/git-mv.perl\n@@ -10,6 +10,8 @@ # at the discretion of Linus Torvalds.\n use warnings;\n use strict;\n use Getopt::Std;\n+use Git;\n+use Error qw(:try);\n \n sub usage() {\n \tprint <<EOT;\n@@ -24,9 +26,7 @@ getopts(\"hnfkv\") || usage;\n usage() if $opt_h;\n @ARGV >= 1 or usage;\n \n-my $GIT_DIR = `git rev-parse --git-dir`;\n-exit 1 if $?; # rev-parse would have given \"not a git dir\" message.\n-chomp($GIT_DIR);\n+my $repo = Git->repository();\n \n my (@srcArgs, @dstArgs, @srcs, @dsts);\n my ($src, $dst, $base, $dstDir);\n@@ -62,11 +62,11 @@ else {\n     $dstDir = \"\";\n }\n \n-my $subdir_prefix = `git rev-parse --show-prefix`;\n-chomp($subdir_prefix);\n+my $subdir_prefix = $repo->wc_subdir();\n \n # run in git base directory, so that git-ls-files lists all revisioned files\n-chdir \"$GIT_DIR/..\";\n+chdir $repo->wc_path();\n+$repo->wc_chdir('');\n \n # normalize paths, needed to compare against versioned files and update-index\n # also, this is nicer to end-users by doing \".//a/./b/.//./c\" ==> \"a/b/c\"\n@@ -84,12 +84,10 @@ my (@allfiles,@srcfiles,@dstfiles);\n my $safesrc;\n my (%overwritten, %srcForDst);\n \n-$/ = \"\\0\";\n-open(F, 'git-ls-files -z |')\n-        or die \"Failed to open pipe from git-ls-files: \" . $!;\n-\n-@allfiles = map { chomp; $_; } <F>;\n-close(F);\n+{\n+\tlocal $/ = \"\\0\";\n+\t@allfiles = $repo->command('ls-files', '-z');\n+}\n \n \n my ($i, $bad);\n@@ -219,28 +217,28 @@ if ($opt_n) {\n }\n else {\n     if (@changedfiles) {\n-\topen(H, \"| git-update-index -z --stdin\")\n-\t\tor die \"git-update-index failed to update changed files with code $!\\n\";\n+\tmy ($fd, $ctx) = $repo->command_input_pipe('update-index', '-z', '--stdin');\n \tforeach my $fileName (@changedfiles) {\n-\t\tprint H \"$fileName\\0\";\n+\t\tprint $fd \"$fileName\\0\";\n \t}\n-\tclose(H);\n+\tgit_cmd_try { $repo->command_close_pipe($fd, $ctx); }\n+\t\t'git-update-index failed to update changed files with code %d';\n     }\n     if (@addedfiles) {\n-\topen(H, \"| git-update-index --add -z --stdin\")\n-\t\tor die \"git-update-index failed to add new names with code $!\\n\";\n+\tmy ($fd, $ctx) = $repo->command_input_pipe('update-index', '--add', '-z', '--stdin');\n \tforeach my $fileName (@addedfiles) {\n-\t\tprint H \"$fileName\\0\";\n+\t\tprint $fd \"$fileName\\0\";\n \t}\n-\tclose(H);\n+\tgit_cmd_try { $repo->command_close_pipe($fd, $ctx); }\n+\t\t'git-update-index failed to add new files with code %d';\n     }\n     if (@deletedfiles) {\n-\topen(H, \"| git-update-index --remove -z --stdin\")\n-\t\tor die \"git-update-index failed to remove old names with code $!\\n\";\n+\tmy ($fd, $ctx) = $repo->command_input_pipe('update-index', '--remove', '-z', '--stdin');\n \tforeach my $fileName (@deletedfiles) {\n-\t\tprint H \"$fileName\\0\";\n+\t\tprint $fd \"$fileName\\0\";\n \t}\n-\tclose(H);\n+\tgit_cmd_try { $repo->command_close_pipe($fd, $ctx); }\n+\t\t'git-update-index failed to remove old files with code %d';\n     }\n }\n \n"},{"id":"22412","messageId":"20060624023946.GP21864@pasky.or.cz","threadId":"4646","inReplyTo":"20060624023453.32751.73126.stgit@machine.or.cz","subject":"Re: [PATCH 12/12] Convert git-mv to use Git.pm","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T02:39:46Z","receivedAt":"2006-06-24T02:39:46Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 04:34:53AM CEST, I got a letter\nwhere Petr Baudis <pasky@suse.cz> said that...\n> +use Error qw(:try);\n\nDuh, no matter how long I stare at the patches before submitting them,\nsomething always slips through. This isn't actually necessary anymore\nsince we have git_cmd_try now. (The try { } catch { } blocks turned\nquite fat and ugly.)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22413","messageId":"7vr71f5kzs.fsf@assigned-by-dhcp.cox.net","threadId":"4646","inReplyTo":"20060624023429.32751.80619.stgit@machine.or.cz","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-24T02:46:15Z","receivedAt":"2006-06-24T02:46:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Just to let you know, I already have v3 in my tree which is\nmerged in \"pu\".  With the two fixes I sent you earlier I think\nit is in a good shape to be cooked in \"next\".\n\nI do not think I'd have trouble applying this new series (I\nwould probably start from \"master\" to apply it and perhaps merge\nor --squash merge it onto pb/gitpm topic branch that has v3 with\nthe two fixes I sent you separately) but we will see soon\nenough.\n"},{"id":"22416","messageId":"20060624031436.GQ21864@pasky.or.cz","threadId":"4646","inReplyTo":"7vr71f5kzs.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T03:14:36Z","receivedAt":"2006-06-24T03:14:36Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 04:46:15AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> Just to let you know, I already have v3 in my tree which is\n> merged in \"pu\".  With the two fixes I sent you earlier I think\n> it is in a good shape to be cooked in \"next\".\n\nAh, yes, could you please apply your fixes as well? :-)\n\n> I do not think I'd have trouble applying this new series (I\n> would probably start from \"master\" to apply it and perhaps merge\n> or --squash merge it onto pb/gitpm topic branch that has v3 with\n> the two fixes I sent you separately) but we will see soon\n> enough.\n\nI noticed v3 in pu but thought that it should be trivial to just throw\nthat away from pu and take v4 instead - I'm sorry if that turns out to\nbe an issue.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22426","messageId":"7vu06bymtr.fsf@assigned-by-dhcp.cox.net","threadId":"4646","inReplyTo":"7vr71f5kzs.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-24T08:33:52Z","receivedAt":"2006-06-24T08:33:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Just to let you know, I already have v3 in my tree which is\n> merged in \"pu\".  With the two fixes I sent you earlier I think\n> it is in a good shape to be cooked in \"next\".\n>\n> I do not think I'd have trouble applying this new series (I\n> would probably start from \"master\" to apply it and perhaps merge\n> or --squash merge it onto pb/gitpm topic branch that has v3 with\n> the two fixes I sent you separately) but we will see soon\n> enough.\n\nEEEEEEEEEK.\n\ngit-fmt-merge-msg failed and git-pull did not notice it and went\nahead to call git-merge with an empty log message.  This screwed\nup my tree rather big way.\n\nThe reason it failed?  Well, it could not find Git.pm because\nthe changes to fmt-merge-msg was done for distros not for people\nwho install under their home directories.\n\nNow, I am quite unhappy about the situation (and it is not your\nfault).  \"git pull\" is something almost everybody uses, and\nhaving the series means they would need to make sure whereever\nGit.pm is installed is on their PERL5LIB as things currently\nstand.\n\nIn the case of git-merge-recursive.py, Fredrik does\n\n\tsys.path.append('''@@GIT_PYTHON_PATH@@''')\n\nand while running test this invalid path is overridden by having\nPYTHONPATH environment variable.  Since it is \"append\", the test\npicks up the freshly built version, not the version from the\nprevious install (i.e. PYTHONPATH environment variable wins).\n\nSo you would probably want to have something like\n\n\tuse lib '@@GIT_PERL_PATH@@';\n\ninside git-fmt-merge-msg.perl, which will be turned into\n\n\tuse lib '/home/junio/some/where/you/install/pm';\n\nin git-fmt-merge-msg and things might start working.\n\n... gitster mumbles something in his mouth, and in a puff of\nsmoke Merlyn appears and solves all our Perl problems ;-) ...\n"},{"id":"22427","messageId":"7vmzc3ymnu.fsf@assigned-by-dhcp.cox.net","threadId":"4646","inReplyTo":"20060624023442.32751.28342.stgit@machine.or.cz","subject":"Re: [PATCH 07/12] Git.pm: Better error handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-24T08:37:25Z","receivedAt":"2006-06-24T08:37:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> +int\n> +error_xs(const char *err, va_list params)\n> +{\n\nYou said in git-compat-util.h that set_error_routine takes a\nfunction that returns void, so this gives unnecessary type\nclash.\n\n--------------------------------\nIn file included from /usr/lib/perl/5.8/CORE/perl.h:756,\n                 from Git.xs:15:\n/usr/lib/perl/5.8/CORE/embed.h:4193:1: warning: \"die\" redefined\nGit.xs:11:1: warning: this is the location of the previous definition\nGit.xs: In function 'boot_Git':\nGit.xs:57: warning: passing argument 1 of 'set_error_routine' from incompatible pointer type\nGit.xs:58: warning: passing argument 1 of 'set_die_routine' makes qualified function pointer from unqualified\n--------------------------------\n\nOther troubles I saw with the v4 series while compiling:\n\n--------------------------------\nusage.c:35: warning: initialization makes qualified function pointer from unqualified\nusage.c:36: warning: initialization makes qualified function pointer from unqualified\n\nI'd fix it with this\n\ndiff --git a/usage.c b/usage.c\nindex b781b00..52c2e96 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -12,19 +12,19 @@ static void report(const char *prefix, c\n \tfputs(\"\\n\", stderr);\n }\n \n-void usage_builtin(const char *err)\n+static NORETURN void usage_builtin(const char *err)\n {\n \tfprintf(stderr, \"usage: %s\\n\", err);\n \texit(129);\n }\n \n-void die_builtin(const char *err, va_list params)\n+static NORETURN void die_builtin(const char *err, va_list params)\n {\n \treport(\"fatal: \", err, params);\n \texit(128);\n }\n \n-void error_builtin(const char *err, va_list params)\n+static void error_builtin(const char *err, va_list params)\n {\n \treport(\"error: \", err, params);\n }\n\n--------------------------------\n\n(cd perl && /usr/bin/perl Makefile.PL \\\n                PREFIX=\"/home/junio/git-test\" \\\n                DEFINE=\"-O2 -Wall -Wdeclaration-after-statement\n                -g -DSHA1_HEADER='<openssl/sha.h>'\n                -DGIT_VERSION=\\\\\\\"1.4.1.rc1.gab0df\\\\\\\"\" \\\n                LIBS=\"libgit.a xdiff/lib.a -lz  -lcrypto\")\nUnrecognized argument in LIBS ignored: 'libgit.a'\nUnrecognized argument in LIBS ignored: 'xdiff/lib.a'\n\nDo you need to pass LIBS, and if so maybe this is not a way\nMakefile.PL expects it to be passed perhaps?\n\n--------------------------------\nMakefile out-of-date with respect to Makefile.PL\nCleaning current config before rebuilding Makefile...\nmake -f Makefile.old clean > /dev/null 2>&1\n/usr/bin/perl Makefile.PL \"PREFIX=/home/junio/git-test\" \"DEFINE=-O2 -Wall -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>'  -DGIT_VERSION=\\\"1.4.1.rc1.gab0df\\\"\" \"LIBS=libgit.a xdiff/lib.a -lz  -lcrypto\"\nUnrecognized argument in LIBS ignored: 'libgit.a'\nUnrecognized argument in LIBS ignored: 'xdiff/lib.a'\nWriting Makefile for Git\n==> Your Makefile has been rebuilt. <==\n==> Please rerun the make command.  <==\nfalse\nmake[1]: *** [Makefile] Error 1\n--------------------------------\n\nThe latter is what Perl's build mechanism does so it is not\nstrictly your fault, but it nevertheless is irritating that we\nhave to say make clean twice.\n"},{"id":"22437","messageId":"20060624111657.GR21864@pasky.or.cz","threadId":"4646","inReplyTo":"7vu06bymtr.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T11:16:57Z","receivedAt":"2006-06-24T11:16:57Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 10:33:52AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> The reason it failed?  Well, it could not find Git.pm because\n> the changes to fmt-merge-msg was done for distros not for people\n> who install under their home directories.\n\nI don't understand what are you trying to say here...\n\n> Now, I am quite unhappy about the situation (and it is not your\n> fault).  \"git pull\" is something almost everybody uses, and\n> having the series means they would need to make sure whereever\n> Git.pm is installed is on their PERL5LIB as things currently\n> stand.\n\n...because well, they do:\n\n$(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl\n\trm -f $@ $@+\n\tsed -e '1s|#!.*perl\\(.*\\)|#!$(PERL_PATH_SQ)\\1 -I'\"$$(make -s -C perl instlibdir)\"'|' \\\n\t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n\t    $@.perl >$@+\n\tchmod +x $@+\n\tmv $@+ $@\n\n(This is also why I was a bit confused by your make test patch - it does\nnot \"fix\" anything per se since no tests directly use Git.pm.)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22442","messageId":"20060624115227.GS21864@pasky.or.cz","threadId":"4646","inReplyTo":"20060624111657.GR21864@pasky.or.cz","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T11:52:27Z","receivedAt":"2006-06-24T11:52:27Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 01:16:57PM CEST, I got a letter\nwhere Petr Baudis <pasky@suse.cz> said that...\n> $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl\n> \trm -f $@ $@+\n> \tsed -e '1s|#!.*perl\\(.*\\)|#!$(PERL_PATH_SQ)\\1 -I'\"$$(make -s -C perl instlibdir)\"'|' \\\n> \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n> \t    $@.perl >$@+\n> \tchmod +x $@+\n> \tmv $@+ $@\n> \n> (This is also why I was a bit confused by your make test patch - it does\n> not \"fix\" anything per se since no tests directly use Git.pm.)\n\nAnd this makes the Perl scripts work even without make install:\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n\ndiff --git a/Makefile b/Makefile\nindex 7842195..d614f18 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -509,7 +509,9 @@ common-cmds.h: Documentation/git-*.txt\n \n $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl\n \trm -f $@ $@+\n-\tsed -e '1s|#!.*perl\\(.*\\)|#!$(PERL_PATH_SQ)\\1 -I'\"$$(make -s -C perl instlibdir)\"'|' \\\n+\tsed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \\\n+\t    -e '2i\\\n+\t        use lib qw ('\"$$(make -s -C perl instlibdir)\"' '\"$$(pwd)\"'/perl/blib/lib);' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    $@.perl >$@+\n \tchmod +x $@+\ndiff --git a/perl/Makefile.PL b/perl/Makefile.PL\nindex 54e8b20..2cbd227 100644\n--- a/perl/Makefile.PL\n+++ b/perl/Makefile.PL\n@@ -2,6 +2,9 @@ use ExtUtils::MakeMaker;\n \n sub MY::postamble {\n \treturn <<'MAKE_FRAG';\n+all::\n+\tcp blib/arch/auto/Git/* blib/lib/auto/Git/\n+\n instlibdir:\n \t@echo $(INSTALLSITELIB)\n \n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22443","messageId":"7vac82wytw.fsf@assigned-by-dhcp.cox.net","threadId":"4646","inReplyTo":"20060624111657.GR21864@pasky.or.cz","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-24T11:57:31Z","receivedAt":"2006-06-24T11:57:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> (This is also why I was a bit confused by your make test patch - it does\n> not \"fix\" anything per se since no tests directly use Git.pm.)\n\nYou are right.\n\nYou do not want to be testing installed version, but the one\nfreshly built, so the patch does not have any effect, except for\none case: testing before installing Git.pm for the first time\nanywhere yet.  -I prepends the directory to the search path, so\nwe are not testing the freshly built copy at all.\n\nIs there a way from the environment to override this behaviour,\nso that we can run the tests properly?  I think PERL5LIB and\nPERLLIB are defeated by having -I there (that's why I said I\nliked what Fredrik did with his Python script, which appends the\nfinal installed location to the search path).  I think unshift\ninto @INC by hand (i.e. without even using use lib \"$path\")\nwould do what we want, but I feel that is a bit too ugly just \nfor the testing X-<.\n\nI suspect we would need to think this a bit more... sigh.\n\n> ...because well, they do:\n>\n> $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl\n> \trm -f $@ $@+\n> \tsed -e '1s|#!.*perl\\(.*\\)|#!$(PERL_PATH_SQ)\\1 -I'\"$$(make -s -C perl instlibdir)\"'|' \\\n> \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n> \t    $@.perl >$@+\n> \tchmod +x $@+\n> \tmv $@+ $@\n\nI'll need to look at why it fails for me, but the above seems to\nbe doing the right thing, from a superficial look at least.\n\ngit-fmt-merge-msg substituted like the above begins with:\n\n\t#!/usr/bin/perl -w -I/home/junio/git-pu/share/perl/5.8.8\n\nbecause my $(prefix) is /home/junio/git-pu/ when building from \"pu\"\nbranch.  Then it goes on to create ~/git-pu/{lib,share}/perl/5.8.8\nand does this:\n\nmake -C perl install\nmake[1]: Entering directory `/opt/git/git.git/perl'\nInstalling /home/junio/git-pu/lib/perl/5.8.8/auto/Git/Git.so\nInstalling /home/junio/git-pu/lib/perl/5.8.8/auto/Git/Git.bs\nFiles found in blib/arch: installing files in blib/lib into architecture dependent library tree\nInstalling /home/junio/git-pu/lib/perl/5.8.8/Git.pm\nInstalling /home/junio/git-pu/lib/perl/5.8.8/Error.pm\nInstalling /home/junio/git-pu/man/man3/Error.3pm\nInstalling /home/junio/git-pu/man/man3/Git.3pm\nWriting /home/junio/git-pu/lib/perl/5.8.8/auto/Git/.packlist\nAppending installation info to /home/junio/git-pu/lib/perl/5.8.8/perllocal.pod\n\nIt appears that this is needed perhaps?\n\ndiff --git a/perl/Makefile.PL b/perl/Makefile.PL\nindex 54e8b20..92c140d 100644\n--- a/perl/Makefile.PL\n+++ b/perl/Makefile.PL\n@@ -3,7 +3,7 @@ use ExtUtils::MakeMaker;\n sub MY::postamble {\n \treturn <<'MAKE_FRAG';\n instlibdir:\n-\t@echo $(INSTALLSITELIB)\n+\t@echo $(INSTALLSITEARCH)\n \n MAKE_FRAG\n }\n"},{"id":"22448","messageId":"20060624130234.GT21864@pasky.or.cz","threadId":"4646","inReplyTo":"7vac82wytw.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T13:02:34Z","receivedAt":"2006-06-24T13:02:34Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 01:57:31PM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> Petr Baudis <pasky@suse.cz> writes:\n> \n> > (This is also why I was a bit confused by your make test patch - it does\n> > not \"fix\" anything per se since no tests directly use Git.pm.)\n> \n> You are right.\n> \n> You do not want to be testing installed version, but the one\n> freshly built, so the patch does not have any effect, except for\n> one case: testing before installing Git.pm for the first time\n> anywhere yet.  -I prepends the directory to the search path, so\n> we are not testing the freshly built copy at all.\n> \n> Is there a way from the environment to override this behaviour,\n> so that we can run the tests properly?  I think PERL5LIB and\n> PERLLIB are defeated by having -I there (that's why I said I\n> liked what Fredrik did with his Python script, which appends the\n> final installed location to the search path).  I think unshift\n> into @INC by hand (i.e. without even using use lib \"$path\")\n> would do what we want, but I feel that is a bit too ugly just \n> for the testing X-<.\n\nPERL5LIB and use lib at the same time works for me. Anyway, with the\nsecond patch I've sent things should work well even if you don't have\nGit.pm installed anywhere yet.\n\n> diff --git a/perl/Makefile.PL b/perl/Makefile.PL\n> index 54e8b20..92c140d 100644\n> --- a/perl/Makefile.PL\n> +++ b/perl/Makefile.PL\n> @@ -3,7 +3,7 @@ use ExtUtils::MakeMaker;\n>  sub MY::postamble {\n>  \treturn <<'MAKE_FRAG';\n>  instlibdir:\n> -\t@echo $(INSTALLSITELIB)\n> +\t@echo $(INSTALLSITEARCH)\n>  \n>  MAKE_FRAG\n>  }\n\nOh, yes; that line came from the time when we had no .xs yet. It is not\nvisible here since both arch-specific and non-arch-specific libraries\nget installed to ~/lib.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22451","messageId":"20060624131731.GU21864@pasky.or.cz","threadId":"4646","inReplyTo":"7vmzc3ymnu.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 07/12] Git.pm: Better error handling","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T13:17:31Z","receivedAt":"2006-06-24T13:17:31Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 10:37:25AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> Petr Baudis <pasky@suse.cz> writes:\n> \n> > +int\n> > +error_xs(const char *err, va_list params)\n> > +{\n> \n> You said in git-compat-util.h that set_error_routine takes a\n> function that returns void, so this gives unnecessary type\n> clash.\n> \n> --------------------------------\n> In file included from /usr/lib/perl/5.8/CORE/perl.h:756,\n>                  from Git.xs:15:\n> /usr/lib/perl/5.8/CORE/embed.h:4193:1: warning: \"die\" redefined\n> Git.xs:11:1: warning: this is the location of the previous definition\n> Git.xs: In function 'boot_Git':\n> Git.xs:57: warning: passing argument 1 of 'set_error_routine' from incompatible pointer type\n> Git.xs:58: warning: passing argument 1 of 'set_die_routine' makes qualified function pointer from unqualified\n> --------------------------------\n\nOh, I forgot to fix it in the .xs. :-(\n\n> Other troubles I saw with the v4 series while compiling:\n> \n> --------------------------------\n> usage.c:35: warning: initialization makes qualified function pointer from unqualified\n> usage.c:36: warning: initialization makes qualified function pointer from unqualified\n> \n> I'd fix it with this\n...\n\nAh, so THAT's where you put the NORETURN thing. ;-)\n\n> --------------------------------\n> \n> (cd perl && /usr/bin/perl Makefile.PL \\\n>                 PREFIX=\"/home/junio/git-test\" \\\n>                 DEFINE=\"-O2 -Wall -Wdeclaration-after-statement\n>                 -g -DSHA1_HEADER='<openssl/sha.h>'\n>                 -DGIT_VERSION=\\\\\\\"1.4.1.rc1.gab0df\\\\\\\"\" \\\n>                 LIBS=\"libgit.a xdiff/lib.a -lz  -lcrypto\")\n> Unrecognized argument in LIBS ignored: 'libgit.a'\n> Unrecognized argument in LIBS ignored: 'xdiff/lib.a'\n> \n> Do you need to pass LIBS, and if so maybe this is not a way\n> Makefile.PL expects it to be passed perhaps?\n\nIt is harmless, but this should fix it:\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n\ndiff --git a/Makefile b/Makefile\nindex d614f18..91bef4e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -230,7 +230,8 @@ BUILTIN_OBJS = \\\n \tbuiltin-update-ref.o\n \n GITLIBS = $(LIB_FILE) $(XDIFF_LIB)\n-LIBS = $(GITLIBS) -lz\n+\n+EXTLIBS = -lz\n \n #\n # Platform specific tweaks\n@@ -380,14 +381,14 @@ ifdef NEEDS_LIBICONV\n \telse\n \t\tICONV_LINK =\n \tendif\n-\tLIBS += $(ICONV_LINK) -liconv\n+\tEXTLIBS += $(ICONV_LINK) -liconv\n endif\n ifdef NEEDS_SOCKET\n-\tLIBS += -lsocket\n+\tEXTLIBS += -lsocket\n \tSIMPLE_LIB += -lsocket\n endif\n ifdef NEEDS_NSL\n-\tLIBS += -lnsl\n+\tEXTLIBS += -lnsl\n \tSIMPLE_LIB += -lnsl\n endif\n ifdef NO_D_TYPE_IN_DIRENT\n@@ -446,7 +447,7 @@ ifdef MOZILLA_SHA1\n \tLIB_OBJS += mozilla-sha1/sha1.o\n else\n \tSHA1_HEADER = <openssl/sha.h>\n-\tLIBS += $(LIB_4_CRYPTO)\n+\tEXTLIBS += $(LIB_4_CRYPTO)\n endif\n endif\n endif\n@@ -469,9 +470,13 @@ PERL_PATH_SQ = $(subst ','\\'',$(PERL_PAT\n PYTHON_PATH_SQ = $(subst ','\\'',$(PYTHON_PATH))\n GIT_PYTHON_DIR_SQ = $(subst ','\\'',$(GIT_PYTHON_DIR))\n \n+LIBS = $(GITLIBS) $(EXTLIBS)\n+\n ALL_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS)\n LIB_OBJS += $(COMPAT_OBJS)\n export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir\n+\n+\n ### Build rules\n \n all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk\n@@ -601,7 +606,7 @@ perl/Makefile:\tperl/Git.pm perl/Makefile\n \t(cd perl && $(PERL_PATH) Makefile.PL \\\n \t\tPREFIX=\"$(prefix)\" \\\n \t\tDEFINE=\"$(ALL_CFLAGS) -DGIT_VERSION=\\\\\\\"$(GIT_VERSION)\\\\\\\"\" \\\n-\t\tLIBS=\"$(LIBS)\")\n+\t\tLIBS=\"$(EXTLIBS)\")\n \n doc:\n \t$(MAKE) -C Documentation all\n\n> --------------------------------\n> Makefile out-of-date with respect to Makefile.PL\n> Cleaning current config before rebuilding Makefile...\n> make -f Makefile.old clean > /dev/null 2>&1\n> /usr/bin/perl Makefile.PL \"PREFIX=/home/junio/git-test\" \"DEFINE=-O2 -Wall -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>'  -DGIT_VERSION=\\\"1.4.1.rc1.gab0df\\\"\" \"LIBS=libgit.a xdiff/lib.a -lz  -lcrypto\"\n> Unrecognized argument in LIBS ignored: 'libgit.a'\n> Unrecognized argument in LIBS ignored: 'xdiff/lib.a'\n> Writing Makefile for Git\n> ==> Your Makefile has been rebuilt. <==\n> ==> Please rerun the make command.  <==\n> false\n> make[1]: *** [Makefile] Error 1\n> --------------------------------\n> \n> The latter is what Perl's build mechanism does so it is not\n> strictly your fault, but it nevertheless is irritating that we\n> have to say make clean twice.\n\nWhat about just this?\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n\ndiff --git a/Makefile b/Makefile\nindex 91bef4e..55c07b6 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -731,7 +731,8 @@ clean:\n \trm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz\n \trm -f $(htmldocs).tar.gz $(manpages).tar.gz\n \t$(MAKE) -C Documentation/ clean\n-\t[ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean\n+\t# Try twice in case the Makefile has been rebuilt\n+\t[ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean || $(MAKE) -C perl/ clean\n \t$(MAKE) -C templates/ clean\n \t$(MAKE) -C t/ clean\n \trm -f GIT-VERSION-FILE GIT-CFLAGS\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22489","messageId":"20060625011347.GY21864@pasky.or.cz","threadId":"4646","inReplyTo":"20060624131731.GU21864@pasky.or.cz","subject":"Re: [PATCH 07/12] Git.pm: Better error handling","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-25T01:13:47Z","receivedAt":"2006-06-25T01:13:47Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Jun 24, 2006 at 03:17:31PM CEST, I got a letter\nwhere Petr Baudis <pasky@suse.cz> said that...\n> Dear diary, on Sat, Jun 24, 2006 at 10:37:25AM CEST, I got a letter\n> where Junio C Hamano <junkio@cox.net> said that...\n> > Petr Baudis <pasky@suse.cz> writes:\n> > \n> > > +int\n> > > +error_xs(const char *err, va_list params)\n> > > +{\n> > \n> > You said in git-compat-util.h that set_error_routine takes a\n> > function that returns void, so this gives unnecessary type\n> > clash.\n> > \n> > --------------------------------\n> > In file included from /usr/lib/perl/5.8/CORE/perl.h:756,\n> >                  from Git.xs:15:\n> > /usr/lib/perl/5.8/CORE/embed.h:4193:1: warning: \"die\" redefined\n> > Git.xs:11:1: warning: this is the location of the previous definition\n> > Git.xs: In function 'boot_Git':\n> > Git.xs:57: warning: passing argument 1 of 'set_error_routine' from incompatible pointer type\n> > Git.xs:58: warning: passing argument 1 of 'set_die_routine' makes qualified function pointer from unqualified\n> > --------------------------------\n> \n> Oh, I forgot to fix it in the .xs. :-(\n\n---\n[PATCH] Git.pm: Squash some annoying warnings in Git.xs\n\nFrom: Petr Baudis <pasky@suse.cz>\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.xs |   11 ++++-------\n 1 files changed, 4 insertions(+), 7 deletions(-)\n\ndiff --git a/perl/Git.xs b/perl/Git.xs\nindex e841e4a..d7a2b75 100644\n--- a/perl/Git.xs\n+++ b/perl/Git.xs\n@@ -29,21 +29,18 @@ report_xs(const char *prefix, const char\n \treturn buf;\n }\n \n-void\n+void NORETURN\n die_xs(const char *err, va_list params)\n {\n-\tchar *str;\n-\tstr = report_xs(\"fatal: \", err, params);\n+\tchar *str = report_xs(\"fatal: \", err, params);\n \tcroak(str);\n }\n \n-int\n+void\n error_xs(const char *err, va_list params)\n {\n-\tchar *str;\n-\tstr = report_xs(\"error: \", err, params);\n+\tchar *str = report_xs(\"error: \", err, params);\n \twarn(str);\n-\treturn -1;\n }\n \n \n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nA person is just about as big as the things that make them angry.\n"},{"id":"22496","messageId":"7vr71erphz.fsf@assigned-by-dhcp.cox.net","threadId":"4646","inReplyTo":"20060624131731.GU21864@pasky.or.cz","subject":"Re: [PATCH 07/12] Git.pm: Better error handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-25T01:30:16Z","receivedAt":"2006-06-25T01:30:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n>> --------------------------------\n>> \n>> (cd perl && /usr/bin/perl Makefile.PL \\\n>>                 PREFIX=\"/home/junio/git-test\" \\\n>>                 DEFINE=\"-O2 -Wall -Wdeclaration-after-statement\n>>                 -g -DSHA1_HEADER='<openssl/sha.h>'\n>>                 -DGIT_VERSION=\\\\\\\"1.4.1.rc1.gab0df\\\\\\\"\" \\\n>>                 LIBS=\"libgit.a xdiff/lib.a -lz  -lcrypto\")\n>> Unrecognized argument in LIBS ignored: 'libgit.a'\n>> Unrecognized argument in LIBS ignored: 'xdiff/lib.a'\n>> \n>> Do you need to pass LIBS, and if so maybe this is not a way\n>> Makefile.PL expects it to be passed perhaps?\n>\n> It is harmless, but this should fix it:\n>\n> Signed-off-by: Petr Baudis <pasky@suse.cz>\n\nApplied the \"EXTLIBS\" change in the message.  I did the same\n\"clean twice\" change last night.  Also I will apply the\n\"PERL_DEFINES_SQ\" change as well.  Hopefully this would make\nthings buildable for more people.\n\nThanks.\n"},{"id":"22515","messageId":"7vr71eorlw.fsf@assigned-by-dhcp.cox.net","threadId":"4646","inReplyTo":"20060624130234.GT21864@pasky.or.cz","subject":"Re: [PATCH 01/12] Introduce Git.pm (v4)","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-25T03:12:59Z","receivedAt":"2006-06-25T03:12:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"ePetr Baudis <pasky@suse.cz> writes:\n\n>> Is there a way from the environment to override this behaviour,\n>> so that we can run the tests properly?  I think PERL5LIB and\n>> PERLLIB are defeated by having -I there (that's why I said I\n>> liked what Fredrik did with his Python script, which appends the\n>> final installed location to the search path).  I think unshift\n>> into @INC by hand (i.e. without even using use lib \"$path\")\n>> would do what we want, but I feel that is a bit too ugly just \n>> for the testing X-<.\n>\n> PERL5LIB and use lib at the same time works for me. Anyway, with the\n> second patch I've sent things should work well even if you don't have\n> Git.pm installed anywhere yet.\n\nSorry, I am not sure it \"works for me\" -- which one take\nprecedence for this?\n\n\t$ head -n 2 script.perl\n        #!/usr/bin/perl -w -I /path/a\n        use lib \"/path/b\";\n        $ ./script.perl ;# invocation #1\n        $ PERL5LIB=/path/c ./script.perl ;# invocation #2\n\nPrecedence between the in-script -I and \"use lib\" are\nirrelevant, but unless PERL5LIB takes precedence and the\ninvocation #2 takes Git.pm from /path/c my previous patch \nto make sure test uses freshly built one does not work.\n\n>> diff --git a/perl/Makefile.PL b/perl/Makefile.PL\n>> index 54e8b20..92c140d 100644\n>> --- a/perl/Makefile.PL\n>> +++ b/perl/Makefile.PL\n>> @@ -3,7 +3,7 @@ use ExtUtils::MakeMaker;\n>>  sub MY::postamble {\n>>  \treturn <<'MAKE_FRAG';\n>>  instlibdir:\n>> -\t@echo $(INSTALLSITELIB)\n>> +\t@echo $(INSTALLSITEARCH)\n>>  \n>>  MAKE_FRAG\n>>  }\n>\n> Oh, yes; that line came from the time when we had no .xs yet. It is not\n> visible here since both arch-specific and non-arch-specific libraries\n> get installed to ~/lib.\n\nOK.  Thanks.\n"}]}