I'm working on moving all of my CPAN module source code over to github, and I discovered much to my dismay that I didn't have any good code repositories - SVN, CVS, or even RCS. D'oh.

So i decided the next best thing was to rebuild the repositories using CPAN and BACKPAN to get tarfiles of all the releases of each module, then create git repositories treating each tarfile as if it were a commit. I've done "release early, release often" for most of my modules, so I actually had small enough deltas that this was a reasonable thing to do.

After doing a couple by hand, I realized that I could make things much easier for myself by letting Perl grab the names of all the files, unpack them one by one, and add the changed files to the repository each time. I used rsync to make this faster and easier; since it already knows how to crawl down trees and move only the new stuff, it seemed much more reasonable to do it that way.

#!/opt/local/bin/perl use strict; use warnings; my $workdir = shift || die "No work directory supplied\n"; chdir $workdir; my @files = glob('./*.tar.gz'); my %dists; for my $file (@files) { my($dist_name,$release) = ($file =~ m{\A(.*)-(\d+\.\d+)\.tar.gz}) or next; $dist_name =~ s{./}{}; push @{$dists{$dist_name}}, $release; } for my $dist (sort keys %dists) { my $lowered = lc($dist); mkdir $lowered; chdir $lowered; system qq(git init); chdir '..'; for my $release (sort @{ $dists{$dist} } ) { system qq(tar zxvf $dist-$release.tar.gz); system qq(rsync -avv $dist-$release/ $lowered); chdir $lowered; system qq(mv .cvsignore .gitignore); system qq(git diff); system qq(git add .); system qq(git commit -a -m'$release release'); chdir '..'; } }
It's still necessary to create the repos on github and push them up, but the dogwork of cd'ing around, copying files, and committing them to the local repositories becomes trivial.

I should probably add a WWW::Mechanize section at the bottom to create the repos on Github and then push them, but I haven't double-checked the TOS to be sure that would be OK.


In reply to CPAN dists to git repositories by pemungkah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.