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