# Wrapper scripts to help git-cvsimport cope with cvs 1.12 breakage

1 messages from 2007-07-03 to 2007-07-03. Participants: Yann Dirson.
Thread: https://gitlist.dev/t/8844

## Yann Dirson, 2007-07-03 21:43

Subject: Wrapper scripts to help git-cvsimport cope with cvs 1.12 breakage
Message-ID: <20070703214336.GC6361@nan92-1-81-57-214-146.fbx.proxad.net>
URL: https://gitlist.dev/e/20070703214336.GC6361%40nan92-1-81-57-214-146.fbx.proxad.net

```
Some of you may have noticed that cvs 1.12.x has a bad habit, when a
file gets added on a branch, of creating a dummy 1.x.2.1 revision of
the empty file on the branch.  What's annoying, is that the dummy
revision gets an erroneous timestamp, which makes the cvsps output
wrong, following the well-known GIGO principle.

Until someone (maybe me, but I can give no guaranty whatsoever) finds
the time to deal with this bug in cvsps, as well as avoiding at the
cvsps level the extra "file initially added on branch" dummy
revisions, here is a little perl filter that sanitizes the csvps
output, and a customizable git-cvsimport wrapper using it.

Best regards,
-- 
Yann


#!/usr/bin/perl
use strict;
use warnings;

$/='---------------------';

our @branches = qw/HEAD/;
our %parents = ();		# parents not yet recorded

# parsing state
our $patchset_is_valid;
our $patchset;

while(<>) {
  $patchset = $_;

  # skip first separator line
  if ($patchset eq $/) {
    print $patchset;
    next;
  }

  $patchset_is_valid = 1;
  my ($branch, $ancestor);
  if (m/^Branch: (.*)/m) {
    $branch = $1;
    if (!grep { $_ eq $branch } @branches) {
      push @branches, $branch;
    }
  } else {
    die "no branch in $patchset";
  }

  if (m/^Ancestor branch: (.*)/m) {
    $ancestor = $1;
    if (!grep { $_ eq $ancestor } @branches or
	m/^file .* was added on branch /m) {
      print STDERR "preparing $branch fixup\n";
      $patchset_is_valid = 0;
      $parents{$branch} = $ancestor;
    }
  }

  if (m/^file .* was added on branch /m) {
    $patchset_is_valid = 0;
  }

  if (defined $parents{$branch} and $patchset_is_valid) {
    print STDERR "finalizing $branch fixup\n";
    my $line = 'Ancestor branch: ' . $parents{$branch} . "\n";
    $patchset =~ s/^(?=Tag:)/$line/m;
    delete $parents{$branch};
  }

```
