As I wrote earlier Debian migrates from Alioth to Salsa. In the previous post I've explained how to batch import Alioth repositories for which one has local clones with the help of a small and ugly Perl script. But this is just a part of what should be done. This time I modified the scipt to change Vcs-{Browser,Git} URLs in the debian/control files from Alioth to Salsa, commit changes, change git remote, and push. Don't expect the code to be beautiful or efficient, it just works for me.

So, to use the script with the other team's repositories (other than Debian Emacs Addons Packaging Team) one needs to slightly change the $salsa, $alioth, $salsa_origin variables. Also, it is possible to black list directories with the help of grep in @dirs declaration. If you want to silence git, then append >/dev/null 2>/dev/null to the corresponding git commands.

Yes, I understand that I should add this URLs updating functionality to the original script in the first place, but at the time I wrote it I was not ready to spend more time on it. And since the migration is rather a one-shot thing, I don't want to polish it now. Therefore, be careful while using it for your stuff. There are no guarantees that it will work for you or will not break anything.

#!/usr/bin/perl

use warnings;
use strict;

use File::Slurp;

my $root = $ARGV[0];

my $salsa = "https://salsa.debian.org/emacsen-team/";
my $alioth = qr/https:\/\/anonscm\.debian\.org\/c?git\/pkg-emacsen\/pkg\//;

my $salsa_origin = 'git@salsa.debian.org:emacsen-team/';

my $commit_message = "Change Vcs-{Browser,Git} URL to salsa.debian.org";

opendir my $dh, $root or die "$0: opendir: $!";

my @dirs = grep { -d "$root/$_" && ! /^\.{1,2}$|^dh-.*(elpa)+/ } readdir($dh);

closedir $dh;

foreach my $dir (@dirs) {
    chdir $root . $dir;
    next unless (-e $root . $dir . "/debian/control");
    system "git pull origin master";
    my @lines = read_file( $root . $dir . "/debian/control" );
    my $git_new_origin;
    print "Processing $dir...\n";
    for (my $l = 0; $l <= $#lines; $l++) {
        unless ($lines[$l] =~ /$salsa/g) {
            if ($lines[$l] =~ m/Vcs-Browser: $alioth/) {
                $lines[$l] =~ s/(Vcs-Browser: ).*\/(.+)\.git\/$/$1$salsa$2/g;
            } elsif ($lines[$l] =~ m/Vcs-Git: $alioth/) {
                $lines[$l] =~ s/(Vcs-Git: ).*\/(.+\.git)$/$1$salsa$2/g;
                $git_new_origin = "git remote add origin $salsa_origin$2";
            }
        }
    }
    write_file( $root . $dir . "/debian/control", @lines );
    system "git remote rm origin";
    if ($git_new_origin) {
        system $git_new_origin;
        system "git commit -a -m $commit_message";
        system "git push"
    } else {
        print "No changes, skipping...\n"
    }
}

The script gets path to the root directory, containing the local clones, as an argument, so it should be ran as something like ./salsa-convert.pl ~/freedom/packaging/elpa/.