{"thread":{"id":"10311","subject":"[PATCH] git-cvsexportcommit.perl tabified","startedAt":"2007-10-16T09:56:26Z","lastAt":"2007-10-16T09:56:26Z","messageCount":1,"participants":["Michael Witten"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56002","messageId":"1192528586-8633-1-git-send-email-mfwitten@mit.edu","threadId":"10311","inReplyTo":null,"subject":"[PATCH] git-cvsexportcommit.perl tabified","fromName":"Michael Witten","fromEmail":"mfwitten@mit.edu","sentAt":"2007-10-16T09:56:26Z","receivedAt":"2007-10-16T09:56:26Z","isPatch":true,"sender":{"key":"mfwitten@gmail.com","avatar":"https://avatars.githubusercontent.com/u/597101?v=4"},"body":"---\n\t\n\tThis patch can be applied to spearce/next\n\tThe other patch for removing --binary should\n\tstill be applicable.\n\t\n\t\n git-cvsexportcommit.perl |  277 +++++++++++++++++++++++-----------------------\n 1 files changed, 139 insertions(+), 138 deletions(-)\n\ndiff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl\nindex 6b0123c..9dac7aa 100755\n--- a/git-cvsexportcommit.perl\n+++ b/git-cvsexportcommit.perl\n@@ -12,7 +12,7 @@ use Data::Dumper;\n use File::Basename qw(basename dirname);\n \n unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){\n-    die \"GIT_DIR is not defined or is unreadable\";\n+\tdie \"GIT_DIR is not defined or is unreadable\";\n }\n \n our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u);\n@@ -36,18 +36,18 @@ $commit = pop @ARGV;\n $commit = safe_pipe_capture('git-rev-parse', '--verify', \"$commit^0\");\n chomp $commit;\n if ($?) {\n-    die \"The commit reference $commit did not resolve!\";\n+\tdie \"The commit reference $commit did not resolve!\";\n }\n \n # resolve what parent we want\n my $parent;\n if (@ARGV) {\n-    $parent = pop @ARGV;\n-    $parent =  safe_pipe_capture('git-rev-parse', '--verify', \"$parent^0\");\n-    chomp $parent;\n-    if ($?) {\n-\tdie \"The parent reference did not resolve!\";\n-    }\n+\t$parent = pop @ARGV;\n+\t$parent =  safe_pipe_capture('git-rev-parse', '--verify', \"$parent^0\");\n+\tchomp $parent;\n+\tif ($?) {\n+\t\tdie \"The parent reference did not resolve!\";\n+\t}\n }\n \n # find parents from the commit itself\n@@ -60,44 +60,44 @@ my $title;\n my $msg = '';\n \n foreach my $line (@commit) {\n-    chomp $line;\n-    if ($stage eq 'headers' && $line eq '') {\n-\t$stage = 'msg';\n-\tnext;\n-    }\n-\n-    if ($stage eq 'headers') {\n-\tif ($line =~ m/^parent (\\w{40})$/) { # found a parent\n-\t    push @parents, $1;\n-\t} elsif ($line =~ m/^author (.+) \\d+ [-+]\\d+$/) {\n-\t    $author = $1;\n-\t} elsif ($line =~ m/^committer (.+) \\d+ [-+]\\d+$/) {\n-\t    $committer = $1;\n+\tchomp $line;\n+\tif ($stage eq 'headers' && $line eq '') {\n+\t\t$stage = 'msg';\n+\t\tnext;\n \t}\n-    } else {\n-\t$msg .= $line . \"\\n\";\n-\tunless ($title) {\n-\t    $title = $line;\n+\n+\tif ($stage eq 'headers') {\n+\t\tif ($line =~ m/^parent (\\w{40})$/) { # found a parent\n+\t\t\tpush @parents, $1;\n+\t\t} elsif ($line =~ m/^author (.+) \\d+ [-+]\\d+$/) {\n+\t\t\t$author = $1;\n+\t\t} elsif ($line =~ m/^committer (.+) \\d+ [-+]\\d+$/) {\n+\t\t\t$committer = $1;\n+\t\t}\n+\t} else {\n+\t\t$msg .= $line . \"\\n\";\n+\t\tunless ($title) {\n+\t\t\t$title = $line;\n+\t\t}\n \t}\n-    }\n }\n \n if ($parent) {\n-    my $found;\n-    # double check that it's a valid parent\n-    foreach my $p (@parents) {\n-\tif ($p eq $parent) {\n-\t    $found = 1;\n-\t    last;\n-\t}; # found it\n-    }\n-    die \"Did not find $parent in the parents for this commit!\" if !$found and !$opt_P;\n+\tmy $found;\n+\t# double check that it's a valid parent\n+\tforeach my $p (@parents) {\n+\t\tif ($p eq $parent) {\n+\t\t\t$found = 1;\n+\t\t\tlast;\n+\t\t}; # found it\n+\t}\n+\tdie \"Did not find $parent in the parents for this commit!\" if !$found and !$opt_P;\n } else { # we don't have a parent from the cmdline...\n-    if (@parents == 1) { # it's safe to get it from the commit\n-\t$parent = $parents[0];\n-    } else { # or perhaps not!\n-\tdie \"This commit has more than one parent -- please name the parent you want to use explicitly\";\n-    }\n+\tif (@parents == 1) { # it's safe to get it from the commit\n+\t\t$parent = $parents[0];\n+\t} else { # or perhaps not!\n+\t\tdie \"This commit has more than one parent -- please name the parent you want to use explicitly\";\n+\t}\n }\n \n $opt_v && print \"Applying to CVS commit $commit from parent $parent\\n\";\n@@ -105,14 +105,14 @@ $opt_v && print \"Applying to CVS commit $commit from parent $parent\\n\";\n # grab the commit message\n open(MSG, \">.msg\") or die \"Cannot open .msg for writing\";\n if ($opt_m) {\n-    print MSG $opt_m;\n+\tprint MSG $opt_m;\n }\n print MSG $msg;\n if ($opt_a) {\n-    print MSG \"\\n\\nAuthor: $author\\n\";\n-    if ($author ne $committer) {\n-\tprint MSG \"Committer: $committer\\n\";\n-    }\n+\tprint MSG \"\\n\\nAuthor: $author\\n\";\n+\tif ($author ne $committer) {\n+\t\tprint MSG \"Committer: $committer\\n\";\n+\t}\n }\n close MSG;\n \n@@ -148,70 +148,71 @@ map { s/\\\\([0-7]{3})/sprintf('%c',oct $1)/eg } @bfiles,@files;\n my $dirty;\n my @dirs;\n foreach my $p (@afiles) {\n-    my $path = dirname $p;\n-    while (!-d $path and ! grep { $_ eq $path } @dirs) {\n-\tunshift @dirs, $path;\n-\t$path = dirname $path;\n-    }\n+\tmy $path = dirname $p;\n+\twhile (!-d $path and ! grep { $_ eq $path } @dirs) {\n+\t\tunshift @dirs, $path;\n+\t\t$path = dirname $path;\n+\t}\n }\n \n # ... check dirs,\n foreach my $d (@dirs) {\n-    if (-e $d) {\n-\t$dirty = 1;\n-\twarn \"$d exists and is not a directory!\\n\";\n-    }\n+\tif (-e $d) {\n+\t\t$dirty = 1;\n+\t\twarn \"$d exists and is not a directory!\\n\";\n+\t}\n }\n \n # ... query status of all files that we have a directory for and parse output of 'cvs status' to %cvsstat.\n my @canstatusfiles;\n foreach my $f (@files) {\n-    my $path = dirname $f;\n-    next if (grep { $_ eq $path } @dirs);\n-    push @canstatusfiles, $f;\n+\tmy $path = dirname $f;\n+\tnext if (grep { $_ eq $path } @dirs);\n+\tpush @canstatusfiles, $f;\n }\n \n my %cvsstat;\n if (@canstatusfiles) {\n-    if ($opt_u) {\n-      my @updated = safe_pipe_capture(@cvs, 'update', @canstatusfiles);\n-      print @updated;\n-    }\n-    my @cvsoutput;\n-    @cvsoutput= safe_pipe_capture(@cvs, 'status', @canstatusfiles);\n-    my $matchcount = 0;\n-    foreach my $l (@cvsoutput) {\n-        chomp $l;\n-        if ( $l =~ /^File:/ and  $l =~ /Status: (.*)$/ ) {\n-            $cvsstat{$canstatusfiles[$matchcount]} = $1;\n-            $matchcount++;\n-        }\n-    }\n+\tif ($opt_u) {\n+\t\tmy @updated = safe_pipe_capture(@cvs, 'update', @canstatusfiles);\n+\t\tprint @updated;\n+\t}\n+\tmy @cvsoutput;\n+\t@cvsoutput= safe_pipe_capture(@cvs, 'status', @canstatusfiles);\n+\tmy $matchcount = 0;\n+\tforeach my $l (@cvsoutput) {\n+\t\tchomp $l;\n+\t\tif ( $l =~ /^File:/ and  $l =~ /Status: (.*)$/ ) {\n+\t\t\t$cvsstat{$canstatusfiles[$matchcount]} = $1;\n+\t\t\t$matchcount++;\n+\t\t}\n+\t}\n }\n \n # ... validate new files,\n foreach my $f (@afiles) {\n-    if (defined ($cvsstat{$f}) and $cvsstat{$f} ne \"Unknown\") {\n-\t$dirty = 1;\n-\twarn \"File $f is already known in your CVS checkout -- perhaps it has been added by another user. Or this may indicate that it exists on a different branch. If this is the case, use -f to force the merge.\\n\";\n-\twarn \"Status was: $cvsstat{$f}\\n\";\n-    }\n+\tif (defined ($cvsstat{$f}) and $cvsstat{$f} ne \"Unknown\") {\n+\t\t$dirty = 1;\n+\t\twarn \"File $f is already known in your CVS checkout -- perhaps it has been added by another user. Or this may indicate that it exists on a different branch. If this is the case, use -f to force the merge.\\n\";\n+\t\twarn \"Status was: $cvsstat{$f}\\n\";\n+\t}\n }\n # ... validate known files.\n foreach my $f (@files) {\n-    next if grep { $_ eq $f } @afiles;\n-    # TODO:we need to handle removed in cvs\n-    unless (defined ($cvsstat{$f}) and $cvsstat{$f} eq \"Up-to-date\") {\n-\t$dirty = 1;\n-\twarn \"File $f not up to date but has status '$cvsstat{$f}' in your CVS checkout!\\n\";\n-    }\n+\tnext if grep { $_ eq $f } @afiles;\n+\t# TODO:we need to handle removed in cvs\n+\tunless (defined ($cvsstat{$f}) and $cvsstat{$f} eq \"Up-to-date\") {\n+\t\t$dirty = 1;\n+\t\twarn \"File $f not up to date but has status '$cvsstat{$f}' in your CVS checkout!\\n\";\n+\t}\n }\n if ($dirty) {\n-    if ($opt_f) {\twarn \"The tree is not clean -- forced merge\\n\";\n-\t$dirty = 0;\n-    } else {\n-\tdie \"Exiting: your CVS tree is not clean for this merge.\";\n-    }\n+\tif ($opt_f) {\n+\t\twarn \"The tree is not clean -- forced merge\\n\";\n+\t\t$dirty = 0;\n+\t} else {\n+\t\tdie \"Exiting: your CVS tree is not clean for this merge.\";\n+\t}\n }\n \n print \"Applying\\n\";\n@@ -220,30 +221,30 @@ print \"Applying\\n\";\n print \"Patch applied successfully. Adding new files and directories to CVS\\n\";\n my $dirtypatch = 0;\n foreach my $d (@dirs) {\n-    if (system(@cvs,'add',$d)) {\n-\t$dirtypatch = 1;\n-\twarn \"Failed to cvs add directory $d -- you may need to do it manually\";\n-    }\n+\tif (system(@cvs,'add',$d)) {\n+\t\t$dirtypatch = 1;\n+\t\twarn \"Failed to cvs add directory $d -- you may need to do it manually\";\n+\t}\n }\n \n foreach my $f (@afiles) {\n-    if (grep { $_ eq $f } @bfiles) {\n-      system(@cvs, 'add','-kb',$f);\n-    } else {\n-      system(@cvs, 'add', $f);\n-    }\n-    if ($?) {\n-\t$dirtypatch = 1;\n-\twarn \"Failed to cvs add $f -- you may need to do it manually\";\n-    }\n+\tif (grep { $_ eq $f } @bfiles) {\n+\t  system(@cvs, 'add','-kb',$f);\n+\t} else {\n+\t  system(@cvs, 'add', $f);\n+\t}\n+\tif ($?) {\n+\t\t$dirtypatch = 1;\n+\t\twarn \"Failed to cvs add $f -- you may need to do it manually\";\n+\t}\n }\n \n foreach my $f (@dfiles) {\n-    system(@cvs, 'rm', '-f', $f);\n-    if ($?) {\n-\t$dirtypatch = 1;\n-\twarn \"Failed to cvs rm -f $f -- you may need to do it manually\";\n-    }\n+\tsystem(@cvs, 'rm', '-f', $f);\n+\tif ($?) {\n+\t\t$dirtypatch = 1;\n+\t\twarn \"Failed to cvs rm -f $f -- you may need to do it manually\";\n+\t}\n }\n \n print \"Commit to CVS\\n\";\n@@ -252,25 +253,25 @@ my @commitfiles = map { unless (m/\\s/) { '\\''.$_.'\\''; } else { $_; }; } (@files\n my $cmd = join(' ', @cvs).\" commit -F .msg @commitfiles\";\n \n if ($dirtypatch) {\n-    print \"NOTE: One or more hunks failed to apply cleanly.\\n\";\n-    print \"You'll need to apply the patch in .cvsexportcommit.diff manually\\n\";\n-    print \"using a patch program. After applying the patch and resolving the\\n\";\n-    print \"problems you may commit using:\";\n-    print \"\\n    $cmd\\n\\n\";\n-    exit(1);\n+\tprint \"NOTE: One or more hunks failed to apply cleanly.\\n\";\n+\tprint \"You'll need to apply the patch in .cvsexportcommit.diff manually\\n\";\n+\tprint \"using a patch program. After applying the patch and resolving the\\n\";\n+\tprint \"problems you may commit using:\";\n+\tprint \"\\n\t$cmd\\n\\n\";\n+\texit(1);\n }\n \n if ($opt_c) {\n-    print \"Autocommit\\n  $cmd\\n\";\n-    print safe_pipe_capture(@cvs, 'commit', '-F', '.msg', @files);\n-    if ($?) {\n-\tdie \"Exiting: The commit did not succeed\";\n-    }\n-    print \"Committed successfully to CVS\\n\";\n-    # clean up\n-    unlink(\".msg\");\n+\tprint \"Autocommit\\n  $cmd\\n\";\n+\tprint safe_pipe_capture(@cvs, 'commit', '-F', '.msg', @files);\n+\tif ($?) {\n+\t\tdie \"Exiting: The commit did not succeed\";\n+\t}\n+\tprint \"Committed successfully to CVS\\n\";\n+\t# clean up\n+\tunlink(\".msg\");\n } else {\n-    print \"Ready for you to commit, just run:\\n\\n   $cmd\\n\";\n+\tprint \"Ready for you to commit, just run:\\n\\n   $cmd\\n\";\n }\n \n # clean up\n@@ -292,25 +293,25 @@ END\n # to work around shell problems with weird characters in arguments\n # if the exec returns non-zero we die\n sub safe_pipe_capture {\n-    my @output;\n-    if (my $pid = open my $child, '-|') {\n-\t@output = (<$child>);\n-\tclose $child or die join(' ',@_).\": $! $?\";\n-    } else {\n-\texec(@_) or die \"$! $?\"; # exec() can fail the executable can't be found\n-    }\n-    return wantarray ? @output : join('',@output);\n+\tmy @output;\n+\tif (my $pid = open my $child, '-|') {\n+\t\t@output = (<$child>);\n+\t\tclose $child or die join(' ',@_).\": $! $?\";\n+\t} else {\n+\t\texec(@_) or die \"$! $?\"; # exec() can fail the executable can't be found\n+\t}\n+\treturn wantarray ? @output : join('',@output);\n }\n \n sub safe_pipe_capture_blob {\n-    my $output;\n-    if (my $pid = open my $child, '-|') {\n-        local $/;\n-\tundef $/;\n-\t$output = (<$child>);\n-\tclose $child or die join(' ',@_).\": $! $?\";\n-    } else {\n-\texec(@_) or die \"$! $?\"; # exec() can fail the executable can't be found\n-    }\n-    return $output;\n+\tmy $output;\n+\tif (my $pid = open my $child, '-|') {\n+\t\tlocal $/;\n+\t\tundef $/;\n+\t\t$output = (<$child>);\n+\t\tclose $child or die join(' ',@_).\": $! $?\";\n+\t} else {\n+\t\texec(@_) or die \"$! $?\"; # exec() can fail the executable can't be found\n+\t}\n+\treturn $output;\n }\n-- \n1.5.3.4.209.g397ef-dirty\n"}]}