git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Read cvsimport options from repo-config

From
James Bowes <jbowes@dangerouslyinc.com>
Date
Feb 7, 2007, 22:57 UTC
Message-ID
<3f80363f0702071457g713f6f0bn41dfc0dacd7415a2@mail.gmail.com>
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
Previous: Junio C HamanoNext: Eric Wong
Message 3 of 4 in “Read cvsimport options from repo-config”
  1. Read cvsimport options from repo-configJames Bowes, Feb 6, 2007
  2. Junio C HamanoFeb 6, 2007
  3. James BowesFeb 7, 2007
  4. Eric WongFeb 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.