Skip to content

Commit

Permalink
Introduce Git.pm (v4)
Browse files Browse the repository at this point in the history
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 <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Petr Baudis authored and Junio C Hamano committed Jul 3, 2006
1 parent 35c636e commit b1edc53
Show file tree
Hide file tree
Showing 6 changed files with 516 additions and 9 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ export prefix TAR INSTALL DESTDIR SHELL_PATH template_dir

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

all:
all: perl/Makefile
$(MAKE) -C perl
$(MAKE) -C templates

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

$(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' \
$@.perl >$@+
chmod +x $@+
Expand Down Expand Up @@ -608,6 +609,9 @@ $(XDIFF_LIB): $(XDIFF_OBJS)
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

Expand Down Expand Up @@ -663,6 +667,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)'; \
Expand Down Expand Up @@ -730,7 +735,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

Expand Down
13 changes: 7 additions & 6 deletions git-fmt-merge-msg.perl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# by grouping branches and tags together to form a single line.

use strict;
use Git;

my $repo = Git->repository();

my @src;
my %src;
Expand All @@ -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";
Expand All @@ -47,11 +49,10 @@ 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, $_;
}
die "git-log failed\n" if $?;
return @result;
}

Expand Down Expand Up @@ -168,6 +169,6 @@ sub shortlog {
print " ...\n";
last;
}
print " $log";
print " $log\n";
}
}
7 changes: 7 additions & 0 deletions perl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Git.bs
Git.c
Makefile
blib
blibdirs
pm_to_blib
ppport.h

0 comments on commit b1edc53

Please sign in to comment.