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