{"thread":{"id":"4654","subject":"[PATCH 2/2] Convert git-send-email to use Git.pm","startedAt":"2006-06-24T14:34:21Z","lastAt":"2006-06-24T14:34:23Z","messageCount":2,"participants":["Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"22454","messageId":"20060624143421.13849.21667.stgit@machine.or.cz","threadId":"4654","inReplyTo":null,"subject":"[PATCH 1/2] Git.pm: Add config() method","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T14:34:21Z","receivedAt":"2006-06-24T14:34:21Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"This accessor will retrieve value(s) of the given configuration variable.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n Documentation/git-repo-config.txt |    3 ++-\n perl/Git.pm                       |   37 ++++++++++++++++++++++++++++++++++++-\n repo-config.c                     |    2 +-\n 3 files changed, 39 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt\nindex 803c0d5..cc72fa9 100644\n--- a/Documentation/git-repo-config.txt\n+++ b/Documentation/git-repo-config.txt\n@@ -54,7 +54,8 @@ OPTIONS\n \n --get::\n \tGet the value for a given key (optionally filtered by a regex\n-\tmatching the value).\n+\tmatching the value). Returns error code 1 if the key was not\n+\tfound and error code 2 if multiple key values were found.\n \n --get-all::\n \tLike get, but does not fail if the number of values for the key\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 7bbb5be..2e1241b 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -472,7 +472,6 @@ and the directory must exist.\n \n sub wc_chdir {\n \tmy ($self, $subdir) = @_;\n-\n \t$self->wc_path()\n \t\tor throw Error::Simple(\"bare repository\");\n \n@@ -485,6 +484,42 @@ sub wc_chdir {\n }\n \n \n+=item config ( VARIABLE )\n+\n+Retrieve the configuration C<VARIABLE> in the same manner as C<repo-config>\n+does. In scalar context requires the variable to be set only one time\n+(exception is thrown otherwise), in array context returns allows the\n+variable to be set multiple times and returns all the values.\n+\n+Must be called on a repository instance.\n+\n+This currently wraps command('repo-config') so it is not so fast.\n+\n+=cut\n+\n+sub config {\n+\tmy ($self, $var) = @_;\n+\t$self->repo_path()\n+\t\tor throw Error::Simple(\"not a repository\");\n+\n+\ttry {\n+\t\tif (wantarray) {\n+\t\t\treturn $self->command('repo-config', '--get-all', $var);\n+\t\t} else {\n+\t\t\treturn $self->command_oneline('repo-config', '--get', $var);\n+\t\t}\n+\t} catch Git::Error::Command with {\n+\t\tmy $E = shift;\n+\t\tif ($E->value() == 1) {\n+\t\t\t# Key not found.\n+\t\t\treturn undef;\n+\t\t} else {\n+\t\t\tthrow $E;\n+\t\t}\n+\t};\n+}\n+\n+\n =item hash_object ( FILENAME [, TYPE ] )\n \n =item hash_object ( FILEHANDLE [, TYPE ] )\ndiff --git a/repo-config.c b/repo-config.c\nindex ab8f1af..346fb14 100644\n--- a/repo-config.c\n+++ b/repo-config.c\n@@ -121,7 +121,7 @@ static int get_value(const char* key_, c\n \tif (do_all)\n \t\tret = !seen;\n \telse\n-\t\tret =  (seen == 1) ? 0 : 1;\n+\t\tret = (seen == 1) ? 0 : seen > 1 ? 2 : 1;\n \n free_strings:\n \tif (repo_config)\n"},{"id":"22453","messageId":"20060624143423.13849.8400.stgit@machine.or.cz","threadId":"4654","inReplyTo":"20060624143421.13849.21667.stgit@machine.or.cz","subject":"[PATCH 2/2] Convert git-send-email to use Git.pm","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-06-24T14:34:23Z","receivedAt":"2006-06-24T14:34:23Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Signed-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n git-send-email.perl |   30 ++++++++----------------------\n 1 files changed, 8 insertions(+), 22 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex c5d9e73..e794e44 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -21,6 +21,7 @@ use warnings;\n use Term::ReadLine;\n use Getopt::Long;\n use Data::Dumper;\n+use Git;\n \n # most mail servers generate the Date: header, but not all...\n $ENV{LC_ALL} = 'C';\n@@ -46,6 +47,8 @@ my $smtp_server;\n # Example reply to:\n #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';\n \n+my $repo = Git->repository();\n+\n my $term = new Term::ReadLine 'git-send-email';\n \n # Begin by accumulating all the variables (defined above), that we will end up\n@@ -81,23 +84,9 @@ foreach my $entry (@bcclist) {\n \n # Now, let's fill any that aren't set in with defaults:\n \n-sub gitvar {\n-    my ($var) = @_;\n-    my $fh;\n-    my $pid = open($fh, '-|');\n-    die \"$!\" unless defined $pid;\n-    if (!$pid) {\n-\texec('git-var', $var) or die \"$!\";\n-    }\n-    my ($val) = <$fh>;\n-    close $fh or die \"$!\";\n-    chomp($val);\n-    return $val;\n-}\n-\n sub gitvar_ident {\n     my ($name) = @_;\n-    my $val = gitvar($name);\n+    my $val = $repo->command('var', $name);\n     my @field = split(/\\s+/, $val);\n     return join(' ', @field[0...(@field-3)]);\n }\n@@ -106,8 +95,8 @@ my ($author) = gitvar_ident('GIT_AUTHOR_\n my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');\n \n my %aliases;\n-chomp(my @alias_files = `git-repo-config --get-all sendemail.aliasesfile`);\n-chomp(my $aliasfiletype = `git-repo-config sendemail.aliasfiletype`);\n+my @alias_files = $repo->config('sendemail.aliasesfile');\n+my $aliasfiletype = $repo->config('sendemail.aliasfiletype');\n my %parse_alias = (\n \t# multiline formats can be supported in the future\n \tmutt => sub { my $fh = shift; while (<$fh>) {\n@@ -132,7 +121,7 @@ my %parse_alias = (\n \t\t}}}\n );\n \n-if (@alias_files && defined $parse_alias{$aliasfiletype}) {\n+if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {\n \tforeach my $file (@alias_files) {\n \t\topen my $fh, '<', $file or die \"opening $file: $!\\n\";\n \t\t$parse_alias{$aliasfiletype}->($fh);\n@@ -374,10 +363,7 @@ sub send_message\n \tmy $date = strftime('%a, %d %b %Y %H:%M:%S %z', localtime($time++));\n \tmy $gitversion = '@@GIT_VERSION@@';\n \tif ($gitversion =~ m/..GIT_VERSION../) {\n-\t    $gitversion = `git --version`;\n-\t    chomp $gitversion;\n-\t    # keep only what's after the last space\n-\t    $gitversion =~ s/^.* //;\n+\t    $gitversion = Git::version();\n \t}\n \n \tmy $header = \"From: $from\n"}]}