Convert git-send-email to use Git.pm
Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
Petr Baudis committed
Jul 3, 2006 at 22:47 UTC
3cb8caf7294bf8909b924ab63ca7d8f90917e677
1 file changed
+8
-22
git-send-email.perl
+8
-22
@@ -21,6 +21,7 @@ use warnings;
21
use Term::ReadLine;
22
use Getopt::Long;
23
use Data::Dumper;
24
+use Git;
25
26
# most mail servers generate the Date: header, but not all...
27
$ENV{LC_ALL} = 'C';
@@ -46,6 +47,8 @@ my $smtp_server;
47
# Example reply to:
48
#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
49
50
+my $repo = Git->repository();
51
+
52
my $term = new Term::ReadLine 'git-send-email';
53
54
# Begin by accumulating all the variables (defined above), that we will end up
@@ -81,23 +84,9 @@ foreach my $entry (@bcclist) {
84
85
# Now, let's fill any that aren't set in with defaults:
86
84
-sub gitvar {
85
- my ($var) = @_;
86
- my $fh;
87
- my $pid = open($fh, '-|');
88
- die "$!" unless defined $pid;
89
- if (!$pid) {
90
- exec('git-var', $var) or die "$!";
91
- }
92
- my ($val) = <$fh>;
93
- close $fh or die "$!";
94
- chomp($val);
95
- return $val;
96
-}
97
-
87
sub gitvar_ident {
88
my ($name) = @_;
100
- my $val = gitvar($name);
89
+ my $val = $repo->command('var', $name);
90
my @field = split(/\s+/, $val);
91
return join(' ', @field[0...(@field-3)]);
92
}
@@ -106,8 +95,8 @@ my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
95
my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
96
97
my %aliases;
109
-chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);
110
-chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
98
+my @alias_files = $repo->config('sendemail.aliasesfile');
99
+my $aliasfiletype = $repo->config('sendemail.aliasfiletype');
100
my %parse_alias = (
101
# multiline formats can be supported in the future
102
mutt => sub { my $fh = shift; while (<$fh>) {
@@ -132,7 +121,7 @@ my %parse_alias = (
121
}}}
122
);
123
135
-if (@alias_files && defined $parse_alias{$aliasfiletype}) {
124
+if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
125
foreach my $file (@alias_files) {
126
open my $fh, '<', $file or die "opening $file: $!\n";
127
$parse_alias{$aliasfiletype}->($fh);
@@ -374,10 +363,7 @@ sub send_message
363
my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));
364
my $gitversion = '@@GIT_VERSION@@';
365
if ($gitversion =~ m/..GIT_VERSION../) {
377
- $gitversion = `git --version`;
378
- chomp $gitversion;
379
- # keep only what's after the last space
380
- $gitversion =~ s/^.* //;
366
+ $gitversion = Git::version();
367
}
368
369
my $header = "From: $from