Skip to content

Commit b1edc53

Browse files
Petr BaudisJunio C Hamano
Petr Baudis
authored and
Junio C Hamano
committed
Introduce Git.pm (v4)
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. I will send them as follow-ups to this patch. 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). Compared to v3, only very minor things were fixed in this patch (some whitespaces, a missing export, tiny bug in git-fmt-merge-msg.perl); at first I wanted to post them as a separate patch but since this is still only in pu, I decided that it will be cleaner to just resend the patch. 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. Signed-off-by: Petr Baudis <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35c636e commit b1edc53

File tree

6 files changed

+516
-9
lines changed

6 files changed

+516
-9
lines changed

Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir
490490

491491
all: $(ALL_PROGRAMS) $(BUILT_INS) git$X gitk
492492

493-
all:
493+
all: perl/Makefile
494+
$(MAKE) -C perl
494495
$(MAKE) -C templates
495496

496497
strip: $(PROGRAMS) git$X
@@ -522,7 +523,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
522523

523524
$(patsubst %.perl,%,$(SCRIPT_PERL)) : % : %.perl
524525
rm -f $@ $@+
525-
sed -e '1s|#!.*perl|#!$(PERL_PATH_SQ)|' \
526+
sed -e '1s|#!.*perl\(.*\)|#!$(PERL_PATH_SQ)\1 -I'"$$(make -s -C perl instlibdir)"'|' \
526527
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
527528
$@.perl >$@+
528529
chmod +x $@+
@@ -608,6 +609,9 @@ $(XDIFF_LIB): $(XDIFF_OBJS)
608609
rm -f $@ && $(AR) rcs $@ $(XDIFF_OBJS)
609610

610611

612+
perl/Makefile: perl/Git.pm perl/Makefile.PL
613+
(cd perl && $(PERL_PATH) Makefile.PL PREFIX="$(prefix)" DEFINE="$(ALL_CFLAGS)" LIBS="$(LIBS)")
614+
611615
doc:
612616
$(MAKE) -C Documentation all
613617

@@ -663,6 +667,7 @@ install: all
663667
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
664668
$(INSTALL) git$X gitk '$(DESTDIR_SQ)$(bindir_SQ)'
665669
$(MAKE) -C templates install
670+
$(MAKE) -C perl install
666671
$(INSTALL) -d -m755 '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'
667672
$(INSTALL) $(PYMODULES) '$(DESTDIR_SQ)$(GIT_PYTHON_DIR_SQ)'
668673
if test 'z$(bindir_SQ)' != 'z$(gitexecdir_SQ)'; \
@@ -730,7 +735,8 @@ clean:
730735
rm -f $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
731736
rm -f $(htmldocs).tar.gz $(manpages).tar.gz
732737
$(MAKE) -C Documentation/ clean
733-
$(MAKE) -C templates clean
738+
[ ! -e perl/Makefile ] || $(MAKE) -C perl/ clean
739+
$(MAKE) -C templates/ clean
734740
$(MAKE) -C t/ clean
735741
rm -f GIT-VERSION-FILE GIT-CFLAGS
736742

git-fmt-merge-msg.perl

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# by grouping branches and tags together to form a single line.
77

88
use strict;
9+
use Git;
10+
11+
my $repo = Git->repository();
912

1013
my @src;
1114
my %src;
@@ -28,13 +31,12 @@ sub andjoin {
2831
}
2932

3033
sub repoconfig {
31-
my ($val) = qx{git-repo-config --get merge.summary};
34+
my ($val) = $repo->command_oneline('repo-config', '--get', 'merge.summary');
3235
return $val;
3336
}
3437

3538
sub current_branch {
36-
my ($bra) = qx{git-symbolic-ref HEAD};
37-
chomp($bra);
39+
my ($bra) = $repo->command_oneline('symbolic-ref', 'HEAD');
3840
$bra =~ s|^refs/heads/||;
3941
if ($bra ne 'master') {
4042
$bra = " into $bra";
@@ -47,11 +49,10 @@ sub current_branch {
4749
sub shortlog {
4850
my ($tip) = @_;
4951
my @result;
50-
foreach ( qx{git-log --no-merges --topo-order --pretty=oneline $tip ^HEAD} ) {
52+
foreach ($repo->command('log', '--no-merges', '--topo-order', '--pretty=oneline', $tip, '^HEAD')) {
5153
s/^[0-9a-f]{40}\s+//;
5254
push @result, $_;
5355
}
54-
die "git-log failed\n" if $?;
5556
return @result;
5657
}
5758

@@ -168,6 +169,6 @@ sub shortlog {
168169
print " ...\n";
169170
last;
170171
}
171-
print " $log";
172+
print " $log\n";
172173
}
173174
}

perl/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Git.bs
2+
Git.c
3+
Makefile
4+
blib
5+
blibdirs
6+
pm_to_blib
7+
ppport.h

0 commit comments

Comments
 (0)