* [PATCH 1/2] Git.pm: Add config() method
@ 2006-06-24 14:34 Petr Baudis
2006-06-24 14:34 ` [PATCH 2/2] Convert git-send-email to use Git.pm Petr Baudis
0 siblings, 1 reply; 2+ messages in thread
From: Petr Baudis @ 2006-06-24 14:34 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This accessor will retrieve value(s) of the given configuration variable.
Signed-off-by: Petr Baudis <pasky@suse.cz>
---
Documentation/git-repo-config.txt | 3 ++-
perl/Git.pm | 37 ++++++++++++++++++++++++++++++++++++-
repo-config.c | 2 +-
3 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt
index 803c0d5..cc72fa9 100644
--- a/Documentation/git-repo-config.txt
+++ b/Documentation/git-repo-config.txt
@@ -54,7 +54,8 @@ OPTIONS
--get::
Get the value for a given key (optionally filtered by a regex
- matching the value).
+ matching the value). Returns error code 1 if the key was not
+ found and error code 2 if multiple key values were found.
--get-all::
Like get, but does not fail if the number of values for the key
diff --git a/perl/Git.pm b/perl/Git.pm
index 7bbb5be..2e1241b 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -472,7 +472,6 @@ and the directory must exist.
sub wc_chdir {
my ($self, $subdir) = @_;
-
$self->wc_path()
or throw Error::Simple("bare repository");
@@ -485,6 +484,42 @@ sub wc_chdir {
}
+=item config ( VARIABLE )
+
+Retrieve the configuration C<VARIABLE> in the same manner as C<repo-config>
+does. In scalar context requires the variable to be set only one time
+(exception is thrown otherwise), in array context returns allows the
+variable to be set multiple times and returns all the values.
+
+Must be called on a repository instance.
+
+This currently wraps command('repo-config') so it is not so fast.
+
+=cut
+
+sub config {
+ my ($self, $var) = @_;
+ $self->repo_path()
+ or throw Error::Simple("not a repository");
+
+ try {
+ if (wantarray) {
+ return $self->command('repo-config', '--get-all', $var);
+ } else {
+ return $self->command_oneline('repo-config', '--get', $var);
+ }
+ } catch Git::Error::Command with {
+ my $E = shift;
+ if ($E->value() == 1) {
+ # Key not found.
+ return undef;
+ } else {
+ throw $E;
+ }
+ };
+}
+
+
=item hash_object ( FILENAME [, TYPE ] )
=item hash_object ( FILEHANDLE [, TYPE ] )
diff --git a/repo-config.c b/repo-config.c
index ab8f1af..346fb14 100644
--- a/repo-config.c
+++ b/repo-config.c
@@ -121,7 +121,7 @@ static int get_value(const char* key_, c
if (do_all)
ret = !seen;
else
- ret = (seen == 1) ? 0 : 1;
+ ret = (seen == 1) ? 0 : seen > 1 ? 2 : 1;
free_strings:
if (repo_config)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] Convert git-send-email to use Git.pm
2006-06-24 14:34 [PATCH 1/2] Git.pm: Add config() method Petr Baudis
@ 2006-06-24 14:34 ` Petr Baudis
0 siblings, 0 replies; 2+ messages in thread
From: Petr Baudis @ 2006-06-24 14:34 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Signed-off-by: Petr Baudis <pasky@suse.cz>
---
git-send-email.perl | 30 ++++++++----------------------
1 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index c5d9e73..e794e44 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -21,6 +21,7 @@ use warnings;
use Term::ReadLine;
use Getopt::Long;
use Data::Dumper;
+use Git;
# most mail servers generate the Date: header, but not all...
$ENV{LC_ALL} = 'C';
@@ -46,6 +47,8 @@ my $smtp_server;
# Example reply to:
#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
+my $repo = Git->repository();
+
my $term = new Term::ReadLine 'git-send-email';
# Begin by accumulating all the variables (defined above), that we will end up
@@ -81,23 +84,9 @@ foreach my $entry (@bcclist) {
# Now, let's fill any that aren't set in with defaults:
-sub gitvar {
- my ($var) = @_;
- my $fh;
- my $pid = open($fh, '-|');
- die "$!" unless defined $pid;
- if (!$pid) {
- exec('git-var', $var) or die "$!";
- }
- my ($val) = <$fh>;
- close $fh or die "$!";
- chomp($val);
- return $val;
-}
-
sub gitvar_ident {
my ($name) = @_;
- my $val = gitvar($name);
+ my $val = $repo->command('var', $name);
my @field = split(/\s+/, $val);
return join(' ', @field[0...(@field-3)]);
}
@@ -106,8 +95,8 @@ my ($author) = gitvar_ident('GIT_AUTHOR_
my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
my %aliases;
-chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);
-chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);
+my @alias_files = $repo->config('sendemail.aliasesfile');
+my $aliasfiletype = $repo->config('sendemail.aliasfiletype');
my %parse_alias = (
# multiline formats can be supported in the future
mutt => sub { my $fh = shift; while (<$fh>) {
@@ -132,7 +121,7 @@ my %parse_alias = (
}}}
);
-if (@alias_files && defined $parse_alias{$aliasfiletype}) {
+if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
foreach my $file (@alias_files) {
open my $fh, '<', $file or die "opening $file: $!\n";
$parse_alias{$aliasfiletype}->($fh);
@@ -374,10 +363,7 @@ sub send_message
my $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));
my $gitversion = '@@GIT_VERSION@@';
if ($gitversion =~ m/..GIT_VERSION../) {
- $gitversion = `git --version`;
- chomp $gitversion;
- # keep only what's after the last space
- $gitversion =~ s/^.* //;
+ $gitversion = Git::version();
}
my $header = "From: $from
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-06-24 14:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-24 14:34 [PATCH 1/2] Git.pm: Add config() method Petr Baudis
2006-06-24 14:34 ` [PATCH 2/2] Convert git-send-email to use Git.pm Petr Baudis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).