git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "James Bowes" <jbowes@dangerouslyinc.com>
To: "Junio C Hamano" <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Read cvsimport options from repo-config
Date: Wed, 7 Feb 2007 17:57:43 -0500	[thread overview]
Message-ID: <3f80363f0702071457g713f6f0bn41dfc0dacd7415a2@mail.gmail.com> (raw)
In-Reply-To: <7vireflxna.fsf@assigned-by-dhcp.cox.net>

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

  reply	other threads:[~2007-02-07 22:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2007-02-11  5:13   ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f80363f0702071457g713f6f0bn41dfc0dacd7415a2@mail.gmail.com \
    --to=jbowes@dangerouslyinc.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).