* [PATCH 0/4] Don't require to be in the repository if we don't need to
@ 2008-03-14 17:29 Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 1/4] var: Don't require to be in a git repository Frank Lichtenheld
2008-03-16 3:55 ` [PATCH 0/4] Don't require to be in the repository if we don't need to Junio C Hamano
0 siblings, 2 replies; 6+ messages in thread
From: Frank Lichtenheld @ 2008-03-14 17:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
Here a small patch series that was based on a user request who wants to be able
to call git send-email from outside of any repository.
I've done some basic testing but more would of course be welcome.
Probably no 1.5.5 material anyway.
Gruesse,
--
Frank Lichtenheld <frank@lichtenheld.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] var: Don't require to be in a git repository.
2008-03-14 17:29 [PATCH 0/4] Don't require to be in the repository if we don't need to Frank Lichtenheld
@ 2008-03-14 17:29 ` Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 2/4] Git.pm: Don't require a repository instance for config Frank Lichtenheld
2008-03-16 3:55 ` [PATCH 0/4] Don't require to be in the repository if we don't need to Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Frank Lichtenheld @ 2008-03-14 17:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List, Frank Lichtenheld
git var works fine even when not called in a git repository. So
don't require it.
This will make it possible to remove this pre-condition for some
other git commands as well.
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de>
---
var.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/var.c b/var.c
index 0de0efa..c20ac91 100644
--- a/var.c
+++ b/var.c
@@ -51,11 +51,12 @@ static int show_config(const char *var, const char *value)
int main(int argc, char **argv)
{
const char *val;
+ int nongit;
if (argc != 2) {
usage(var_usage);
}
- setup_git_directory();
+ setup_git_directory_gently(&nongit);
val = NULL;
if (strcmp(argv[1], "-l") == 0) {
--
1.5.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] Git.pm: Don't require a repository instance for config
2008-03-14 17:29 ` [PATCH 1/4] var: Don't require to be in a git repository Frank Lichtenheld
@ 2008-03-14 17:29 ` Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 3/4] Git.pm: Don't require repository instance for ident Frank Lichtenheld
0 siblings, 1 reply; 6+ messages in thread
From: Frank Lichtenheld @ 2008-03-14 17:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List, Frank Lichtenheld
git config itself doesn't require to be called in a repository,
do don't add arbitrary restrictions.
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de>
---
perl/Git.pm | 33 +++++++++++++--------------------
1 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index a2812ea..67b3749 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -487,22 +487,20 @@ 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('config') so it is not so fast.
=cut
sub config {
- my ($self, $var) = @_;
- $self->repo_path()
- or throw Error::Simple("not a repository");
+ my ($self, $var) = _maybe_self(@_);
try {
+ my @cmd = ('config');
+ unshift @cmd, $self if $self;
if (wantarray) {
- return $self->command('config', '--get-all', $var);
+ return command(@cmd, '--get-all', $var);
} else {
- return $self->command_oneline('config', '--get', $var);
+ return command_oneline(@cmd, '--get', $var);
}
} catch Git::Error::Command with {
my $E = shift;
@@ -522,20 +520,17 @@ Retrieve the bool configuration C<VARIABLE>. The return value
is usable as a boolean in perl (and C<undef> if it's not defined,
of course).
-Must be called on a repository instance.
-
This currently wraps command('config') so it is not so fast.
=cut
sub config_bool {
- my ($self, $var) = @_;
- $self->repo_path()
- or throw Error::Simple("not a repository");
+ my ($self, $var) = _maybe_self(@_);
try {
- my $val = $self->command_oneline('config', '--bool', '--get',
- $var);
+ my @cmd = ('config', '--bool', '--get', $var);
+ unshift @cmd, $self if $self;
+ my $val = command_oneline(@cmd);
return undef unless defined $val;
return $val eq 'true';
} catch Git::Error::Command with {
@@ -557,19 +552,17 @@ or 'g' in the config file will cause the value to be multiplied
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
It would return C<undef> if configuration variable is not defined,
-Must be called on a repository instance.
-
This currently wraps command('config') so it is not so fast.
=cut
sub config_int {
- my ($self, $var) = @_;
- $self->repo_path()
- or throw Error::Simple("not a repository");
+ my ($self, $var) = _maybe_self(@_);
try {
- return $self->command_oneline('config', '--int', '--get', $var);
+ my @cmd = ('config', '--int', '--get', $var);
+ unshift @cmd, $self if $self;
+ return command_oneline(@cmd);
} catch Git::Error::Command with {
my $E = shift;
if ($E->value() == 1) {
--
1.5.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] Git.pm: Don't require repository instance for ident
2008-03-14 17:29 ` [PATCH 2/4] Git.pm: Don't require a repository instance for config Frank Lichtenheld
@ 2008-03-14 17:29 ` Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 4/4] send-email: Don't require to be called in a repository Frank Lichtenheld
0 siblings, 1 reply; 6+ messages in thread
From: Frank Lichtenheld @ 2008-03-14 17:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List, Frank Lichtenheld
git var doesn't require to be called in a repository anymore,
so don't require it either.
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de>
---
perl/Git.pm | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 67b3749..2e7f896 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -632,15 +632,15 @@ The synopsis is like:
"$name <$email>" eq ident_person($name);
$time_tz =~ /^\d+ [+-]\d{4}$/;
-Both methods must be called on a repository instance.
-
=cut
sub ident {
- my ($self, $type) = @_;
+ my ($self, $type) = _maybe_self(@_);
my $identstr;
if (lc $type eq lc 'committer' or lc $type eq lc 'author') {
- $identstr = $self->command_oneline('var', 'GIT_'.uc($type).'_IDENT');
+ my @cmd = ('var', 'GIT_'.uc($type).'_IDENT');
+ unshift @cmd, $self if $self;
+ $identstr = command_oneline(@cmd);
} else {
$identstr = $type;
}
@@ -652,8 +652,8 @@ sub ident {
}
sub ident_person {
- my ($self, @ident) = @_;
- $#ident == 0 and @ident = $self->ident($ident[0]);
+ my ($self, @ident) = _maybe_self(@_);
+ $#ident == 0 and @ident = $self ? $self->ident($ident[0]) : ident($ident[0]);
return "$ident[0] <$ident[1]>";
}
--
1.5.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] send-email: Don't require to be called in a repository
2008-03-14 17:29 ` [PATCH 3/4] Git.pm: Don't require repository instance for ident Frank Lichtenheld
@ 2008-03-14 17:29 ` Frank Lichtenheld
0 siblings, 0 replies; 6+ messages in thread
From: Frank Lichtenheld @ 2008-03-14 17:29 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List, Frank Lichtenheld
We might not have some configuration variables available, but if the
user doesn't care about that, neither should we. Still use the
repository if it is available, though.
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de>
---
git-send-email.perl | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index be4a20d..9e568bf 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -168,7 +168,8 @@ my $envelope_sender;
# Example reply to:
#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
-my $repo = Git->repository();
+my $repo = eval { Git->repository() };
+my @repo = $repo ? ($repo) : ();
my $term = eval {
$ENV{"GIT_SEND_EMAIL_NOTTY"}
? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
@@ -271,25 +272,25 @@ sub read_config {
foreach my $setting (keys %config_bool_settings) {
my $target = $config_bool_settings{$setting}->[0];
- $$target = $repo->config_bool("$prefix.$setting") unless (defined $$target);
+ $$target = Git::config_bool(@repo, "$prefix.$setting") unless (defined $$target);
}
foreach my $setting (keys %config_settings) {
my $target = $config_settings{$setting};
if (ref($target) eq "ARRAY") {
unless (@$target) {
- my @values = $repo->config("$prefix.$setting");
+ my @values = Git::config(@repo, "$prefix.$setting");
@$target = @values if (@values && defined $values[0]);
}
}
else {
- $$target = $repo->config("$prefix.$setting") unless (defined $$target);
+ $$target = Git::config(@repo, "$prefix.$setting") unless (defined $$target);
}
}
}
# read configuration from [sendemail "$identity"], fall back on [sendemail]
-$identity = $repo->config("sendemail.identity") unless (defined $identity);
+$identity = Git::config(@repo, "sendemail.identity") unless (defined $identity);
read_config("sendemail.$identity") if (defined $identity);
read_config("sendemail");
@@ -327,8 +328,9 @@ if (0) {
}
}
-my ($repoauthor) = $repo->ident_person('author');
-my ($repocommitter) = $repo->ident_person('committer');
+my ($repoauthor, $repocommitter);
+($repoauthor) = Git::ident_person(@repo, 'author');
+($repocommitter) = Git::ident_person(@repo, 'committer');
# Verify the user input
@@ -415,7 +417,7 @@ if (@files) {
my $prompting = 0;
if (!defined $sender) {
- $sender = $repoauthor || $repocommitter;
+ $sender = $repoauthor || $repocommitter || '';
while (1) {
$_ = $term->readline("Who should the emails appear to be from? [$sender] ");
@@ -509,7 +511,7 @@ GIT: for the patch you are writing.
EOT
close(C);
- my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
+ my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
system('sh', '-c', '$0 $@', $editor, $compose_filename);
open(C2,">",$compose_filename . ".final")
--
1.5.4.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] Don't require to be in the repository if we don't need to
2008-03-14 17:29 [PATCH 0/4] Don't require to be in the repository if we don't need to Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 1/4] var: Don't require to be in a git repository Frank Lichtenheld
@ 2008-03-16 3:55 ` Junio C Hamano
1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2008-03-16 3:55 UTC (permalink / raw)
To: Frank Lichtenheld; +Cc: Git Mailing List
Frank Lichtenheld <frank@lichtenheld.de> writes:
> Here a small patch series that was based on a user request who wants to
> be able to call git send-email from outside of any repository.
>
> I've done some basic testing but more would of course be welcome.
> Probably no 1.5.5 material anyway.
I am tempted to queue this to 'next', as I think it is a good thing to
do, but there are other users of Git.pm that makes it a bit worrisome.
We'll see if we would want to have it in 'master' before or after 1.5.5
depending on how well it goes.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-03-16 3:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-14 17:29 [PATCH 0/4] Don't require to be in the repository if we don't need to Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 1/4] var: Don't require to be in a git repository Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 2/4] Git.pm: Don't require a repository instance for config Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 3/4] Git.pm: Don't require repository instance for ident Frank Lichtenheld
2008-03-14 17:29 ` [PATCH 4/4] send-email: Don't require to be called in a repository Frank Lichtenheld
2008-03-16 3:55 ` [PATCH 0/4] Don't require to be in the repository if we don't need to Junio C Hamano
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).