update_branches 5.36 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/local/bin/perl -w
#
# Copyright (C) 2005  Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

Mark Andrews's avatar
Mark Andrews committed
17
# $Id: update_branches,v 1.14 2005/05/17 03:36:44 marka Exp $
Mark Andrews's avatar
Mark Andrews committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#
#  Track which branches are still open or not in the bind9 cvs repository.
#  This is done so that work that is "in progress" (active) doesn't get
#  so easily forgotten about.
#
#  This script updates doc/private/branches by adding new branches and moving
#  closed branches to the end of the file.  New branches are found by walking
#  the cvs repository and extracting the new branches from the header fields
#  of the files there.
#
#  doc/private/branches has one line per branch in the following field order:
#  name, status, to whom the branch belongs and comments.  Comments are
#  in '(',')'.  The first three field are single words.
#
Mark Andrews's avatar
Mark Andrews committed
33
34
35
36

%branches = ();
%whom = ();
%comments = ();
37
38
$repository = "/proj/cvs/prod";
$module = "bind9";
Mark Andrews's avatar
Mark Andrews committed
39

Mark Andrews's avatar
Mark Andrews committed
40
41
42
43
#
# Make sure we have a up to date copy.  If the previous ran failed for
# any reason remove it (-C).
#
44
!system("cvs", "-d", $repository, "update", "-C", "doc/private/branches") || die "cannot update doc/private/branches: $!";
Mark Andrews's avatar
Mark Andrews committed
45

Mark Andrews's avatar
Mark Andrews committed
46
47
48
49
50
51
#
# load existing content
#
open(BRANCHES, "<doc/private/branches") || die "can't open util/branches: $!";
while (<BRANCHES>) {
	chomp;
Mark Andrews's avatar
Mark Andrews committed
52
	next if (/^-/);
Mark Andrews's avatar
Mark Andrews committed
53
	next if (/^Branch/);
Mark Andrews's avatar
Mark Andrews committed
54
	$c = "";
Mark Andrews's avatar
Mark Andrews committed
55
	if (m://.*:) {
Mark Andrews's avatar
Mark Andrews committed
56
		$c = $_;
57
		$c =~ s:.*?//\s*(.*)$:$1:;
Mark Andrews's avatar
Mark Andrews committed
58
59
		s:(.*?)//.*:$1:;
	} else {
60
61
62
		#
		# look for old style comment
		#
Mark Andrews's avatar
Mark Andrews committed
63
64
65
66
67
		if (m/\(.*\)/) {
			$c = $_;
			$c =~ s/.*\((.*)\).*$/$1/;
			s/\(.*\)//;
		}
Mark Andrews's avatar
Mark Andrews committed
68
	}
Mark Andrews's avatar
update    
Mark Andrews committed
69
	s/\s$//;
Mark Andrews's avatar
Mark Andrews committed
70
71
	next if (/^\s*$/);
	($branch, $status, $who) = split;
Mark Andrews's avatar
update    
Mark Andrews committed
72
	$status = "new" if (!defined($status));
Mark Andrews's avatar
Mark Andrews committed
73
	$branches{$branch} = $status;
Mark Andrews's avatar
update    
Mark Andrews committed
74
	$who = "" if (!defined($who));
Mark Andrews's avatar
Mark Andrews committed
75
76
77
78
79
80
81
82
	$whom{$branch} = $who;
	$comments{$branch} = $c;
}
close (BRANCHES);

