update_branches revision 133015326138df036e018e197017f9086cb8e135
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#!/usr/local/bin/perl -w
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# Copyright (C) 2005 Internet Systems Consortium, Inc. ("ISC")
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# Permission to use, copy, modify, and distribute this software for any
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# purpose with or without fee is hereby granted, provided that the above
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# copyright notice and this permission notice appear in all copies.
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# PERFORMANCE OF THIS SOFTWARE.
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# $Id: update_branches,v 1.12 2005/05/17 00:58:41 marka Exp $
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# Track which branches are still open or not in the bind9 cvs repository.
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# This is done so that work that is "in progress" (active) doesn't get
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# so easily forgotten about.
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# This script updates doc/private/branches by adding new branches and moving
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# closed branches to the end of the file. New branches are found by walking
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# the cvs repository and extracting the new branches from the header fields
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# of the files there.
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# doc/private/branches has one line per branch in the following field order:
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# name, status, to whom the branch belongs and comments. Comments are
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# in '(',')'. The first three field are single words.
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson%branches = ();
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson%whom = ();
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson%comments = ();
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# Make sure we have a up to date copy. If the previous ran failed for
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# any reason remove it (-C).
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson!system("cvs", "-d", "/proj/cvs/prod", "update", "-C", "doc/private/branches") || die "cannot update doc/private/branches: $!";
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson# load existing content
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson#
d49d75f5073294d798aa500728116309398bb535Andreas Gustafssonopen(BRANCHES, "<doc/private/branches") || die "can't open util/branches: $!";
d49d75f5073294d798aa500728116309398bb535Andreas Gustafssonwhile (<BRANCHES>) {
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson chomp;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson next if (/^-/);
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson next if (/^Branch/);
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $c = "";
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson if (m://.*:) {
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $c = $_;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $c =~ s:.*?//(.*)$:$1:;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson s:(.*?)//.*:$1:;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson } else {
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson if (m/\(.*\)/) {
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $c = $_;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $c =~ s/.*\((.*)\).*$/$1/;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson s/\(.*\)//;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson }
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson }
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson s/\s$//;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson next if (/^\s*$/);
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson ($branch, $status, $who) = split;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $status = "new" if (!defined($status));
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $branches{$branch} = $status;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $who = "" if (!defined($who));
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $whom{$branch} = $who;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson $comments{$branch} = $c;
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson}
close (BRANCHES);
#
# Search repository for new branches.
#
open(FILES, "find /proj/cvs/prod/bind9 -type f -name *,v -print |") || die "can't start find: $!";
while (<FILES>) {
chomp;
# print "file: $_\n"; # debug
# $file = $_; # save for branch debug below.
s:/proj/cvs/prod/bind9/::;
s:/Attic/([^/]*)$:/$1:;
s:^Attic/([^/]*)$:$1:;
s:,v$::;
#
# use cvs so that the file is locked.
#
open(FILE, "cvs log -h $_|") || die "can't start cvs log -h $_: $!";
while (<FILE>) {
chomp;
next unless m/^symbols$/; # skip until we find the tags
while (<FILE>) {
chomp;
last if (m/^locks;/); # we are past the tags
last if (m/^keyword/); # we are past the tags
next unless m/\.0\.\d$/; # skip if not a branch
s/\s(.*):.*/$1/; # extract label
if (!$branches{$_}) {
$branches{$_} = "new";
$whom{$_} = "";
$comments{$_} = "";
# print "branch: $_ $file\n"; # debug
}
}
last;
}
close(FILE);
}
close(FILES);
#
# Write out updated version.
#
open(BRANCHES, ">doc/private/newbranches") || die "can't open doc/private/branches: $!";
print BRANCHES "\nBranch\t\t\t\tStatus\tWhom\t(Comments)\n";
print BRANCHES "----------------------------------------------------------\n\n";
foreach $key (sort keys %branches) {
next if ($branches{$key} eq "closed");
print BRANCHES "$key";
$len = length($key);
if ($len >= 32) {
$tabs = 1;
} else {
$needed = int (32 - $len);
$tabs = int ($needed / 8);
if ($needed % 8 != 0) {
$tabs++;
}
}
for ($i = 0; $i < $tabs; $i++) {
printf BRANCHES "\t";
}
print BRANCHES "$branches{$key}\t";
print BRANCHES "$whom{$key}";
print BRANCHES "\t//$comments{$key}" if ($comments{$key} ne "");
print BRANCHES "\n";
}
print BRANCHES "\n\n";
foreach $key (sort keys %branches) {
next if ($branches{$key} ne "closed");
print BRANCHES "$key";
$len = length($key);
if ($len >= 32) {
$tabs = 1;
} else {
$needed = int (32 - $len);
$tabs = int ($needed / 8);
if ($needed % 8 != 0) {
$tabs++;
}
}
for ($i = 0; $i < $tabs; $i++) {
printf BRANCHES "\t";
}
print BRANCHES "$branches{$key}";
print BRANCHES "\t\t//$comments{$key}" if ($comments{$key} ne "");
print BRANCHES "\n";
}
close(BRANCHES);
#
# Update if changed.
#
if (system("cmp", "-s", "doc/private/newbranches", "doc/private/branches")) {
rename("doc/private/newbranches", "doc/private/branches") || die "Cannot rename: doc/private/newbranches -> doc/private/branches: $!";
!system("cvs", "-d", "/proj/cvs/prod", "commit", "-m", "auto update", "doc/private/branches") || die "cvs commit failed: $!";
} else {
unlink("doc/private/newbranches");
}