Git.pm: config_boolean() -> config_bool()
Subsystems (2)
PATCH 1/4 Git.pm: config_boolean() -> config_bool()
This patch renames config_boolean() to config_bool() for consistency with the commandline interface and because it is shorter but still obvious. ;-) It also changes the return value from some obscure string to real Perl boolean, allowing for clean user code.
---
git-remote.perl | 4 ++-- perl/Git.pm | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
git-remote.perl +2 -2
@@ -297,9 +297,9 @@ sub update_remote { } elsif ($name eq 'default') { undef @remotes; for (sort keys %$remote) { - my $do_fetch = $git->config_boolean("remote." . $_ . + my $do_fetch = $git->config_bool("remote." . $_ . ".skipDefaultUpdate"); - if (!defined($do_fetch) || $do_fetch ne "true") { + unless ($do_fetch) { push @remotes, $_; } }
perl/Git.pm +8 -4
@@ -516,9 +516,11 @@ sub config { } -=item config_boolean ( VARIABLE ) +=item config_bool ( VARIABLE ) -Retrieve the boolean configuration C<VARIABLE>. +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.
@@ -526,14 +528,16 @@ This currently wraps command('config') s =cut -sub config_boolean { +sub config_bool { my ($self, $var) = @_; $self->repo_path() or throw Error::Simple("not a repository"); try { - return $self->command_oneline('config', '--bool', '--get', + my $var = $self->command_oneline('config', '--bool', '--get', $var); + return undef unless defined $var; + return $var eq 'true'; } catch Git::Error::Command with { my $E = shift; if ($E->value() == 1) {
PATCH 2/4 Git.pm: Add remote_refs() git-ls-remote frontend
Should support all the important features, I guess. Too bad that
git-ls-remote --heads .
is subtly different from
git-ls-remote . refs/heads/
so we have to provide the interface for specifying both.
This patch also converts git-svn.perl to use it.
---
git-remote.perl | 5 +---- perl/Git.pm | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-)
git-remote.perl +1 -4
@@ -128,10 +128,7 @@ sub update_ls_remote { return if (($harder == 0) || (($harder == 1) && exists $info->{'LS_REMOTE'})); - my @ref = map { - s|^[0-9a-f]{40}\s+refs/heads/||; - $_; - } $git->command(qw(ls-remote --heads), $info->{'URL'}); + my @ref = keys %{$git->remote_refs($info->{'URL'}, [ 'heads' ])}; $info->{'LS_REMOTE'} = \@ref; }
perl/Git.pm +54 -1
67 lines not on this page · raw message
PATCH 3/4 git-mirror - exactly mirror another repository
In reply to Petr BaudisSometimes its handy to be able to efficiently backup or mirror one Git repository to another Git repository by employing the native Git object transfer protocol. But when mirroring or backing up a repository you really want:
1) Every object in the source to go to the mirror.
2) Every ref in the source to go to the mirror.
3) Any ref removed from the source to be removed from the mirror.
and since git-fetch doesn't do 2 and 3, here's a tool that does.
This is based on Shawn Pearce's patch from 25 Sep 2006, updated to take Junio's and Sergey's review into account, to use few newer pieces of Git infrastructure and with few trivial tweaks. The repacking part was dropped since git-fetch does that on its own now.
I actually still would kind of prefer this to be a git-fetch's feature but the general mood seems to be to have this as a separate command and I can't say I care at all.
---
.gitignore | 1 Documentation/config.txt | 6 ++ Documentation/git-mirror.txt | 54 +++++++++++++++++++++ Makefile | 2 - git-mirror.perl | 110 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 1 deletions(-)
.gitignore +1 -0
@@ -80,6 +80,7 @@ git-merge-resolve git-merge-stupid git-merge-subtree git-mergetool +git-mirror git-mktag git-mktree git-name-rev
Documentation/config.txt +6 -0
@@ -513,6 +513,12 @@ log.showroot:: Tools like gitlink:git-log[1] or gitlink:git-whatchanged[1], which normally hide the root commit will now show it. True by default. +mirror.allowed:: + If true, gitlink:git-mirror[1] will be allowed to run on the + repository. Please see its documentation for all the implications. + +mirror. + merge.summary:: Whether to include summaries of merged commits in newly created merge commit messages. False by default.
Documentation/git-mirror.txt new file +54 -0
54 lines not on this page · raw message
Makefile +1 -1
@@ -208,7 +208,7 @@ SCRIPT_PERL = \ git-archimport.perl git-cvsimport.perl git-relink.perl \ git-cvsserver.perl git-remote.perl \ git-svnimport.perl git-cvsexportcommit.perl \ - git-send-email.perl git-svn.perl + git-send-email.perl git-svn.perl git-mirror.perl SCRIPT_PYTHON = \ git-p4import.py
git-mirror.perl new file +110 -0
110 lines not on this page · raw message
Re: [PATCH 3/4] [PATCH] git-mirror - exactly mirror another repository
Quoted 5 lines · Petr Baudis
Documentation/config.txt +0
-0
Documentation/config.txt log.showroot:: · line 521
Quoted 9 lines
Documentation/config.txt +6
-0@@ -513,6 +513,12 @@ log.showroot:: Tools like gitlink:git-log[1] or gitlink:git-whatchanged[1], which normally hide the root commit will now show it. True by default. +mirror.allowed:: + If true, gitlink:git-mirror[1] will be allowed to run on the + repository. Please see its documentation for all the implications. + +mirror. +
Uhhh.... what's that mirror. line for?
Documentation/config.txt log.showroot:: · line 522
Quoted 1 line
Documentation/config.txt +1
-0+++ b/git-mirror.perl
Otherwise, Ack'd.
Signature · 1 line
Shawn.
PATCH 4/4 server info: Add HEAD to info/refs
In reply to Petr BaudisFor some reason, HEAD was not listed in info/refs until now, which means that git-ls-remote does not return it for dumb transports while the native transports show it. It would be nice to have it because of git-mirror and possibly other nifty stuff.
---
server-info.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
server-info.c +1 -0
@@ -36,6 +36,7 @@ static int update_info_refs(int force) info_ref_fp =fopen (path1,"w" );if (!info_ref_fp)return error ("unable to update %s" , path0); +head_ref (add_info_ref,NULL );for_each_ref (add_info_ref,NULL );fclose (info_ref_fp);rename (path1, path0);
Re: [PATCH 4/4] server info: Add HEAD to info/refs
Quoted 4 lines · Petr Baudis
For some reason, HEAD was not listed in info/refs until now, which means that git-ls-remote does not return it for dumb transports while the native transports show it. It would be nice to have it because of git-mirror and possibly other nifty stuff.
Hmmm. I know why you want to do this, but honestly speaking, this is going somewhat backwards. Maybe one step back, before going two steps forward.
I always considered it was a bug that the native transport sends SHA-1 of HEAD after dereferencing the symref, instead of saying which branch it points at. You would understand (or more likely, "remember", as I suspect you have in the past looked at what git-clone does and git-clone-pack used to do) what yuck factor this introduced to git-clone.
The info/refs files is designed to mimick peek-remote output (I know you looked at ls-remote implementation that has "case-esac" that switches on transport, whose output is piped to the same filtering loop), but HEAD SHA-1 is not needed in this file to support dumb transports, as we try to read HEAD symref by hand when cloning over http.
Longer term, I would want to have a protocol extension to the native stuff to additionally send the symref information, so that git-clone does not have to guess. At the same time, we would probably want to update the output from git-peek-remote so that it can say which branch HEAD points at more explicitly, and in such way that does not break older clients too badly. We would need to update the file format of info/refs at the same time if we update git-peek-remote.
How about proceeding along these lines?
* We take this patch to add HEAD SHA-1 to info/refs;
* We add --symref option to git-ls-remote; without the option, its last "while read sha1 path" loop filters out lines that begin with "->";
* We add native protocol extension to let upload-pack to say what HEAD symref points at, in addition to the SHA-1 HEAD points at. Update peek-remote to show this information like this:
->refs/heads/master<TAB>HEAD<LF>
0d5e6c97...<TAB>HEAD<LF>
...* We also enhance update-server-info to generate similar -> information.
* We update git-clone to use --symref when it calls git-ls-remote; if it can figure out which branch the remote HEAD points at (because the remote side has newer git), it uses that information to set the HEAD branch instead of guessing.
Hmm?
Re: [PATCH 4/4] server info: Add HEAD to info/refs
Quoted 3 lines · Junio C Hamano
I always considered it was a bug that the native transport sends SHA-1 of HEAD after dereferencing the symref, instead of saying which branch it points at.
Yes, you are right. That was what I was originally after, but then got sidetracked into working on something else and this easy bit was the only thing left done, so I just passed it along. :)
Quoted 1 line
How about proceeding along these lines?
Looks generally good.
Quoted 8 lines
* We add native protocol extension to let upload-pack to say what HEAD symref points at, in addition to the SHA-1 HEAD points at. Update peek-remote to show this information like this:
->refs/heads/master<TAB>HEAD<LF> 0d5e6c97...<TAB>HEAD<LF> ...
Yet another obscure syntax? Why not just reusing the actual ref: syntax?
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Ever try. Ever fail. No matter. // Try again. Fail again. Fail better. -- Samuel Beckett
Re: [PATCH 4/4] server info: Add HEAD to info/refs
Quoted 18 lines · Petr Baudis
Quoted 3 lines · Junio C Hamano
I always considered it was a bug that the native transport sends SHA-1 of HEAD after dereferencing the symref, instead of saying which branch it points at.
Yes, you are right. That was what I was originally after, but then got sidetracked into working on something else and this easy bit was the only thing left done, so I just passed it along. :)
Quoted 1 line
How about proceeding along these lines?
Looks generally good.
Quoted 5 lines
* We add native protocol extension to let upload-pack to say what HEAD symref points at, in addition to the SHA-1 HEAD points at. Update peek-remote to show this information like this:
Quoted 5 lines
Quoted 3 lines
->refs/heads/master<TAB>HEAD<LF> 0d5e6c97...<TAB>HEAD<LF> ...Yet another obscure syntax? Why not just reusing the actual ref: syntax?
Yup, ref: is fine. Please make it so, but after 1.5.2 ;-).
Quoted 4 lines · Petr Baudis
This patch renames
config_boolean()toconfig_bool()for consistency with the commandline interface and because it is shorter but still obvious. ;-) It also changes the return value from some obscure string to real Perl boolean, allowing for clean user code.
Doesn't this break send-email?
Quoted 6 lines
perl/Git.pm +1
-1@@ -526,14 +528,16 @@ This currently wraps command('config') s =cut -sub config_boolean { +sub config_bool {
perl/Git.pm This currently wraps command('config') s · line 540
Quoted 10 lines
perl/Git.pm +3
-1my ($self, $var) = @_; $self->repo_path() or throw Error::Simple("not a repository"); try { - return $self->command_oneline('config', '--bool', '--get', + my $var = $self->command_oneline('config', '--bool', '--get', $var); + return undef unless defined $var; + return $var eq 'true';
Did you mean to hide $var in the nested scope?
PATCH 1/1 Git.pm: config_boolean() -> config_bool()
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Petr Baudis
This patch renames
config_boolean()toconfig_bool()for consistency with the commandline interface and because it is shorter but still obvious. ;-) It also changes the return value from some obscure string to real Perl boolean, allowing for clean user code.Doesn't this break send-email?
Oh, sorry! My grep must've been broken or something.
Quoted 10 lines
Quoted 10 lines
(quoted diff) +1
-1@@ -526,14 +528,16 @@ This currently wraps command('config') s =cut -sub config_boolean { +sub config_bool { my ($self, $var) = @_; $self->repo_path() or throw Error::Simple("not a repository");
Quoted 8 lines
Review This currently wraps command('config') s · line 540
Quoted 6 lines
(quoted diff) +3
-1try { - return $self->command_oneline('config', '--bool', '--get', + my $var = $self->command_oneline('config', '--bool', '--get', $var); + return undef unless defined $var; + return $var eq 'true';Did you mean to hide $var in the nested scope?
Hmm, I agree that having a different name for it will be more readable, fixed.
So, I realized that I'm not sure again how to stick a mail reply and new patch version in the same mail - originally I wanted to reply to this mail and send the patch as another reply, but that seemed wasteful. Now it seems that the only option is to stuff the mail reply in the diffstat area, but I refuse to do that since that's just plainly stupid.
---
This patch renames config_boolean() to config_bool() for consistency with the commandline interface and because it is shorter but still obvious. ;-) It also changes the return value from some obscure string to real Perl boolean, allowing for clean user code.
---
git-remote.perl | 4 ++-- git-send-email.perl | 4 ++-- perl/Git.pm | 14 +++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-)
git-remote.perl +2 -2
@@ -297,9 +297,9 @@ sub update_remote { } elsif ($name eq 'default') { undef @remotes; for (sort keys %$remote) { - my $do_fetch = $git->config_boolean("remote." . $_ . + my $do_fetch = $git->config_bool("remote." . $_ . ".skipDefaultUpdate"); - if (!defined($do_fetch) || $do_fetch ne "true") { + unless ($do_fetch) { push @remotes, $_; } }
git-send-email.perl +2 -2
@@ -154,8 +154,8 @@ if ($@) { $term = new FakeTerm "$@: going non-interactive"; } -my $def_chain = $repo->config_boolean('sendemail.chainreplyto'); -if ($def_chain and $def_chain eq 'false') { +my $def_chain = $repo->config_bool('sendemail.chainreplyto'); +if (defined $def_chain and not $def_chain) { $chain_reply_to = 0; }
perl/Git.pm +9 -5
@@ -516,9 +516,11 @@ sub config { } -=item config_boolean ( VARIABLE ) +=item config_bool ( VARIABLE ) -Retrieve the boolean configuration C<VARIABLE>. +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.
@@ -526,14 +528,16 @@ This currently wraps command('config') so it is not so fast. =cut -sub config_boolean { +sub config_bool { my ($self, $var) = @_; $self->repo_path() or throw Error::Simple("not a repository"); try { - return $self->command_oneline('config', '--bool', '--get', - $var); + my $val = $self->command_oneline('config', '--bool', '--get', + $val); + return undef unless defined $val; + return $val eq 'true'; } catch Git::Error::Command with { my $E = shift; if ($E->value() == 1) {
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Ever try. Ever fail. No matter. // Try again. Fail again. Fail better. -- Samuel Beckett
Quoted 5 lines · Petr Baudis
perl/Git.pm +0
-1@@ -526,14 +528,16 @@ This currently wraps command('config') so it is not so fast. =cut -sub config_boolean {
perl/Git.pm This currently wraps command('config') so it is not so fast. · line 538
Quoted 10 lines
perl/Git.pm +3
-2+sub config_bool { my ($self, $var) = @_; $self->repo_path() or throw Error::Simple("not a repository"); try { - return $self->command_oneline('config', '--bool', '--get', - $var); + my $val = $self->command_oneline('config', '--bool', '--get', + $val);
^^^
Sorry, should be $var. Looks like I forgot to make install or something when "testing" the patch, also judging by the error messages repo.or.cz spewed furiously in the last update round.
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Ever try. Ever fail. No matter. // Try again. Fail again. Fail better. -- Samuel Beckett
Quoted 3 lines · Petr Baudis
Looks like I forgot to make install or something
when "testing" the patch, also judging by the error messages repo.or.cz spewed furiously in the last update round.
Well, at least I can trust Git.pm and gitweb patches coming thru you better than patches from elsewhere, as I would know if they are broken too badly. People would immediately notice the breakage at repo.or.cz ;-).
Thanks.
Quoted 5 lines · Petr Baudis
So, I realized that I'm not sure again how to stick a mail reply and new patch version in the same mail - originally I wanted to reply to this mail and send the patch as another reply, but that seemed wasteful. Now it seems that the only option is to stuff the mail reply in the diffstat area, but I refuse to do that since that's just plainly stupid.
That's your opinion to go against a convention, which is fine, as long as you use something other than what begins with three dashes here as a separator.
Quoted 20 lines
---
This patch renames
config_boolean()toconfig_bool()for consistency with the commandline interface and because it is shorter but still obvious. ;-) It also changes the return value from some obscure string to real Perl boolean, allowing for clean user code.Signed-off-by Petr Baudis <[email protected]>---
git-remote.perl | 4 ++-- git-send-email.perl | 4 ++-- perl/Git.pm | 14 +++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-)git-remote.perl +0
-0@@ -297,9 +297,9 @@ sub update_remote {