*** empty log message ***
[repair.git] / CVSROOT / cvsprep
1 #!/usr/bin/perl
2 $ID = q(cvsprep,v 1.6 2004/06/12 02:07:09 eagle Exp );
3 #
4 # cvsprep -- Prep a multi-directory commit.
5 #
6 # Written by Russ Allbery <rra@stanford.edu>
7 # Copyright 2001, 2002, 2003, 2004
8 #     Board of Trustees, Leland Stanford Jr. University
9 #
10 # This program is free software; you can redistribute it and/or modify it
11 # under the same terms as Perl itself.
12
13 use Getopt::Long qw(GetOptions);
14 use vars qw($ID);
15
16 Getopt::Long::config ('require_order');
17 GetOptions ('help|h' => \$help, 'version|v' => \$version) or exit 1;
18 if ($help) {
19     print "Feeding myself to perldoc, please wait....\n";
20     exec ('perldoc', '-t', $0);
21 } elsif ($version) {
22     my @version = split (' ', $ID);
23     shift @version if $ID =~ /^\$Id/;
24     my $version = join (' ', @version[0..2]);
25     $version =~ s/,v\b//;
26     $version =~ s/(\S+)$/($1)/;
27     $version =~ tr%/%-%;
28     print $version, "\n";
29     exit;
30 }
31
32 my $directory = shift;
33 die "$0: CVS didn't provide a directory\n" unless $directory;
34 my $tmp = $ENV{TMPDIR} || '/tmp';
35 $tmp .= '/cvs.' . $< . '.' . getpgrp;
36 if (!mkdir ($tmp, 0700)) {
37     if (-l $tmp || !-d _ || (lstat _)[4] != $<) {
38         die "$0: can't create $tmp: $!\n";
39     }
40 }
41 open (LOG, "> $tmp/directory") or die "$0: can't create $tmp/directory: $!\n";
42 print LOG "$directory\n";
43 close LOG;
44 exit 0;
45 __END__
46
47 =head1 NAME
48
49 cvsprep - Prep for a multi-directory CVS commit
50
51 =head1 SYNOPSIS
52
53 B<cvsprep>
54
55 =head1 DESCRIPTION
56
57 This program is designed to run from CVS's F<commitinfo> administrative file
58 and make a note of the last directorie involved in the commit.  It is used to
59 support merging of multi-directory CVS commits into a single notification by
60 B<cvslog> (B<cvslog> knows to stop merging commits when it sees the
61 notification for the final directory recorded by B<cvsprep>).
62
63 It should be run from F<commitinfo> with something like:
64
65     DEFAULT     $CVSROOT/CVSROOT/cvsprep
66
67 If you are using CVS version 1.12.6 or later, the format strings for
68 F<commitinfo> rules have changed.  This line should instead be:
69
70     DEFAULT     $CVSROOT/CVSROOT/cvsprep -- %r/%p
71
72 once you've set UseNewInfoFmtStrings=yes in F<config>.
73
74 The directory in which the commit is occurring is saved in a file named
75 F<directory> in a directory in TMPDIR named cvs.<uid>.<group>, where <uid> is
76 the UID of the committing user and <group> is the process group of the commit
77 process.  If TMPDIR is not used, F</tmp> is used as the parent directory.
78
79 For details on how to install this program as part of a B<cvslog>
80 installation, see cvslog(1).
81
82 =head1 OPTIONS
83
84 =over 4
85
86 =item B<-h>, B<--help>
87
88 Print out this documentation (which is done simply by feeding the script to
89 C<perldoc -t>).
90
91 =item B<-v>, B<--version>
92
93 Print out the version of B<cvsprep> and exit.
94
95 =head1 DIAGNOSTICS
96
97 =item can't create %s: %s
98
99 (Fatal) B<cvsprep> was unable to create either the directory or the file in
100 that directory needed to pass information to B<cvslog>, or the directory
101 already exists and is owned by someone other than the current user.  The
102 directory for this commit won't be recorded, and B<cvslog> will therefore not
103 merge this multi-directory commit.
104
105 =item CVS didn't provide a directory
106
107 (Fatal) No directory was given on the B<cvsprep> command line.  If run out of
108 F<commitinfo> as described above, CVS should pass the name of the directory in
109 which the commit is happening as the first argument to B<cvsprep>.
110
111 =back
112
113 =head1 FILES
114
115 =over 4
116
117 =item TMPDIR/cvs.%d.%d/directory
118
119 B<cvslog> expects this file to contain the name of the final directory
120 affected by a multidirectory commit.  B<cvsprep> creates the parent directory
121 and stores its first argument in this file.
122
123 The first %d is the numeric UID of the user running B<cvslog>.  The second %d
124 is the process group B<cvslog> is part of.  The process group is included in
125 the directory name so that if you're running a shell that calls setpgrp() (any
126 modern shell with job control should), multiple commits won't collide with
127 each other even when done from the same shell.
128
129 If TMPDIR isn't set in the environment, F</tmp> is used for TMPDIR.
130
131 =back
132
133 =head1 ENVIRONMENT
134
135 =over 4
136
137 =item TMPDIR
138
139 If set, specifies the temporary directory to use instead of F</tmp> for
140 storing information about multidirectory commits.  Setting this to some
141 private directory is recommended if you're doing CVS commits on a multiuser
142 machine with other untrusted users due to the standard troubles with safely
143 creating files in F</tmp>.  (Note that other programs besides B<cvslog> also
144 use TMPDIR.)
145
146 =back
147
148 =head1 WARNINGS
149
150 B<cvsprep> inherently creates directories in TMPDIR (F</tmp> by default) with
151 very predictable names.  It creates directories rather than files because this
152 should be less risky, but this is still something of a security risk.  Because
153 of this, I highly recommend that you set TMPDIR to some other directory that
154 only you have write access to, such as a subdirectory of your home directory.
155
156 For more warnings, see cvslog(1).
157
158 =head1 NOTES
159
160 This process of noting the final directory of a commit so that B<cvslog> knows
161 when to stop merging is a horrible hack.  There's just no better way to do it
162 given how CVS handles commit notification, which is completely undocumented
163 and truly bizarre.
164
165 =head1 SEE ALSO
166
167 cvs(1), cvsprep(1).
168
169 Current versions of this program are available from the cvslog web site at
170 L<http://www.eyrie.org/~eagle/software/cvslog/>.  B<cvslog> is available from
171 this same location.
172
173 =head1 AUTHOR
174
175 Russ Allbery <rra@stanford.edu>.
176
177 =head1 COPYRIGHT AND LICENSE
178
179 Copyright 2001, 2002, 2003, 2004  Board of Trustees, Leland Stanford Jr.
180 University.
181
182 This program is free software; you can redistribute it and/or modify it under
183 the same terms as Perl itself.
184
185 =cut