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