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

[PATCH] cvsimport: allow for multiple -M options

From
Philippe Bruhat (BooK) <book@cpan.org>
Date
Feb 28, 2008, 10:18 UTC
Message-ID
<1204193904-3652-3-git-send-email-book@cpan.org>
In-Reply-To
<1204193904-3652-2-git-send-email-book@cpan.org>
From: Philippe Bruhat (BooK <book@cpan.org>

Use Getopt::Long instead of Getopt::Std to handle multiple -M options, for all the cases when having a single custom regex is not enough.

For example, "merged (\w+)" and "(\w+) merged" can't be easily turned
into a single regular expression capturing the branch name in $1.
---
 git-cvsimport.perl |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 3d013a7..f138a01 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -15,7 +15,7 @@
 
 use strict;
 use warnings;
-use Getopt::Std;
+use Getopt::Long;
 use File::Spec;
 use File::Temp qw(tempfile tmpnam);
 use File::Path qw(mkpath);
@@ -29,7 +29,7 @@ use IPC::Open2;
 $SIG{'PIPE'}="IGNORE";
 $ENV{'TZ'}="UTC";
 
-our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r);
+our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r);
 my (%conv_author_name, %conv_author_email);
 
 sub usage(;$) {
@@ -112,7 +112,12 @@ sub read_repo_config {
 
 my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:";
 read_repo_config($opts);
-getopts($opts) or usage();
+Getopt::Long::Configure( 'no_ignore_case' );
+
+# turn the Getopt::Std specification in a Getopt::Long one,
+# with support for multiple -M options
+GetOptions( map { s/:/=s/; /M/ ? "$_\@" : $_ } split( /(?!:)/, $opts ) )
+    or usage();
 usage if $opt_h;
 
 if (@ARGV == 0) {
@@ -166,8 +171,8 @@ our @mergerx = ();
 if ($opt_m) {
 	@mergerx = ( qr/\b(?:from|of|merge|merging|merged) ([-\w]+)/i );
 }
-if ($opt_M) {
-	push (@mergerx, qr/$opt_M/);
+if (@opt_M) {
+	push (@mergerx, map { qr/$_/ } @opt_M);
 }
 
 # Remember UTC of our starting time
-- 
1.5.4.2.187.gfc276
Previous: Philippe Bruhat (BooK)Next: Philippe Bruhat (BooK)
Message 3 of 9 in “Multiple -M options for git-cvsimport”
  1. Philippe Bruhat (BooK)Feb 28, 2008
  2. cvsimport: have default merge regex allow for dashes in the branch namePhilippe Bruhat (BooK), Feb 28, 2008
  3. cvsimport: allow for multiple -M optionsPhilippe Bruhat (BooK), Feb 28, 2008
  4. cvsimport: document that -M can be used multiple timesPhilippe Bruhat (BooK), Feb 28, 2008
  5. cvsimport: configure Getopt::Long to bundle optionsPhilippe Bruhat (BooK), Feb 28, 2008
  6. Junio C HamanoFeb 28, 2008
  7. Philippe Bruhat (BooK)Feb 29, 2008
  8. Junio C HamanoMar 1, 2008
  9. Junio C HamanoMar 1, 2008

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.