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