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