update_branches revision 648ba62b1f156cbca14d54d06c535385f1193d13
385N/A#!/usr/local/bin/perl -w
385N/A#
385N/A# Copyright (C) 2005 Internet Systems Consortium, Inc. ("ISC")
385N/A#
385N/A# Permission to use, copy, modify, and distribute this software for any
385N/A# purpose with or without fee is hereby granted, provided that the above
385N/A# copyright notice and this permission notice appear in all copies.
385N/A#
385N/A# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
385N/A# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
385N/A# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
385N/A# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
385N/A# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
385N/A# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
385N/A# PERFORMANCE OF THIS SOFTWARE.
385N/A
385N/A# $Id: update_branches,v 1.2 2005/05/16 04:27:57 marka Exp $
385N/A
407N/A%branches = ();
1045N/A%whom = ();
1045N/A%comments = ();
1045N/A
1045N/A!system("cvs", "-d", "/proj/cvs/prod", "update", "doc/private/branches") || die "cannot update doc/private/branches: $!";
385N/A
385N/A#
385N/A# load existing content
385N/A#
385N/Aopen(BRANCHES, "<doc/private/branches") || die "can't open util/branches: $!";
385N/Awhile (<BRANCHES>) {
385N/A chomp;
385N/A next if (/----------/);
385N/A next if (/Whom/);
385N/A $c = "";
457N/A if (m/\(.*\)/) {
385N/A $c = $_;
385N/A $c =~ s/.*(\(.*\)).*$/$1/;
385N/A s/\(.*\)//;
385N/A }
385N/A next if (/^\s*$/);
385N/A ($branch, $status, $who) = split;
385N/A #$status = "new" if (!defined($status));
385N/A $branches{$branch} = $status;
385N/A #$who = "-" if (!defined($who));
385N/A $whom{$branch} = $who;
385N/A $comments{$branch} = $c;
385N/A}
385N/Aclose (BRANCHES);
385N/A
385N/A#
385N/A# Search repository for new branches.
385N/A#
385N/Aopen(FILES, "find /proj/cvs/prod/bind9 -type f -name *,v -print |") || die "can't start find: $!";
385N/Awhile (<FILES>) {
385N/A chomp;
385N/A # print "file: $_\n"; # debug
385N/A # $file = $_; # save for branch debug below.
385N/A open(FILE, "<$_") || die "can't open $_: $!";
385N/A while (<FILE>) {
385N/A chomp;
385N/A next unless m/^symbols$/; # skip until we find the tags
385N/A while (<FILE>) {
385N/A chomp;
1045N/A last if (m/^locks;/); # we are past the tags
1045N/A next unless m/\.0\.\d$/; # skip if not a branch
385N/A s/\s(.*):.*/$1/; # extract label
1045N/A if (!$branches{$_}) {
1045N/A $branches{$_} = "new";
1045N/A $whom{$_} = "";
1045N/A $comments{$_} = "";
1045N/A # print "branch: $_ $file\n"; # debug
1045N/A }
1045N/A }
1045N/A last;
385N/A }
1045N/A close(FILE);
1045N/A}
385N/Aclose(FILES);
1045N/A
1045N/A#
1045N/A# Write out updated version.
1045N/A#
385N/Aopen(BRANCHES, ">doc/private/newbranches") || die "can't open doc/private/branches: $!";
1045N/Aprint BRANCHES "\nBranch\t\t\t\tStatus\tWhom\n";
1045N/Aprint BRANCHES "-------------------------------------------------------\n\n";
1045N/Aforeach $key (sort keys %branches) {
1045N/A next if ($branches{$key} eq "closed");
1045N/A print BRANCHES "$key";
1045N/A $len = length($key);
385N/A if ($len >= 32) {
1045N/A $tabs = 1;
385N/A } else {
1045N/A $needed = int (32 - $len);
385N/A $tabs = int ($needed / 8);
1045N/A if ($needed % 8 != 0) {
385N/A $tabs++;
1045N/A }
385N/A }
1045N/A for ($i = 0; $i < $tabs; $i++) {
385N/A printf BRANCHES "\t";
1045N/A }
1045N/A print BRANCHES "$branches{$key}\t";
1045N/A print BRANCHES "$whom{$key}";
1045N/A print BRANCHES "\t$comments{$key}" if ($comments{$key} ne "");
1045N/A print BRANCHES "\n";
1045N/A}
1045N/A
1045N/Aprint BRANCHES "\n\n";
1045N/A
1045N/Aforeach $key (sort keys %branches) {
1045N/A next if ($branches{$key} ne "closed");
1045N/A print BRANCHES "$key";
385N/A $len = length($key);
1045N/A if ($len >= 32) {
1045N/A $tabs = 1;
1045N/A } else {
1045N/A $needed = int (32 - $len);
1045N/A $tabs = int ($needed / 8);
1045N/A if ($needed % 8 != 0) {
1045N/A $tabs++;
1045N/A }
1045N/A }
1045N/A for ($i = 0; $i < $tabs; $i++) {
1045N/A printf BRANCHES "\t";
1045N/A }
1045N/A print BRANCHES "$branches{$key}";
1045N/A print BRANCHES "\t\t$comments{$key}" if ($comments{$key} ne "");
1045N/A print BRANCHES "\n";
1045N/A}
1045N/Aclose(BRANCHES);
1045N/A
1045N/A#
1045N/A# Update if changed.
1045N/A#
1045N/Aif (system("cmp", "-s", "doc/private/newbranches", "doc/private/branches")) {
1045N/A rename("doc/private/newbranches", "doc/private/branches") || die "Cannot rename: doc/private/newbranches -> doc/private/branches: $!";
1045N/A !system("cvs", "-d", "/proj/cvs/prod", "commit", "-m", "auto update", "doc/private/branches") || die "cvs commit failed: $!";
1045N/A}
385N/A