update_branches revision b08e3be5dbfba22719ae9c428bd6853ac6f09798
116N/A#!/usr/local/bin/perl -w
116N/A#
116N/A# Copyright (C) 2005 Internet Systems Consortium, Inc. ("ISC")
116N/A#
116N/A# Permission to use, copy, modify, and distribute this software for any
116N/A# purpose with or without fee is hereby granted, provided that the above
116N/A# copyright notice and this permission notice appear in all copies.
116N/A#
116N/A# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
116N/A# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
116N/A# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
116N/A# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
116N/A# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
116N/A# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
116N/A# PERFORMANCE OF THIS SOFTWARE.
116N/A
116N/A# $Id: update_branches,v 1.13 2005/05/17 03:31:44 marka Exp $
116N/A
116N/A#
116N/A# Track which branches are still open or not in the bind9 cvs repository.
116N/A# This is done so that work that is "in progress" (active) doesn't get
116N/A# so easily forgotten about.
3817N/A#
116N/A# This script updates doc/private/branches by adding new branches and moving
116N/A# closed branches to the end of the file. New branches are found by walking
116N/A# the cvs repository and extracting the new branches from the header fields
116N/A# of the files there.
1244N/A#
3020N/A# doc/private/branches has one line per branch in the following field order:
618N/A# name, status, to whom the branch belongs and comments. Comments are
1244N/A# in '(',')'. The first three field are single words.
1244N/A#
116N/A
844N/A%branches = ();
3020N/A%whom = ();
116N/A%comments = ();
1258N/A$repository = "/proj/cvs/prod";
116N/A$module = "bind9";
3020N/A
2899N/A#
3817N/A# Make sure we have a up to date copy. If the previous ran failed for
3817N/A# any reason remove it (-C).
3817N/A#
116N/A!system("cvs", "-d", $repository, "update", "-C", "doc/private/branches") || die "cannot update doc/private/branches: $!";
116N/A
116N/A#
116N/A# load existing content
116N/A#
116N/Aopen(BRANCHES, "<doc/private/branches") || die "can't open util/branches: $!";
116N/Awhile (<BRANCHES>) {
116N/A chomp;
116N/A next if (/^-/);
1137N/A next if (/^Branch/);
116N/A $c = "";
116N/A if (m://.*:) {
116N/A $c = $_;
1137N/A $c =~ s:.*?//\s*(.*)$:$1:;
1137N/A s:(.*?)//.*:$1:;
1137N/A } else {
1137N/A #
1137N/A # look for old style comment
151N/A #
151N/A if (m/\(.*\)/) {
116N/A $c = $_;
151N/A $c =~ s/.*\((.*)\).*$/$1/;
151N/A s/\(.*\)//;
151N/A }
116N/A }
181N/A s/\s$//;
181N/A next if (/^\s*$/);
116N/A ($branch, $status, $who) = split;
1938N/A $status = "new" if (!defined($status));
1938N/A $branches{$branch} = $status;
116N/A $who = "" if (!defined($who));
116N/A $whom{$branch} = $who;
181N/A $comments{$branch} = $c;
116N/A}
181N/Aclose (BRANCHES);
116N/A
116N/A#
3817N/A# Search repository for new branches.
3817N/A#
3817N/Aopen(FILES, "find $repository/$module -type f -name *,v -print |") || die "can't start find: $!";
3817N/Awhile (<FILES>) {
3817N/A chomp;
# print "file: $_\n"; # debug
# $file = $_; # save for branch debug below.
s:^$repository/::;
s:/Attic/([^/]*)$:/$1:;
s:,v$::;
#
# use cvs so that the file is locked.
#
#print "cvs -d $repository rlog -h $_\n";
open(FILE, "cvs -d $repository rlog -h $_|") || die "can't start cvs rlog -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
}
}
chomp while (<FILE>); # let cvs rlog exit normally.
}
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";
print BRANCHES "//\t\t\t\tnew\tnot yet clasified\n";
print BRANCHES "//\t\t\t\topen\tdevelopement branch\n";
print BRANCHES "//\t\t\t\tactive\tnot a development branch\n";
print BRANCHES "//\t\t\t\treview\tready for review\n";
print BRANCHES "//\t\t\t\tprivate\tprivate branch\n";
print BRANCHES "//\t\t\t\tclosed\tfinished with\n";
print BRANCHES "\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", $repository, "commit", "-m", "auto update", "doc/private/branches") || die "cvs commit failed: $!";
} else {
unlink("doc/private/newbranches");
}