{"thread":{"id":"12695","subject":"[PATCH 2/4] Git.pm: Don't require a repository instance for config","startedAt":"2008-03-14T17:29:26Z","lastAt":"2008-03-16T03:55:43Z","messageCount":6,"participants":["Frank Lichtenheld","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"72114","messageId":"1205515770-3424-1-git-send-email-frank@lichtenheld.de","threadId":"12695","inReplyTo":null,"subject":"[PATCH 0/4] Don't require to be in the repository if we don't need to","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2008-03-14T17:29:26Z","receivedAt":"2008-03-14T17:29:26Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"Here a small patch series that was based on a user request who wants to be able\nto call git send-email from outside of any repository.\n\nI've done some basic testing but more would of course be welcome.\nProbably no 1.5.5 material anyway.\n\nGruesse,\n-- \nFrank Lichtenheld <frank@lichtenheld.de>\n"},{"id":"72117","messageId":"1205515770-3424-2-git-send-email-frank@lichtenheld.de","threadId":"12695","inReplyTo":"1205515770-3424-1-git-send-email-frank@lichtenheld.de","subject":"[PATCH 1/4] var: Don't require to be in a git repository.","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2008-03-14T17:29:27Z","receivedAt":"2008-03-14T17:29:27Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"git var works fine even when not called in a git repository. So\ndon't require it.\n\nThis will make it possible to remove this pre-condition for some\nother git commands as well.\n\nSigned-off-by: Frank Lichtenheld <frank@lichtenheld.de>\n---\n var.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/var.c b/var.c\nindex 0de0efa..c20ac91 100644\n--- a/var.c\n+++ b/var.c\n@@ -51,11 +51,12 @@ static int show_config(const char *var, const char *value)\n int main(int argc, char **argv)\n {\n \tconst char *val;\n+\tint nongit;\n \tif (argc != 2) {\n \t\tusage(var_usage);\n \t}\n \n-\tsetup_git_directory();\n+\tsetup_git_directory_gently(&nongit);\n \tval = NULL;\n \n \tif (strcmp(argv[1], \"-l\") == 0) {\n-- \n1.5.4.4\n"},{"id":"72113","messageId":"1205515770-3424-3-git-send-email-frank@lichtenheld.de","threadId":"12695","inReplyTo":"1205515770-3424-2-git-send-email-frank@lichtenheld.de","subject":"[PATCH 2/4] Git.pm: Don't require a repository instance for config","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2008-03-14T17:29:28Z","receivedAt":"2008-03-14T17:29:28Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"git config itself doesn't require to be called in a repository,\ndo don't add arbitrary restrictions.\n\nSigned-off-by: Frank Lichtenheld <frank@lichtenheld.de>\n---\n perl/Git.pm |   33 +++++++++++++--------------------\n 1 files changed, 13 insertions(+), 20 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex a2812ea..67b3749 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -487,22 +487,20 @@ 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('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+\tmy ($self, $var) = _maybe_self(@_);\n \n \ttry {\n+\t\tmy @cmd = ('config');\n+\t\tunshift @cmd, $self if $self;\n \t\tif (wantarray) {\n-\t\t\treturn $self->command('config', '--get-all', $var);\n+\t\t\treturn command(@cmd, '--get-all', $var);\n \t\t} else {\n-\t\t\treturn $self->command_oneline('config', '--get', $var);\n+\t\t\treturn command_oneline(@cmd, '--get', $var);\n \t\t}\n \t} catch Git::Error::Command with {\n \t\tmy $E = shift;\n@@ -522,20 +520,17 @@ Retrieve the bool configuration C<VARIABLE>. The return value\n is usable as a boolean in perl (and C<undef> if it's not defined,\n of course).\n \n-Must be called on a repository instance.\n-\n This currently wraps command('config') so it is not so fast.\n \n =cut\n \n sub config_bool {\n-\tmy ($self, $var) = @_;\n-\t$self->repo_path()\n-\t\tor throw Error::Simple(\"not a repository\");\n+\tmy ($self, $var) = _maybe_self(@_);\n \n \ttry {\n-\t\tmy $val = $self->command_oneline('config', '--bool', '--get',\n-\t\t\t\t\t      $var);\n+\t\tmy @cmd = ('config', '--bool', '--get', $var);\n+\t\tunshift @cmd, $self if $self;\n+\t\tmy $val = command_oneline(@cmd);\n \t\treturn undef unless defined $val;\n \t\treturn $val eq 'true';\n \t} catch Git::Error::Command with {\n@@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied\n by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.\n It would return C<undef> if configuration variable is not defined,\n \n-Must be called on a repository instance.\n-\n This currently wraps command('config') so it is not so fast.\n \n =cut\n \n sub config_int {\n-\tmy ($self, $var) = @_;\n-\t$self->repo_path()\n-\t\tor throw Error::Simple(\"not a repository\");\n+\tmy ($self, $var) = _maybe_self(@_);\n \n \ttry {\n-\t\treturn $self->command_oneline('config', '--int', '--get', $var);\n+\t\tmy @cmd = ('config', '--int', '--get', $var);\n+\t\tunshift @cmd, $self if $self;\n+\t\treturn command_oneline(@cmd);\n \t} catch Git::Error::Command with {\n \t\tmy $E = shift;\n \t\tif ($E->value() == 1) {\n-- \n1.5.4.4\n"},{"id":"72115","messageId":"1205515770-3424-4-git-send-email-frank@lichtenheld.de","threadId":"12695","inReplyTo":"1205515770-3424-3-git-send-email-frank@lichtenheld.de","subject":"[PATCH 3/4] Git.pm: Don't require repository instance for ident","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2008-03-14T17:29:29Z","receivedAt":"2008-03-14T17:29:29Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"git var doesn't require to be called in a repository anymore,\nso don't require it either.\n\nSigned-off-by: Frank Lichtenheld <frank@lichtenheld.de>\n---\n perl/Git.pm |   12 ++++++------\n 1 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 67b3749..2e7f896 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -632,15 +632,15 @@ The synopsis is like:\n \t\"$name <$email>\" eq ident_person($name);\n \t$time_tz =~ /^\\d+ [+-]\\d{4}$/;\n \n-Both methods must be called on a repository instance.\n-\n =cut\n \n sub ident {\n-\tmy ($self, $type) = @_;\n+\tmy ($self, $type) = _maybe_self(@_);\n \tmy $identstr;\n \tif (lc $type eq lc 'committer' or lc $type eq lc 'author') {\n-\t\t$identstr = $self->command_oneline('var', 'GIT_'.uc($type).'_IDENT');\n+\t\tmy @cmd = ('var', 'GIT_'.uc($type).'_IDENT');\n+\t\tunshift @cmd, $self if $self;\n+\t\t$identstr = command_oneline(@cmd);\n \t} else {\n \t\t$identstr = $type;\n \t}\n@@ -652,8 +652,8 @@ sub ident {\n }\n \n sub ident_person {\n-\tmy ($self, @ident) = @_;\n-\t$#ident == 0 and @ident = $self->ident($ident[0]);\n+\tmy ($self, @ident) = _maybe_self(@_);\n+\t$#ident == 0 and @ident = $self ? $self->ident($ident[0]) : ident($ident[0]);\n \treturn \"$ident[0] <$ident[1]>\";\n }\n \n-- \n1.5.4.4\n"},{"id":"72116","messageId":"1205515770-3424-5-git-send-email-frank@lichtenheld.de","threadId":"12695","inReplyTo":"1205515770-3424-4-git-send-email-frank@lichtenheld.de","subject":"[PATCH 4/4] send-email: Don't require to be called in a repository","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2008-03-14T17:29:30Z","receivedAt":"2008-03-14T17:29:30Z","isPatch":true,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"We might not have some configuration variables available, but if the\nuser doesn't care about that, neither should we. Still use the\nrepository if it is available, though.\n\nSigned-off-by: Frank Lichtenheld <frank@lichtenheld.de>\n---\n git-send-email.perl |   20 +++++++++++---------\n 1 files changed, 11 insertions(+), 9 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex be4a20d..9e568bf 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -168,7 +168,8 @@ my $envelope_sender;\n # Example reply to:\n #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';\n \n-my $repo = Git->repository();\n+my $repo = eval { Git->repository() };\n+my @repo = $repo ? ($repo) : ();\n my $term = eval {\n \t$ENV{\"GIT_SEND_EMAIL_NOTTY\"}\n \t\t? new Term::ReadLine 'git-send-email', \\*STDIN, \\*STDOUT\n@@ -271,25 +272,25 @@ sub read_config {\n \n \tforeach my $setting (keys %config_bool_settings) {\n \t\tmy $target = $config_bool_settings{$setting}->[0];\n-\t\t$$target = $repo->config_bool(\"$prefix.$setting\") unless (defined $$target);\n+\t\t$$target = Git::config_bool(@repo, \"$prefix.$setting\") unless (defined $$target);\n \t}\n \n \tforeach my $setting (keys %config_settings) {\n \t\tmy $target = $config_settings{$setting};\n \t\tif (ref($target) eq \"ARRAY\") {\n \t\t\tunless (@$target) {\n-\t\t\t\tmy @values = $repo->config(\"$prefix.$setting\");\n+\t\t\t\tmy @values = Git::config(@repo, \"$prefix.$setting\");\n \t\t\t\t@$target = @values if (@values && defined $values[0]);\n \t\t\t}\n \t\t}\n \t\telse {\n-\t\t\t$$target = $repo->config(\"$prefix.$setting\") unless (defined $$target);\n+\t\t\t$$target = Git::config(@repo, \"$prefix.$setting\") unless (defined $$target);\n \t\t}\n \t}\n }\n \n # read configuration from [sendemail \"$identity\"], fall back on [sendemail]\n-$identity = $repo->config(\"sendemail.identity\") unless (defined $identity);\n+$identity = Git::config(@repo, \"sendemail.identity\") unless (defined $identity);\n read_config(\"sendemail.$identity\") if (defined $identity);\n read_config(\"sendemail\");\n \n@@ -327,8 +328,9 @@ if (0) {\n \t}\n }\n \n-my ($repoauthor) = $repo->ident_person('author');\n-my ($repocommitter) = $repo->ident_person('committer');\n+my ($repoauthor, $repocommitter);\n+($repoauthor) = Git::ident_person(@repo, 'author');\n+($repocommitter) = Git::ident_person(@repo, 'committer');\n \n # Verify the user input\n \n@@ -415,7 +417,7 @@ if (@files) {\n \n my $prompting = 0;\n if (!defined $sender) {\n-\t$sender = $repoauthor || $repocommitter;\n+\t$sender = $repoauthor || $repocommitter || '';\n \n \twhile (1) {\n \t\t$_ = $term->readline(\"Who should the emails appear to be from? [$sender] \");\n@@ -509,7 +511,7 @@ GIT: for the patch you are writing.\n EOT\n \tclose(C);\n \n-\tmy $editor = $ENV{GIT_EDITOR} || $repo->config(\"core.editor\") || $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n+\tmy $editor = $ENV{GIT_EDITOR} || Git::config(@repo, \"core.editor\") || $ENV{VISUAL} || $ENV{EDITOR} || \"vi\";\n \tsystem('sh', '-c', '$0 $@', $editor, $compose_filename);\n \n \topen(C2,\">\",$compose_filename . \".final\")\n-- \n1.5.4.4\n"},{"id":"72202","messageId":"7vy78jl3uo.fsf@gitster.siamese.dyndns.org","threadId":"12695","inReplyTo":"1205515770-3424-1-git-send-email-frank@lichtenheld.de","subject":"Re: [PATCH 0/4] Don't require to be in the repository if we don't need to","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-16T03:55:43Z","receivedAt":"2008-03-16T03:55:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Frank Lichtenheld <frank@lichtenheld.de> writes:\n\n> Here a small patch series that was based on a user request who wants to\n> be able to call git send-email from outside of any repository.\n>\n> I've done some basic testing but more would of course be welcome.\n> Probably no 1.5.5 material anyway.\n\nI am tempted to queue this to 'next', as I think it is a good thing to\ndo, but there are other users of Git.pm that makes it a bit worrisome.\nWe'll see if we would want to have it in 'master' before or after 1.5.5\ndepending on how well it goes.\n"}]}