d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews#!/usr/local/bin/perl -w
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2005, 2007, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User# $Id$
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews#
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# Track which branches are still open or not in the bind9 cvs repository.
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# This is done so that work that is "in progress" (active) doesn't get
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# so easily forgotten about.
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews#
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# This script updates doc/private/branches by adding new branches and moving
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# closed branches to the end of the file. New branches are found by walking
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# the cvs repository and extracting the new branches from the header fields
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# of the files there.
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews#
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# doc/private/branches has one line per branch in the following field order:
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# name, status, to whom the branch belongs and comments. Comments are
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews# in '(',')'. The first three field are single words.
95317501208f3bf5b159e6a40801b7069f68c486Mark Andrews#
73cac2175470e9068829589476dda8bd6d88036fMark Andrews# Note: this is intended to be run on the machine hosting the CVS repository.
73cac2175470e9068829589476dda8bd6d88036fMark Andrews#
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews%branches = ();
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews%whom = ();
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews%comments = ();
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews%history = ();
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews%dates = ();
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews$repository = "/proj/cvs/prod";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews$module = "bind9";
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
01163d188b89911c3a23fe1125a4cab6764a408cMark Andrews#
01163d188b89911c3a23fe1125a4cab6764a408cMark Andrews# Make sure we have a up to date copy. If the previous ran failed for
01163d188b89911c3a23fe1125a4cab6764a408cMark Andrews# any reason remove it (-C).
01163d188b89911c3a23fe1125a4cab6764a408cMark Andrews#
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews!system("cvs", "-d", $repository, "update", "-C", "doc/private/branches") || die "cannot update doc/private/branches: $!";
648ba62b1f156cbca14d54d06c535385f1193d13Mark 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>) {
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $branch;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $status;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $who;
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews chomp;
35665db4e49e3e4c0e3776e635449f931f3732cfMark Andrews next if (/^-/);
c6313caa6cd9d011ac075048d2b62fd3410162dfMark Andrews next if (/^Branch/);
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrews next if (/^\s/);
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews $c = "";
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews if (m://.*:) {
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews $c = $_;
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews $c =~ s:.*?//\s*(.*)$:$1:;
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews s:(.*?)//.*:$1:;
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews } else {
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews #
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews # look for old style comment
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews #
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews if (m/\(.*\)/) {
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews $c = $_;
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews $c =~ s/.*\((.*)\).*$/$1/;
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews s/\(.*\)//;
bdfd62f497fe0d5281c25b61271595a4c821a040Mark Andrews }
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews }
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrews s/\s*$//;
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews next if (/^\s*$/);
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews ($branch, $status, $who) = split;
64cde9d94a2f6c7050f00d9651df6b05e63d09f2Mark Andrews $status = "new" if (!defined($status));
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews $branches{$branch} = $status;
cbb94d52f98b48e8c3a8866dbf8c67860764f349Mark Andrews $who = "" if (!defined($who));
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews $whom{$branch} = $who;
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews $comments{$branch} = $c;
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews}
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrewsclose (BRANCHES);
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews# T 1999-03-15 21:15 +0000 vixie bind [ietf44:A]
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrewsopen(HISTORY, "cvs history -T -a 2> /dev/null |") || die("can't get history");
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrewswhile (<HISTORY>) {
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $tag;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $date;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $time;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $tz;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $who;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $mod;
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews my $branch;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews chomp;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews s/[][]//g;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews s/:[^ \t]+$//;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews s/\s+/ /g;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews ($tag, $date, $time, $tz, $who, $mod, $branch) = split;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews next if ($mod ne $module );
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews next if ($tag ne "T" );
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews next if (exists($history{$branch}));
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews $history{$branch} = $who;
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews $dates{$branch} = "$date $time $tz";
11b07ea523314b123b4e503ce3813443a018c8d3Mark Andrews # print "$_\n";
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews}
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrewsclose (HISTORY);
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews#
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews# Search repository for new branches.
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews#
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrews# New branches have the following format "name:<revision>.0.#"
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrews# where # is the number of potential branches from this the revision.
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrews#
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrewsopen(FILES, "find $repository/$module -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.
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews s:^$repository/::;
61a03692ab84504fb2bd85b71facfe0f6456b466Mark Andrews s:/Attic/([^/]*)$:/$1:;
61a03692ab84504fb2bd85b71facfe0f6456b466Mark Andrews s:,v$::;
61a03692ab84504fb2bd85b71facfe0f6456b466Mark Andrews #
61a03692ab84504fb2bd85b71facfe0f6456b466Mark Andrews # use cvs so that the file is locked.
61a03692ab84504fb2bd85b71facfe0f6456b466Mark Andrews #
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews #print "cvs -d $repository rlog -h $_\n";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews open(FILE, "cvs -d $repository rlog -h $_|") || die "can't start cvs rlog -h $_: $!";
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews while (<FILE>) {
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews chomp;
8f8634e66351e292925dde8ab6b0418a0141f86aMark Andrews next unless m/^symbolic names:$/; # skip until we find the tags
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews while (<FILE>) {
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews chomp;
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews last if (m/^locks;/); # we are past the tags
61a03692ab84504fb2bd85b71facfe0f6456b466Mark Andrews last if (m/^keyword/); # we are past the tags
68843c99b695bf194b019d465f6d33e6297fd02aMark 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";
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews if (exists($history{$_})) {
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews $whom{$_} = $history{$_};
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews $comments{$_} = $dates{$_};
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews } else {
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews $whom{$_} = "";
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews $comments{$_} = "";
514f6f14245f42c96f3d5e90462ce2ebe0597d2eMark Andrews }
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews # print "branch: $_ $file\n"; # debug
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews }
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews }
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews chomp while (<FILE>); # let cvs rlog exit normally.
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: $!";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrewsprint BRANCHES "\nBranch\t\t\t\tStatus\tWhom\t// Comments\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "-----------------------------------------------------------\n\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "\t\t\t\tnew\t\tnot yet classified\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "\t\t\t\topen\t\tdevelopement branch\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "\t\t\t\tactive\t\tnot a development branch\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "\t\t\t\treview\t\tready for review\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "\t\t\t\tprivate\t\tprivate branch\n";
d6dc0d4f584352d2e4305435599ae8c93776d9b4Mark Andrewsprint BRANCHES "\t\t\t\tclosed\t\tfinished with\n";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrewsprint BRANCHES "\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";
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews print BRANCHES "$whom{$key}";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews print BRANCHES "\t// $comments{$key}" if ($comments{$key} ne "");
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews print BRANCHES "\n";
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews}
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrewsprint BRANCHES "\n\n";
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrewsforeach $key (sort keys %branches) {
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews next if ($branches{$key} ne "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}";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews print BRANCHES "\t\t// $comments{$key}" if ($comments{$key} ne "");
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews print BRANCHES "\n";
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews}
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrewsclose(BRANCHES);
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews#
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews# Update if changed.
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews#
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrewsif (system("cmp", "-s", "doc/private/newbranches", "doc/private/branches")) {
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews rename("doc/private/newbranches", "doc/private/branches") || die "Cannot rename: doc/private/newbranches -> doc/private/branches: $!";
b08e3be5dbfba22719ae9c428bd6853ac6f09798Mark Andrews !system("cvs", "-d", $repository, "commit", "-m", "auto update", "doc/private/branches") || die "cvs commit failed: $!";
f91671c7dc877a52adc06d0a7d0ed1c7f6391e6eMark Andrews} else {
f91671c7dc877a52adc06d0a7d0ed1c7f6391e6eMark Andrews unlink("doc/private/newbranches");
d9b4174233b951f25cd53a2787b9f14314258c2fMark Andrews}