#
# Search repository for new branches.
#
83
open(FILES, "find $repository/$module -type f -name *,v -print |") || die "can't start find: $!";
Mark Andrews's avatar
Mark Andrews committed
84
85
86
87
while (<FILES>) {
	chomp;
	# print "file: $_\n"; # debug
	# $file = $_; # save for branch debug below.
88
	s:^$repository/::;
Mark Andrews's avatar
Mark Andrews committed
89
90
91
92
93
	s:/Attic/([^/]*)$:/$1:;
	s:,v$::;
	#
	# use cvs so that the file is locked.
	#
94
95
	#print "cvs -d $repository rlog -h $_\n";
	open(FILE, "cvs -d $repository rlog -h $_|") || die "can't start cvs rlog -h $_: $!";
Mark Andrews's avatar
Mark Andrews committed
96
97
98
99
100
101
	while (<FILE>) {
		chomp;
		next unless m/^symbols$/;	# skip until we find the tags
		while (<FILE>) {
			chomp;
			last if (m/^locks;/);	# we are past the tags
Mark Andrews's avatar
Mark Andrews committed
102
			last if (m/^keyword/);	# we are past the tags
Mark Andrews's avatar
Mark Andrews committed
103
104
105
106
107
108
109
110
111
			next unless m/\.0\.\d$/; # skip if not a branch
			s/\s(.*):.*/$1/;	# extract label
			if (!$branches{$_}) {
				$branches{$_} = "new";
				$whom{$_} =  "";
				$comments{$_} =  "";
				# print "branch: $_ $file\n"; # debug
			}
		}
112
		chomp while (<FILE>);	# let cvs rlog exit normally.
Mark Andrews's avatar
Mark Andrews committed
113
114
115
116
117
118
119
120
121
	}
	close(FILE);
}
close(FILES);

#
# Write out updated version.
#
open(BRANCHES, ">doc/private/newbranches") || die "can't open doc/private/branches: $!";
122
print BRANCHES "\nBranch\t\t\t\tStatus\tWhom\t// Comments\n";
Mark Andrews's avatar
Mark Andrews committed
123
print BRANCHES "----------------------------------------------------------\n\n";
Mark Andrews's avatar
Mark Andrews committed
124
print BRANCHES "//\t\t\t\tnew\tnot yet classified\n";
125
126
127
128
129
130
print BRANCHES "//\t\t\t\topen\tdevelopement branch\n";
print BRANCHES "//\t\t\t\tactive\tnot a development branch\n";
print BRANCHES "//\t\t\t\treview\tready for review\n";
print BRANCHES "//\t\t\t\tprivate\tprivate branch\n";
print BRANCHES "//\t\t\t\tclosed\tfinished with\n";
print BRANCHES "\n";
Mark Andrews's avatar
Mark Andrews committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
foreach $key (sort keys %branches) {
	next if ($branches{$key} eq "closed");
	print BRANCHES "$key";
	$len = length($key);
	if ($len >= 32) {
		$tabs = 1;
	} else {
		$needed = int (32 - $len);
		$tabs = int ($needed / 8);
		if ($needed % 8 != 0) {
			$tabs++;
		}
	}
	for ($i = 0; $i < $tabs; $i++) {
		printf	BRANCHES "\t";
	}
	print BRANCHES "$branches{$key}\t";
	print BRANCHES "$whom{$key}";
149
	print BRANCHES "\t// $comments{$key}" if ($comments{$key} ne "");
Mark Andrews's avatar
Mark Andrews committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	print BRANCHES "\n";
}

print BRANCHES "\n\n";

foreach $key (sort keys %branches) {
	next if ($branches{$key} ne "closed");
	print BRANCHES "$key";
	$len = length($key);
	if ($len >= 32) {
		$tabs = 1;
	} else {
		$needed = int (32 - $len);
		$tabs = int ($needed / 8);
		if ($needed % 8 != 0) {
			$tabs++;
		}
	}
	for ($i = 0; $i < $tabs; $i++) {
		printf	BRANCHES "\t";
	}
	print BRANCHES "$branches{$key}";
172
	print BRANCHES "\t\t// $comments{$key}" if ($comments{$key} ne "");
Mark Andrews's avatar
Mark Andrews committed
173
174
175
176
177
178
179
180
181
	print BRANCHES "\n";
}
close(BRANCHES);

#
# Update if changed.
#
if (system("cmp", "-s", "doc/private/newbranches", "doc/private/branches")) {
	rename("doc/private/newbranches", "doc/private/branches") || die "Cannot rename: doc/private/newbranches -> doc/private/branches: $!";
182
	!system("cvs", "-d", $repository, "commit", "-m", "auto update", "doc/private/branches") || die "cvs commit failed: $!";
Mark Andrews's avatar
tidy up    
Mark Andrews committed
183
184
} else {
	unlink("doc/private/newbranches");
Mark Andrews's avatar
Mark Andrews committed
185
}