{"thread":{"id":"6705","subject":"[PATCH] Read cvsimport options from repo-config","startedAt":"2007-02-06T01:22:25Z","lastAt":"2007-02-11T05:13:53Z","messageCount":4,"participants":["James Bowes","Junio C Hamano","Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"33681","messageId":"3f80363f0702051722x1812228fp1cd7a41dd32b31f3@mail.gmail.com","threadId":"6705","inReplyTo":null,"subject":"[PATCH] Read cvsimport options from repo-config","fromName":"James Bowes","fromEmail":"jbowes@dangerouslyinc.com","sentAt":"2007-02-06T01:22:25Z","receivedAt":"2007-02-06T01:22:25Z","isPatch":true,"sender":{"key":"jbowes@dangerouslyinc.com","avatar":"https://gravatar.com/avatar/a2fe98c66b2b47a9fa9d2ba92ff949d54c3208b1f8acc2e745b4b84ae3c4483a?d=mp&s=160"},"body":"Default values for command line options can be saved in .git/config (or the\nglobal ~/.gitconfig). Config option names match the command line option names,\nso cvsimport.d corresponds to git-cvsimport -d. One may also set\ncvsimport.module to specify a default cvs module name.\n\nSigned-off-by: James Bowes <jbowes@dangerouslyinc.com>\n---\n\nI found myself always forgetting the specific options I needed to sync a given\nproject from CVS, so I wrote up this patch which lets me set the options with\nrepo-config and then forget about them; 'git cvsimport' is then enough to sync\nfrom CVS.\n\nThis is my first patch, so please be gentle :)\n\n git-cvsimport.perl |   28 +++++++++++++++++++++++++++-\n 1 files changed, 27 insertions(+), 1 deletions(-)\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 6c9fbfe..604e636 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -85,7 +85,33 @@ sub write_author_info($) {\n \tclose ($f);\n }\n\n-getopts(\"haivmkuo:d:p:C:z:s:M:P:A:S:L:\") or usage();\n+# convert getopts specs for use by git-repo-config\n+sub read_repo_config {\n+\tmy @opts = split(/ *(?!:)/, shift);\n+\tforeach my $o (@opts) {\n+\t\tmy $key = $o;\n+\t\t$key =~ s/://g;\n+\t\tmy $arg = 'git-repo-config';\n+\t\t$arg .= ' --bool' if ($o !~ /:$/);\n+\n+        chomp(my $tmp = `$arg --get cvsimport.$key`);\n+\t\tif ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {\n+            no strict 'refs';\n+            my $opt_name = \"opt_\" . $key;\n+            if (!$$opt_name) {\n+                $$opt_name = $tmp;\n+            }\n+\t\t}\n+\t}\n+    if (@ARGV == 0) {\n+        chomp(my $module = `git-repo-config --get cvsimport.module`);\n+        push(@ARGV, $module);\n+    }\n+}\n+\n+my $opts = \"haivmkuo:d:p:C:z:s:M:P:A:S:L:\";\n+read_repo_config($opts);\n+getopts($opts) or usage();\n usage if $opt_h;\n\n @ARGV <= 1 or usage();\n-- \n1.4.4.2\n"},{"id":"33689","messageId":"7vireflxna.fsf@assigned-by-dhcp.cox.net","threadId":"6705","inReplyTo":"3f80363f0702051722x1812228fp1cd7a41dd32b31f3@mail.gmail.com","subject":"Re: [PATCH] Read cvsimport options from repo-config","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-06T04:26:17Z","receivedAt":"2007-02-06T04:26:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I find what your patch does quite sensible, although the\nsplit(/ *(?!:)/) magic might be a bit hard to read for the\nuninitiated.\n\n> +\t\tmy $arg = 'git-repo-config';\n> +\t\t$arg .= ' --bool' if ($o !~ /:$/);\n> +\n> +        chomp(my $tmp = `$arg --get cvsimport.$key`);\n> +\t\tif ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {\n\nCan this =~ / --bool / ever match (note the SP after 'l')?\n"},{"id":"33872","messageId":"3f80363f0702071457g713f6f0bn41dfc0dacd7415a2@mail.gmail.com","threadId":"6705","inReplyTo":"7vireflxna.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Read cvsimport options from repo-config","fromName":"James Bowes","fromEmail":"jbowes@dangerouslyinc.com","sentAt":"2007-02-07T22:57:43Z","receivedAt":"2007-02-07T22:57:43Z","isPatch":true,"sender":{"key":"jbowes@dangerouslyinc.com","avatar":"https://gravatar.com/avatar/a2fe98c66b2b47a9fa9d2ba92ff949d54c3208b1f8acc2e745b4b84ae3c4483a?d=mp&s=160"},"body":"Default values for command line options can be saved in .git/config (or the\nglobal ~/.gitconfig). Config option names match the command line option names,\nso cvsimport.d corresponds to git-cvsimport -d. One may also set\ncvsimport.module to specify a default cvs module name.\n\nSigned-off-by: James Bowes <jbowes@dangerouslyinc.com>\n---\n\nThanks for the reply, Junio. I've added a comment explaining the\nregex, and fixed the check for '--bool'; you were right, it didn't\nwork.\n\n git-cvsimport.perl |   30 +++++++++++++++++++++++++++++-\n 1 files changed, 29 insertions(+), 1 deletions(-)\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 6c9fbfe..1a1ba7b 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -85,7 +85,35 @@ sub write_author_info($) {\n \tclose ($f);\n }\n\n-getopts(\"haivmkuo:d:p:C:z:s:M:P:A:S:L:\") or usage();\n+# convert getopts specs for use by git-repo-config\n+sub read_repo_config {\n+    # Split the string between characters, unless there is a ':'\n+    # So \"abc:de\" becomes [\"a\", \"b\", \"c:\", \"d\", \"e\"]\n+\tmy @opts = split(/ *(?!:)/, shift);\n+\tforeach my $o (@opts) {\n+\t\tmy $key = $o;\n+\t\t$key =~ s/://g;\n+\t\tmy $arg = 'git-repo-config';\n+\t\t$arg .= ' --bool' if ($o !~ /:$/);\n+\n+        chomp(my $tmp = `$arg --get cvsimport.$key`);\n+\t\tif ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) {\n+            no strict 'refs';\n+            my $opt_name = \"opt_\" . $key;\n+            if (!$$opt_name) {\n+                $$opt_name = $tmp;\n+            }\n+\t\t}\n+\t}\n+    if (@ARGV == 0) {\n+        chomp(my $module = `git-repo-config --get cvsimport.module`);\n+        push(@ARGV, $module);\n+    }\n+}\n+\n+my $opts = \"haivmkuo:d:p:C:z:s:M:P:A:S:L:\";\n+read_repo_config($opts);\n+getopts($opts) or usage();\n usage if $opt_h;\n\n @ARGV <= 1 or usage();\n-- \n1.4.4.2\n"},{"id":"34153","messageId":"20070211051353.GA9481@localdomain","threadId":"6705","inReplyTo":"7vireflxna.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Read cvsimport options from repo-config","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-02-11T05:13:53Z","receivedAt":"2007-02-11T05:13:53Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> I find what your patch does quite sensible, although the\n> split(/ *(?!:)/) magic might be a bit hard to read for the\n> uninitiated.\n> \n> > +\t\tmy $arg = 'git-repo-config';\n> > +\t\t$arg .= ' --bool' if ($o !~ /:$/);\n> > +\n> > +        chomp(my $tmp = `$arg --get cvsimport.$key`);\n> > +\t\tif ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {\n> \n> Can this =~ / --bool / ever match (note the SP after 'l')?\n\nHeh, the same bug has been in git-svn for ages, too.\n\n>From 0bece11c0019a7d2a2dcb71c42536ee45f523c47 Mon Sep 17 00:00:00 2001\nFrom: Eric Wong <normalperson@yhbt.net>\nDate: Sat, 10 Feb 2007 21:07:12 -0800\nSubject: [PATCH] git-svn: correctly handle boolean options via git-config\n\nWe don't append a space after '--bool', so we can't expect\na regular expression to match the space.\n\nSemi-noticed by Junio C Hamano :)\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n git-svn.perl |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-svn.perl b/git-svn.perl\nindex 8ebaae9..d792a62 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -1610,7 +1610,7 @@ sub read_repo_config {\n \t\t\t@$v = @tmp if @tmp;\n \t\t} else {\n \t\t\tchomp(my $tmp = `$arg --get svn.$key`);\n-\t\t\tif ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {\n+\t\t\tif ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {\n \t\t\t\t$$v = $tmp;\n \t\t\t}\n \t\t}\n-- \nEric Wong\n"}]}