Introduce Git.pm (v3)
PATCH 1/1 Introduce Git.pm (v3)
This patch introduces a very basic and barebone Git.pm module with a sketch of how the generic interface would look like; most functions are missing, but this should give some good base. I will continue expanding it.
Most desirable now is more careful error reporting, generic_in() for feeding input to Git commands and the repository() constructor doing some poking with git-rev-parse to get the git directory and subdirectory prefix. Those three are basically the prerequisities for converting git-mv.
Currently Git.pm just wraps up exec()s of Git commands, but even that is not trivial to get right and various Git perl scripts do it in various inconsistent ways. In addition to Git.pm, there is now also Git.xs which provides barebone Git.xs for directly interfacing with libgit.a, and as an example providing the hash_object() function using libgit.
This adds the Git module, integrates it to the build system and as an example converts the git-fmt-merge-msg.perl script to it (the result is not very impressive since its advantage is not quite apparent in this one, but I just picked up the simplest Git user around).
The changes since v1 are:
* s/generic/command/ in the API, added command_pipe() and changed behaviour of command() in the scalar context
* Added hash_object() and Git.xs providing the fast implementation
* Better error reporting
* Plenty of random minor stuff
It's a good thing v2 didn't make it to the list since it contained a huge file which turns out that can be autogenerated at the build time, so v3 just changes that (and adds .gitignore file and makes some other minor changes).
I consider this patch "stable" now. Further enhancements will be posted as patches on top of this.
My current working state is available all the time at
http://pasky.or.cz/~xpasky/git-perl/Git.pm
and an irregularily updated API documentation is at
http://pasky.or.cz/~xpasky/git-perl/Git.html
Many thanks to Jakub Narebski, Junio and others for their feedback.
---
Makefile | 12 + git-fmt-merge-msg.perl | 10 + perl/.gitignore | 7 + perl/Git.pm | 401 ++++++++++++++++++++++++++++++++++++++++++++++++ perl/Git.xs | 60 +++++++ perl/Makefile.PL | 21 +++ 6 files changed, 504 insertions(+), 7 deletions(-)
Makefile +9 -3
@@ -476,7 +476,8 @@ ### Build rules all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk -all: +all: perl/Makefile + $(MAKE) -C perl $(MAKE) -C templates strip: $(PROGRAMS) git$X
@@ -508,7 +509,7 @@ common-cmds.h: Documentation/git-*.txt $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl rm -f $@ $@+ - sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \ + sed -e '1s|#!.*perl\(.*\)|#!$(PERL_PATH_SQ)\1 -I'"$$(make -s -C perl instlibdir)"'|' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ [email protected] >$@+ chmod +x $@+
@@ -594,6 +595,9 @@ XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS) +perl/Makefile: perl/Git.pm perl/Makefile.PL + (cd perl && $(PERL_PATH) Makefile.PL PREFIX="$(prefix)" DEFINE="$(ALL_CFLAGS)" LIBS="$(LIBS)") + doc: $(MAKE) -C Documentation all
@@ -649,6 +653,7 @@ install: all $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)' $(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates install + $(MAKE) -C perl install $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)' $(INSTALL) $(PYMODULES) '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)' if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \
@@ -716,7 +721,8 @@ clean: rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz rm -f $(htmldocs).tar.gz $(manpages).tar.gz $(MAKE) -C Documentation/ clean - $(MAKE) -C templates clean + [ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean + $(MAKE) -C templates/ clean $(MAKE) -C t/ clean rm -f GIT-VERSION-FILE GIT-CFLAGS
git-fmt-merge-msg.perl +6 -4
@@ -6,6 +6,9 @@ # Read .git/FETCH_HEAD and make a human # by grouping branches and tags together to form a single line. use strict; +use Git; + +my $repo = Git->repository(); my @src; my %src;
@@ -28,13 +31,12 @@ sub andjoin { } sub repoconfig { - my ($val) = qx{git-repo-config --get merge.summary}; + my ($val) = $repo->command_oneline('repo-config', '--get', 'merge.summary'); return $val; } sub current_branch { - my ($bra) = qx{git-symbolic-ref HEAD}; - chomp($bra); + my ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD'); $bra =~ s|^refs/heads/||; if ($bra ne 'master') { $bra = " into $bra";
@@ -47,7 +49,7 @@ sub current_branch { sub shortlog { my ($tip) = @_; my @result; - foreach ( qx{git-log --no-merges --topo-order --pretty=oneline $tip ^HEAD} ) { + foreach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) { s/^[0-9a-f]{40}\s+//; push @result, $_; }
perl/.gitignore new file +7 -0
@@ -0,0 +1,7 @@ +Git.bs +Git.c +Makefile +blib +blibdirs +pm_to_blib +ppport.h
perl/Git.pm new file +401 -0
401 lines not on this page · raw message
perl/Git.xs new file +60 -0
60 lines not on this page · raw message
perl/Makefile.PL new file +21 -0
@@ -0,0 +1,21 @@ +use ExtUtils::MakeMaker; + +sub MY::postamble { + return <<'MAKE_FRAG'; +instlibdir: + @echo $(INSTALLSITELIB) + +MAKE_FRAG +} + +WriteMakefile( + NAME => 'Git', + VERSION_FROM => 'Git.pm', + MYEXTLIB => '../libgit.a', + INC => '-I. -I..', +); + + +use Devel::PPPort; + +-s 'ppport.h' or Devel::PPPort::WriteFile();
Quoted 11 lines · Petr Baudis
* Added
hash_object()and Git.xs providing the fast implementation
* Better error reporting
* Plenty of random minor stuffIt's a good thing v2 didn't make it to the list since it contained a huge file which turns out that can be autogenerated at the build time, so v3 just changes that (and adds .gitignore file and makes some other minor changes).
I consider this patch "stable" now. Further enhancements will be posted as patches on top of this.
Eek. It does not compile for me -- maybe there is more dependencies that need to be listed in INSTALL file?
make -C perl
make[1]: Entering directory `/opt/git/git.git/perl'
cc -c -I. -I.. -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC "-I/usr/lib/perl/5.8/CORE" -O2 -Wall -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>' Git.c
Git.xs: In function 'XS_Git_xs_hash_object':
Git.xs:27: warning: ISO C90 forbids mixed declarations and code
Git.xs:44: warning: passing argument 1 of 'Perl_io_close' from incompatible pointer type Git.xs:44: warning: passing argument 2 of 'Perl_io_close' makes pointer from integer without a cast Git.xs:44: error: too few arguments to function 'Perl_io_close'
make[1]: *** [Git.o] Error 1
make[1]: Leaving directory `/opt/git/git.git/perl'
make: *** [all] Error 2
Dear diary, on Fri, Jun 23, 2006 at 01:18:10AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...
Quoted 17 lines
Quoted 11 lines · Petr Baudis
* Added
hash_object()and Git.xs providing the fast implementation
* Better error reporting
* Plenty of random minor stuffIt's a good thing v2 didn't make it to the list since it contained a huge file which turns out that can be autogenerated at the build time, so v3 just changes that (and adds .gitignore file and makes some other minor changes).
I consider this patch "stable" now. Further enhancements will be posted as patches on top of this.
Eek. It does not compile for me -- maybe there is more dependencies that need to be listed in INSTALL file?
Quoted 8 lines
make -C perl
make[1]: Entering directory `/opt/git/git.git/perl'
cc -c -I. -I.. -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC "-I/usr/lib/perl/5.8/CORE" -O2 -Wall -Wdeclaration-after-statement -g -DSHA1_HEADER='<openssl/sha.h>'Git.c
Git.xs: In function 'XS_Git_xs_hash_object':
Git.xs:27: warning: ISO C90 forbids mixed declarations and code
Git.xs:44: warning: passing argument 1 of 'Perl_io_close' from incompatible pointer type Git.xs:44: warning: passing argument 2 of 'Perl_io_close' makes pointer from integer without a cast Git.xs:44: error: too few arguments to function 'Perl_io_close'
Oops, sorry. Apparently, I've digged too deep and unleashed a monster of unstable API. Now I've finally discovered perlapio(1) and know I should've just called PerlIO_close(). Below comes a fixed patch, I didn't bother to bump the version number.
---
[PATCH] Introduce Git.pm (v3)
This patch introduces a very basic and barebone Git.pm module with a sketch of how the generic interface would look like; most functions are missing, but this should give some good base. I will continue expanding it.
Most desirable now is more careful error reporting, generic_in() for feeding input to Git commands and the repository() constructor doing some poking with git-rev-parse to get the git directory and subdirectory prefix. Those three are basically the prerequisities for converting git-mv.
Currently Git.pm just wraps up exec()s of Git commands, but even that is not trivial to get right and various Git perl scripts do it in various inconsistent ways. In addition to Git.pm, there is now also Git.xs which provides barebone Git.xs for directly interfacing with libgit.a, and as an example providing the hash_object() function using libgit.
This adds the Git module, integrates it to the build system and as an example converts the git-fmt-merge-msg.perl script to it (the result is not very impressive since its advantage is not quite apparent in this one, but I just picked up the simplest Git user around).
The changes since v1 are:
* s/generic/command/ in the API, added command_pipe() and changed behaviour of command() in the scalar context
* Added hash_object() and Git.xs providing the fast implementation
* Better error reporting
* Plenty of random minor stuff
It's a good thing v2 didn't make it to the list since it contained a huge file which turns out that can be autogenerated at the build time, so v3 just changes that (and adds .gitignore file and makes some other minor changes).
I consider this patch "stable" now. Further enhancements will be posted as patches on top of this.
My current working state is available all the time at
http://pasky.or.cz/~xpasky/git-perl/Git.pm
and an irregularily updated API documentation is at
http://pasky.or.cz/~xpasky/git-perl/Git.html
Many thanks to Jakub Narebski, Junio and others for their feedback.
---
Makefile | 12 + git-fmt-merge-msg.perl | 10 + perl/.gitignore | 7 + perl/Git.pm | 401 ++++++++++++++++++++++++++++++++++++++++++++++++ perl/Git.xs | 60 +++++++ perl/Makefile.PL | 21 +++ 6 files changed, 504 insertions(+), 7 deletions(-)
Makefile +9 -3
@@ -476,7 +476,8 @@ ### Build rules all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk -all: +all: perl/Makefile + $(MAKE) -C perl $(MAKE) -C templates strip: $(PROGRAMS) git$X
@@ -508,7 +509,7 @@ common-cmds.h: Documentation/git-*.txt $(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl rm -f $@ $@+ - sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \ + sed -e '1s|#!.*perl\(.*\)|#!$(PERL_PATH_SQ)\1 -I'"$$(make -s -C perl instlibdir)"'|' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ [email protected] >$@+ chmod +x $@+
@@ -594,6 +595,9 @@ XDIFF_OBJS=xdiff/xdiffi.o xdiff/xprepare rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS) +perl/Makefile: perl/Git.pm perl/Makefile.PL + (cd perl && $(PERL_PATH) Makefile.PL PREFIX="$(prefix)" DEFINE="$(ALL_CFLAGS)" LIBS="$(LIBS)") + doc: $(MAKE) -C Documentation all
@@ -649,6 +653,7 @@ install: all $(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)' $(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)' $(MAKE) -C templates install + $(MAKE) -C perl install $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)' $(INSTALL) $(PYMODULES) '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)' if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \
@@ -716,7 +721,8 @@ clean: rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz rm -f $(htmldocs).tar.gz $(manpages).tar.gz $(MAKE) -C Documentation/ clean - $(MAKE) -C templates clean + [ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean + $(MAKE) -C templates/ clean $(MAKE) -C t/ clean rm -f GIT-VERSION-FILE GIT-CFLAGS
git-fmt-merge-msg.perl +6 -4
@@ -6,6 +6,9 @@ # Read .git/FETCH_HEAD and make a human # by grouping branches and tags together to form a single line. use strict; +use Git; + +my $repo = Git->repository(); my @src; my %src;
@@ -28,13 +31,12 @@ sub andjoin { } sub repoconfig { - my ($val) = qx{git-repo-config --get merge.summary}; + my ($val) = $repo->command_oneline('repo-config', '--get', 'merge.summary'); return $val; } sub current_branch { - my ($bra) = qx{git-symbolic-ref HEAD}; - chomp($bra); + my ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD'); $bra =~ s|^refs/heads/||; if ($bra ne 'master') { $bra = " into $bra";
@@ -47,7 +49,7 @@ sub current_branch { sub shortlog { my ($tip) = @_; my @result; - foreach ( qx{git-log --no-merges --topo-order --pretty=oneline $tip ^HEAD} ) { + foreach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) { s/^[0-9a-f]{40}\s+//; push @result, $_; }
perl/.gitignore new file +7 -0
@@ -0,0 +1,7 @@ +Git.bs +Git.c +Makefile +blib +blibdirs +pm_to_blib +ppport.h
perl/Git.pm new file +401 -0
401 lines not on this page · raw message
perl/Git.xs new file +60 -0
60 lines not on this page · raw message
perl/Makefile.PL new file +21 -0
@@ -0,0 +1,21 @@ +use ExtUtils::MakeMaker; + +sub MY::postamble { + return <<'MAKE_FRAG'; +instlibdir: + @echo $(INSTALLSITELIB) + +MAKE_FRAG +} + +WriteMakefile( + NAME => 'Git', + VERSION_FROM => 'Git.pm', + MYEXTLIB => '../libgit.a', + INC => '-I. -I..', +); + + +use Devel::PPPort; + +-s 'ppport.h' or Devel::PPPort::WriteFile();
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ A person is just about as big as the things that make them angry.
Quoted 9 lines · Petr Baudis
Quoted 8 lines
Eek. It does not compile for me -- maybe there is more
dependencies that need to be listed in INSTALL file?
...
Git.xs: In function 'XS_Git_xs_hash_object':
Git.xs:27: warning: ISO C90 forbids mixed declarations and code
Git.xs:44: warning: passing argument 1 of 'Perl_io_close' from incompatible pointer type Git.xs:44: warning: passing argument 2 of 'Perl_io_close' makes pointer from integer without a cast Git.xs:44: error: too few arguments to function 'Perl_io_close'
Quoted 4 lines
Oops, sorry. Apparently, I've digged too deep and unleashed a monster of unstable API. Now I've finally discovered perlapio(1) and know I should've just called
PerlIO_close(). Below comes a fixed patch, I didn't bother to bump the version number.
Thanks; it compiles now with a few more glitches.
/usr/bin/perl /usr/share/perl/5.8/ExtUtils/xsubpp \
-typemap /usr/share/perl/5.8/ExtUtils/typemap Git.xs > Git.xsc && \
mv Git.xsc Git.c
Please specify prototyping behavior for Git.xs (see perlxs manual)
Says xsubpp.
cc -c -I. -I.. -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS \
-DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include \
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 \
-DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC \
"-I/usr/lib/perl/5.8/CORE" -Wall
-Wdeclaration-after-statement \
-g -DSHA1_HEADER='<openssl/sha.h>' \
-DGIT_VERSION=\"1.4.1.rc1.g01a1\" Git.c
Git.xs: In function 'XS_Git_xs__execv_git_cmd':
Git.xs:57: warning: passing argument 1 of 'free' discards qualifiers from pointer target type
Git.xs: In function 'XS_Git_xs_hash_object':
Git.xs:65: warning: ISO C90 forbids mixed declarations and codeI usually compile with -Wdeclaration-after-statement so I probably get some more warnings than you saw; it probably is primarily xsubpp's fault, but you could work it around by having CODE block to be inside an extra set of braces {}. Constness reduction of free() is a bit annoying from the point of view of the coder who has to cast away constness, so I won't be too strict about that, but it would be nicer if we did not have to see the warnings.
rm -f blib/arch/auto/Git/Git.so
cc -shared -L/usr/local/lib Git.o -o blib/arch/auto/Git/Git.so ../libgit.a \
-lz -lcrypto \
/usr/bin/ld: ../libgit.a(exec_cmd.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../libgit.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [blib/arch/auto/Git/Git.so] Error 1
This is a real killer. If we compile everything with -fPIC, this goes away, but I do not think we want -fPIC for the core level tools. At least not until we are ready to do libgit.so.
Dear diary, on Fri, Jun 23, 2006 at 02:22:41AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...
Quoted 16 lines
Quoted 9 lines · Petr Baudis
Quoted 8 lines
Eek. It does not compile for me -- maybe there is more
dependencies that need to be listed in INSTALL file?
...
Git.xs: In function 'XS_Git_xs_hash_object':
Git.xs:27: warning: ISO C90 forbids mixed declarations and code
Git.xs:44: warning: passing argument 1 of 'Perl_io_close' from incompatible pointer type Git.xs:44: warning: passing argument 2 of 'Perl_io_close' makes pointer from integer without a cast Git.xs:44: error: too few arguments to function 'Perl_io_close'Quoted 4 lines
Oops, sorry. Apparently, I've digged too deep and unleashed a monster of unstable API. Now I've finally discovered perlapio(1) and know I should've just called
PerlIO_close(). Below comes a fixed patch, I didn't bother to bump the version number.
Quoted 8 lines
Thanks; it compiles now with a few more glitches.
/usr/bin/perl/usr/share/perl/5.8/ExtUtils/xsubpp\
-typemap/usr/share/perl/5.8/ExtUtils/typemapGit.xs > Git.xsc && \
mv Git.xscGit.c
Please specify prototyping behavior for Git.xs (see perlxs manual)Says xsubpp.
It's harmless but can be fixed by:
perl/Git.xs +2 -0
@@ -17,6 +17,8 @@ #include "ppport.h" MODULE = Git PACKAGE = Git +PROTOTYPES: DISABLE + # /* TODO: xs_call_gate(). See Git.pm. */ char *
Quoted 13 lines
cc -c -I. -I.. -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS \
-DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include \
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 \
-DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC \
"-I/usr/lib/perl/5.8/CORE" -Wall
-Wdeclaration-after-statement \
-g -DSHA1_HEADER='<openssl/sha.h>' \
-DGIT_VERSION=\"1.4.1.rc1.g01a1\" Git.c
Git.xs: In function 'XS_Git_xs__execv_git_cmd':
Git.xs:57: warning: passing argument 1 of 'free' discards qualifiers from pointer target type
Git.xs: In function 'XS_Git_xs_hash_object':
Git.xs:65: warning: ISO C90 forbids mixed declarations and codeQuoted 4 lines
I usually compile with -Wdeclaration-after-statement so I probably get some more warnings than you saw; it probably is primarily xsubpp's fault, but you could work it around by having CODE block to be inside an extra set of braces {}.
Sure. Should I resend all the .xs-related patches with the code blocks in {}, or will you add it at your side?
Quoted 4 lines
Constness reduction of
free()is a bit annoying from the point of view of the coder who has to cast away constness, so I won't be too strict about that, but it would be nicer if we did not have to see the warnings.
Sure, it should be trivial to fix.
Quoted 4 lines
rm -f blib/arch/auto/Git/Git.so
cc -shared -L/usr/local/lib Git.o -o blib/arch/auto/Git/Git.so ../libgit.a \
-lz -lcrypto \
Quoted 8 lines
/usr/bin/ld: ../libgit.a(exec_cmd.o): relocationR_X86_64_32against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../libgit.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [blib/arch/auto/Git/Git.so] Error 1This is a real killer. If we compile everything with -fPIC, this goes away, but I do not think we want -fPIC for the core level tools. At least not until we are ready to do libgit.so.
Hmm, I didn't get that; I guess that's x86-64 specific. :/ Do you have any idea what the error actually means? Could the environ be a problem? (Why aren't we calling just execv()?)
Also, is there any real problem with just using -fPIC?
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ A person is just about as big as the things that make them angry.
Quoted 1 line · Petr Baudis
Also, is there any real problem with just using -fPIC?
Personally, not really, but I consider it a workaround having to compile with -fPIC (being able to compile with -fPIC is a feature).
Doesn't it have performance implications to use -fPIC when you do not have to?
By the way, you also need to adjust the testsuite so that it finds the Perl modules from freshly built tree before installing. I think (but haven't checked yet) the stuff written in Python does that already, so you might want to mimic it.
Quoted 8 lines · Junio C Hamano
Quoted 1 line · Petr Baudis
Also, is there any real problem with just using -fPIC?
Personally, not really, but I consider it a workaround having to compile with -fPIC (being able to compile with -fPIC is a feature).
Quoted 7 lines
Doesn't it have performance implications to use -fPIC when you do not have to?
By the way, you also need to adjust the testsuite so that it finds the Perl modules from freshly built tree before installing. I think (but haven't checked yet) the stuff written in Python does that already, so you might want to mimic it.
So what was being compiled was a shared Git.so.
32bit x86 is on of the few architectures that allows you to build a .so without compiling with -fPIC.
The question is why are we building with a .so?
Eric
Dear diary, on Fri, Jun 23, 2006 at 10:57:50AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...
Quoted 7 lines
Quoted 1 line · Petr Baudis
Also, is there any real problem with just using -fPIC?
Personally, not really, but I consider it a workaround having to compile with -fPIC (being able to compile with -fPIC is a feature).
Well, for the .xs you do need an .so and for that you apparently need -fPIC on most architectures, so there's no way around it.
There's a patch to build libgit.so, would you take it as an excuse to always compile with -fPIC? ;-)
Quoted 2 lines
Doesn't it have performance implications to use -fPIC when you do not have to?
No idea here.
Quoted 4 lines
By the way, you also need to adjust the testsuite so that it finds the Perl modules from freshly built tree before installing. I think (but haven't checked yet) the stuff written in Python does that already, so you might want to mimic it.
It should be enough to -I../perl/blib/lib -I../perl/blib/arch/auto/Git.
Dear diary, on Fri, Jun 23, 2006 at 02:04:17PM CEST, I got a letter where "Eric W. Biederman" <[email protected]> said that...
Quoted 1 line
The question is why are we building with a .so?
To make use of it in Git.pm - it can call libgit routines directly from inside of Perl, but for that it needs to dynamically link libgit to the Perl process on the fly (using dlopen()).
We _can_ avoid the .so, but that involved producing a new perl executable with libgit statically linked to it, which is quite impractical, so to say.
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ A person is just about as big as the things that make them angry.
Quoted 6 lines · Petr Baudis
Quoted 4 lines
By the way, you also need to adjust the testsuite so that it finds the Perl modules from freshly built tree before installing. I think (but haven't checked yet) the stuff written in Python does that already, so you might want to mimic it.
It should be enough to -I../perl/blib/lib -I../perl/blib/arch/auto/Git.
-- >8 --
[PATCH] Perl interface: make testsuite work again.
--- t/test-lib.sh | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
t/test-lib.sh +2 -0
@@ -206,6 +206,8 @@ PYTHON=`sed -e '1{ PYTHONPATH=$(pwd)/../compat export PYTHONPATH } +PERL5LIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git +export PERL5LIB test -d ../templates/blt || { error "You haven't built things yet, have you?" }
Signature · 1 line
1.4.1.rc1.gf2641
Quoted 6 lines · Petr Baudis
Quoted 4 lines
By the way, you also need to adjust the testsuite so that it finds the Perl modules from freshly built tree before installing. I think (but haven't checked yet) the stuff written in Python does that already, so you might want to mimic it.
It should be enough to -I../perl/blib/lib -I../perl/blib/arch/auto/Git.
-- >8 --
[PATCH] Perl interface: add build-time configuration to allow building with -fPIC
On x86-64 it seems that Git.xs does not link without compiling the main git objects with -fPIC.
---
* Also I moved explanation of MOZILLA_SHA1 closer to other SHA1 choices.
Makefile | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-)
Makefile +13 -7
@@ -1,11 +1,6 @@ # The default target of this Makefile is... all: -# Define MOZILLA_SHA1 environment variable when running make to make use of -# a bundled SHA1 routine coming from Mozilla. It is GPL'd and should be fast -# on non-x86 architectures (e.g. PowerPC), while the OpenSSL version (default -# choice) has very fast version optimized for i586. -# # Define NO_OPENSSL environment variable if you do not have OpenSSL. # This also implies MOZILLA_SHA1. #
@@ -37,6 +32,14 @@ # # Define ARM_SHA1 environment variable when running make to make use of # a bundled SHA1 routine optimized for ARM. # +# Define MOZILLA_SHA1 environment variable when running make to make use of +# a bundled SHA1 routine coming from Mozilla. It is GPL'd and should be fast +# on non-x86 architectures (e.g. PowerPC), while the OpenSSL version (default +# choice) has very fast version optimized for i586. +# +# Define USE_PIC if you need the main git objects to be built with -fPIC +# in order to build and link perl/Git.so. x86-64 seems to need this. +# # Define NEEDS_SSL_WITH_CRYPTO if you need -lcrypto with -lssl (Darwin). # # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
@@ -63,13 +66,13 @@ # # Define COLLISION_CHECK below if you believe that SHA1's # 1461501637330902918203684832716283019655932542976 hashes do not give you # sufficient guarantee that no collisions between objects will ever happen. - +# # Define USE_NSEC below if you want git to care about sub-second file mtimes # and ctimes. Note that you need recent glibc (at least 2.2.4) for this, and # it will BREAK YOUR LOCAL DIFFS! show-diff and anything using it will likely # randomly break unless your underlying filesystem supports those sub-second # times (my ext3 doesn't). - +# # Define USE_STDEV below if you want git to care about the underlying device # change being considered an inode change from the update-cache perspective.
@@ -450,6 +453,9 @@ else endif endif endif +ifdef USE_PIC + ALL_CFLAGS += -fPIC +endif ifdef NO_ACCURATE_DIFF ALL_CFLAGS += -DNO_ACCURATE_DIFF endif
Signature · 1 line
1.4.1.rc1.gf2641
Quoted 9 lines · Junio C Hamano
Quoted 1 line
It should be enough to -I../perl/blib/lib -I../perl/blib/arch/auto/Git.
-- >8 --
[PATCH] Perl interface: add build-time configuration to allow building with -fPICOn x86-64 it seems that Git.xs does not link without compiling the main git objects with -fPIC.
Signed-off-by Junio C Hamano <[email protected]>
Eh, sorry this was in response to this part of Pasky's message:
Quoted 5 lines
Quoted 5 lines
Well, for the .xs you do need an .so and for that you apparently need -fPIC on most architectures, so there's no way around it.
There's a patch to build libgit.so, would you take it as an excuse to always compile with -fPIC? ;-)
By the way, I noticed NO_ACCURATE_DIFF is a compile time option to cause git-apply to accept diff output from implementations that botch "\No newline at the end of file", and I think it is wrong -- it should be a run time option to git-apply if we would want to support it, because the version of diff you have does not have much to do with which implementations of diff were used to generate patches you would receive and apply.
Thoughts?
Hi,
Quoted 9 lines · Junio C Hamano
By the way, I noticed
NO_ACCURATE_DIFFis a compile time option to cause git-apply to accept diff output from implementations that botch "\No newline at the end of file", and I think it is wrong -- it should be a run time option to git-apply if we would want to support it, because the version of diff you have does not have much to do with which implementations of diff were used to generate patches you would receive and apply.Thoughts?
My original idea: on a machine where you have no accurate diff, you at least want to pass the tests, and you want to ensure you can apply a diff you generated on that machine.
But I was wrong. This patch is just compile tested, but obviously correct (lacking usage() and Documentation updates as usual, since I do not want to do that work before I know the patch is applied):
---
[PATCH] apply: add --no-accurate-diff and --accurate-diff options
You can still set the default behaviour in the Makefile, but at least you can override it.
---
builtin-apply.c | 32 +++++++++++++++++++++++--------- 1 files changed, 23 insertions(+), 9 deletions(-)
builtin-apply.c +23 -9
@@ -125,6 +125,7 @@ #define BINARY_LITERAL_DEFLATED 2unsigned long deflate_origlen;int lines_added, lines_deleted;int score; + int no_accurate_diff:1;struct fragment *fragments;char *result;unsigned long resultsize;
@@ -1333,7 +1334,8 @@ static int apply_line(char *output, consreturn plen; } -static int apply_one_fragment (struct buffer_desc *desc,struct fragment *frag) +static int apply_one_fragment (struct buffer_desc *desc,struct fragment *frag, +int no_accurate_diff) {int match_beginning, match_end;char *buf = desc->buffer;
@@ -1386,13 +1388,11 @@ static int apply_one_fragment(struct buf size -= len; } -#ifdef NO_ACCURATE_DIFF -if (oldsize >0 && old[oldsize -1 ] =='\n' && +if (no_accurate_diff && oldsize >0 && old[oldsize -1 ] =='\n' && newsize >0 && new[newsize -1 ] =='\n' ) { oldsize--; newsize--; } -#endif oldlines = old; newlines = new;
@@ -1614,7 +1614,7 @@ static int apply_fragments(struct bufferreturn apply_binary (desc, patch);while (frag) { -if (apply_one_fragment (desc, frag) <0 ) +if (apply_one_fragment (desc, frag, patch->no_accurate_diff) <0 )return error ("patch failed: %s:%ld" , name, frag->oldpos); frag = frag->next;
@@ -2097,7 +2097,7 @@ static int use_patch(struct patch *p)return 1 ; } -static int apply_patch (int fd,const char *filename) +static int apply_patch (int fd,const char *filename,int no_accurate_diff) {unsigned long offset, size;char *buffer =read_patch_file (fd, &size);
@@ -2113,6 +2113,7 @@ static int apply_patch(int fd, const chaint nr; patch =xcalloc (1 ,sizeof (*patch)); + patch->no_accurate_diff = no_accurate_diff; nr =parse_chunk (buffer + offset, size, patch);if (nr <0 )break ;
@@ -2180,6 +2181,11 @@ int cmd_apply(int argc, const char **arg {int i;int read_stdin =1 ; +#ifdef NO_ACCURATE_DIFF +int no_accurate_diff =1 ; +#else +int no_accurate_diff =0 ; +#endif const char *whitespace_option =NULL ;for (i =1 ; i < argc; i++) {
@@ -2188,7 +2194,7 @@ int cmd_apply(int argc, const char **argint fd;if (!strcmp (arg,"-" )) { -apply_patch (0 ,"<stdin>" ); +apply_patch (0 ,"<stdin>" , no_accurate_diff); read_stdin =0 ;continue ; }
@@ -2265,6 +2271,14 @@ int cmd_apply(int argc, const char **argparse_whitespace_option (arg +13 );continue ; } +if (!strcmp (arg,"--no-accurate-diff" )) { + no_accurate_diff =1 ; +continue ; + } +if (!strcmp (arg,"--accurate-diff" )) { + no_accurate_diff =0 ; +continue ; + }if (check_index && prefix_length <0 ) { prefix =setup_git_directory ();
@@ -2281,12 +2295,12 @@ int cmd_apply(int argc, const char **argusage (apply_usage); read_stdin =0 ;set_default_whitespace_mode (whitespace_option); -apply_patch (fd, arg); +apply_patch (fd, arg, no_accurate_diff);close (fd); }set_default_whitespace_mode (whitespace_option);if (read_stdin) -apply_patch (0 ,"<stdin>" ); +apply_patch (0 ,"<stdin>" , no_accurate_diff);if (whitespace_error) {if (squelch_whitespace_errors && squelch_whitespace_errors < whitespace_error) {
Quoted 3 lines · Johannes Schindelin
My original idea: on a machine where you have no accurate diff, you at least want to pass the tests, and you want to ensure you can apply a diff you generated on that machine.
I remember that, but I think recently we converted t4100 and t4101 to use pregenerated test vectors so it might not be an issue anymore?
Quoted 1 line
This patch is just compile tested, but obviously correct
Looks sane, thanks.
I would maybe rename the option to --inaccurate-eof and default it to off (i.e. no --accurate-eof option). After all we are not talking about arbitrary inaccuracy but the particular botch of not having "\No newline at the end of file."
Hi,
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
My original idea: on a machine where you have no accurate diff, you at least want to pass the tests, and you want to ensure you can apply a diff you generated on that machine.
I remember that, but I think recently we converted t4100 and t4101 to use pregenerated test vectors so it might not be an issue anymore?
Exactly.
Quoted 4 lines
I would maybe rename the option to --inaccurate-eof and default it to off (i.e. no --accurate-eof option). After all we are not talking about arbitrary inaccuracy but the particular botch of not having "\No newline at the end of file."
Sure. Want me to redo the patch?
Ciao,
Dscho
Quoted 2 lines · Petr Baudis
There's a patch to build libgit.so, would you take it as an excuse to always compile with -fPIC? ;-)
The only benerit we might gain from libgit.so in the current shape, aside from making it easier to do .xs, is that multiple git processes would share it in core, and the disk consumption by 100+ little git commands are reduced -- which largely has become non-issue with the recent spurt of making everything built-ins. But that "aside from" is in itself a big plus, so, well, I am torn.
Quoted 8 lines · Petr Baudis
Quoted 8 lines
cc -shared -L/usr/local/lib Git.o -o blib/arch/auto/Git/Git.so ../libgit.a \
-lz -lcrypto \
/usr/bin/ld: ../libgit.a(exec_cmd.o): relocationR_X86_64_32against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../libgit.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [blib/arch/auto/Git/Git.so] Error 1
Quoted 5 lines
Quoted 3 lines
This is a real killer. If we compile everything with -fPIC, this goes away, but I do not think we want -fPIC for the core level tools. At least not until we are ready to do libgit.so.
Hmm, I didn't get that; I guess that's x86-64 specific. :/
So it seems. Both RH machines I have access at kernel.org and Debian machines I have locally exhibit that x86-32 is OK and x86-64 is bad. They all run libc-2.3.6 except RH x86-32 is at libc-2.3.4.
Quoted 14 lines · Junio C Hamano
Quoted 12 lines · Petr Baudis
Quoted 11 lines
cc -shared -L/usr/local/lib Git.o -o blib/arch/auto/Git/Git.so ../libgit.a \
-lz -lcrypto \
/usr/bin/ld: ../libgit.a(exec_cmd.o): relocationR_X86_64_32against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../libgit.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [blib/arch/auto/Git/Git.so] Error 1This is a real killer. If we compile everything with -fPIC, this goes away, but I do not think we want -fPIC for the core level tools. At least not until we are ready to do libgit.so.
Quoted 6 lines
Quoted 1 line
Hmm, I didn't get that; I guess that's x86-64 specific. :/
So it seems. Both RH machines I have access at kernel.org and Debian machines I have locally exhibit that x86-32 is OK and x86-64 is bad. They all run libc-2.3.6 except RH x86-32 is at libc-2.3.4.
Perhaps Git.pm should provide also generic, pure Perl (and slower) fallback implementation (when for some reason we cannot compile XS).
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Dear diary, on Fri, Jun 23, 2006 at 08:03:23AM CEST, I got a letter where Jakub Narebski <[email protected]> said that...
Quoted 2 lines
Perhaps Git.pm should provide also generic, pure Perl (and slower) fallback implementation (when for some reason we cannot compile XS).
I fiercely want to avoid this if there is any other possible way to go about it - this is a path to hell of massive code duplication and additional work, as the number of routines will grow. If it is question of spending many developer-hours uselessly duplicating code in a way that'll be much slower than possible anyway OR building with -fPIC... ;-)
Signature · 3 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ A person is just about as big as the things that make them angry.
Dnia piątek 23. czerwca 2006 14:45, napisałeś:
Quoted 10 lines
Dear diary, on Fri, Jun 23, 2006 at 08:03:23AM CEST, I got a letter where Jakub Narebski <[email protected]> said that...
Quoted 2 lines
Perhaps Git.pm should provide also generic, pure Perl (and slower) fallback implementation (when for some reason we cannot compile XS).
I fiercely want to avoid this if there is any other possible way to go about it - this is a path to hell of massive code duplication and additional work, as the number of routines will grow. If it is question of spending many developer-hours uselessly duplicating code in a way that'll be much slower than possible anyway OR building with -fPIC... ;-)
I have thought about reimplementing only the parts which are in XS. In C one would probably write
#if can_asm
asm (...)
#else
/* C code equivalent */
#endif
In addition to allowing use of Git.pm for people who cannot compile Git.xs, it would be helpful I guess in Git.pm development.
Signature · 2 lines
Jakub Narebski Poland
Quoted 2 lines · Jakub Narebski
Perhaps Git.pm should provide also generic, pure Perl (and slower) fallback implementation (when for some reason we cannot compile XS).
Haven't looked at Git.pm. But I have written receive-pack in perl. It may have some useful functions for Git.pm