summaryrefslogtreecommitdiffstats
path: root/cervisia/cervisia-change_repos_list.pl
blob: 925c49eeb7a4e98c413c90014b45aece2ff457ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl

# (copied from kdesdk/cervisia/misc.cpp)
# These regular expression parts aren't useful to check the validity of the
# CVSROOT specification. They are just used to extract the different parts of it.
$usernamerx = "([a-z0-9_][a-z0-9_-]*)?";
$passwordrx = "(:[^@]+)?";
$hostrx     = "([^:/]+)";
$portrx     = "(:(\\d*))?";
$pathrx     = "(/.*)";

# concat above regexps into a single expression
$regexp = join('', ":pserver:(", $usernamerx, $passwordrx, "@)?", $hostrx, $portrx, $pathrx);

$loginuser = getlogin || getpwuid($<);

while(<>)
{
    ($key)   = ($_ =~ /([^=]*)=(.*)$/);
    ($value) = ($_ =~ /^[^=]*=(.*)$/);

    if( $key eq "Repos" )
    {
        @repos = split(',', $value);

        foreach $repo ( @repos )
        {
            # pserver CVSROOT specification?
            if( $repo =~ m/($regexp)/ )
            {
                # extract username, hostname, port and path from CVSROOT
                $username = $3;
                $hostname = $5;
                $port     = $7;
                $path     = $8;

                # replace empty port number
                $port =~ s/^$/2401/;

                # replace empty username
                $username =~ s/^$/$loginuser/;

                # create normalized CVSROOT specification
                $repo = join('', ":pserver:", $username, "@", $hostname, ":", $port, $path);
            }
        }

        # remove duplicates from array
        %seen = ();
        @repos = grep { ! $seen{$_} ++ } @repos;

        $value = join(',', @repos);
        print "# DELETE " . $key . "\n";
        print $key . "=" . $value . "\n";
        next;
    }

    print $_;
}