All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Read cvsimport options from repo-config
@ 2007-02-06  1:22 James Bowes
  2007-02-06  4:26 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: James Bowes @ 2007-02-06  1:22 UTC (permalink / raw)
  To: git

Default values for command line options can be saved in .git/config (or the
global ~/.gitconfig). Config option names match the command line option names,
so cvsimport.d corresponds to git-cvsimport -d. One may also set
cvsimport.module to specify a default cvs module name.

Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>
---

I found myself always forgetting the specific options I needed to sync a given
project from CVS, so I wrote up this patch which lets me set the options with
repo-config and then forget about them; 'git cvsimport' is then enough to sync
from CVS.

This is my first patch, so please be gentle :)

 git-cvsimport.perl |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 6c9fbfe..604e636 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -85,7 +85,33 @@ sub write_author_info($) {
 	close ($f);
 }

-getopts("haivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage();
+# convert getopts specs for use by git-repo-config
+sub read_repo_config {
+	my @opts = split(/ *(?!:)/, shift);
+	foreach my $o (@opts) {
+		my $key = $o;
+		$key =~ s/://g;
+		my $arg = 'git-repo-config';
+		$arg .= ' --bool' if ($o !~ /:$/);
+
+        chomp(my $tmp = `$arg --get cvsimport.$key`);
+		if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {
+            no strict 'refs';
+            my $opt_name = "opt_" . $key;
+            if (!$$opt_name) {
+                $$opt_name = $tmp;
+            }
+		}
+	}
+    if (@ARGV == 0) {
+        chomp(my $module = `git-repo-config --get cvsimport.module`);
+        push(@ARGV, $module);
+    }
+}
+
+my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
+read_repo_config($opts);
+getopts($opts) or usage();
 usage if $opt_h;

 @ARGV <= 1 or usage();
-- 
1.4.4.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Read cvsimport options from repo-config
  2007-02-06  1:22 [PATCH] Read cvsimport options from repo-config James Bowes
@ 2007-02-06  4:26 ` Junio C Hamano
  2007-02-07 22:57   ` James Bowes
  2007-02-11  5:13   ` Eric Wong
  0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2007-02-06  4:26 UTC (permalink / raw)
  To: James Bowes; +Cc: git

I find what your patch does quite sensible, although the
split(/ *(?!:)/) magic might be a bit hard to read for the
uninitiated.

> +		my $arg = 'git-repo-config';
> +		$arg .= ' --bool' if ($o !~ /:$/);
> +
> +        chomp(my $tmp = `$arg --get cvsimport.$key`);
> +		if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {

Can this =~ / --bool / ever match (note the SP after 'l')?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Read cvsimport options from repo-config
  2007-02-06  4:26 ` Junio C Hamano
@ 2007-02-07 22:57   ` James Bowes
  2007-02-11  5:13   ` Eric Wong
  1 sibling, 0 replies; 4+ messages in thread
From: James Bowes @ 2007-02-07 22:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Default values for command line options can be saved in .git/config (or the
global ~/.gitconfig). Config option names match the command line option names,
so cvsimport.d corresponds to git-cvsimport -d. One may also set
cvsimport.module to specify a default cvs module name.

Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>
---

Thanks for the reply, Junio. I've added a comment explaining the
regex, and fixed the check for '--bool'; you were right, it didn't
work.

 git-cvsimport.perl |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 6c9fbfe..1a1ba7b 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -85,7 +85,35 @@ sub write_author_info($) {
 	close ($f);
 }

-getopts("haivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage();
+# convert getopts specs for use by git-repo-config
+sub read_repo_config {
+    # Split the string between characters, unless there is a ':'
+    # So "abc:de" becomes ["a", "b", "c:", "d", "e"]
+	my @opts = split(/ *(?!:)/, shift);
+	foreach my $o (@opts) {
+		my $key = $o;
+		$key =~ s/://g;
+		my $arg = 'git-repo-config';
+		$arg .= ' --bool' if ($o !~ /:$/);
+
+        chomp(my $tmp = `$arg --get cvsimport.$key`);
+		if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) {
+            no strict 'refs';
+            my $opt_name = "opt_" . $key;
+            if (!$$opt_name) {
+                $$opt_name = $tmp;
+            }
+		}
+	}
+    if (@ARGV == 0) {
+        chomp(my $module = `git-repo-config --get cvsimport.module`);
+        push(@ARGV, $module);
+    }
+}
+
+my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
+read_repo_config($opts);
+getopts($opts) or usage();
 usage if $opt_h;

 @ARGV <= 1 or usage();
-- 
1.4.4.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Read cvsimport options from repo-config
  2007-02-06  4:26 ` Junio C Hamano
  2007-02-07 22:57   ` James Bowes
@ 2007-02-11  5:13   ` Eric Wong
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Wong @ 2007-02-11  5:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: James Bowes, git

Junio C Hamano <junkio@cox.net> wrote:
> I find what your patch does quite sensible, although the
> split(/ *(?!:)/) magic might be a bit hard to read for the
> uninitiated.
> 
> > +		my $arg = 'git-repo-config';
> > +		$arg .= ' --bool' if ($o !~ /:$/);
> > +
> > +        chomp(my $tmp = `$arg --get cvsimport.$key`);
> > +		if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {
> 
> Can this =~ / --bool / ever match (note the SP after 'l')?

Heh, the same bug has been in git-svn for ages, too.

>From 0bece11c0019a7d2a2dcb71c42536ee45f523c47 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Sat, 10 Feb 2007 21:07:12 -0800
Subject: [PATCH] git-svn: correctly handle boolean options via git-config

We don't append a space after '--bool', so we can't expect
a regular expression to match the space.

Semi-noticed by Junio C Hamano :)

Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
 git-svn.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-svn.perl b/git-svn.perl
index 8ebaae9..d792a62 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -1610,7 +1610,7 @@ sub read_repo_config {
 			@$v = @tmp if @tmp;
 		} else {
 			chomp(my $tmp = `$arg --get svn.$key`);
-			if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {
+			if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
 				$$v = $tmp;
 			}
 		}
-- 
Eric Wong

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-02-11  5:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-06  1:22 [PATCH] Read cvsimport options from repo-config James Bowes
2007-02-06  4:26 ` Junio C Hamano
2007-02-07 22:57   ` James Bowes
2007-02-11  5:13   ` Eric Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.