git.vger.kernel.org archive mirror
 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

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 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).