English 中文(简体)
Use the commit message in a CVS pre-commit hook
原标题:

Is it possible to use the commit message in a pre-commit hook in CVS? The CVS server is running remotely, and I access it using pserver.

Ideally, I want to allow the commit if the files pass the filter or the commit message contains certain text.

I don t have a choice to use another versioning system.

最佳回答

Here are some useful tutorials to read more:

http://durak.org/sean/pubs/software/cvsbook/The-commitinfo-And-loginfo-And-rcsinfo-Files.html
http://durak.org/sean/pubs/software/cvsbook/The-verifymsg-And-rcsinfo-Files.html#The-verifymsg-And-rcsinfo-Files

You can t do what you want with just one hook but you can use two hooks, commitinfo will let you verify the files themselves and verifymsg will let you verify the message. Both can be used to cancel the commit (the programs just need to exit with status 1). In case you weren t aware, checkoutlist, commitinfo and verifymsg can all be found in the CVSROOT directory of your repository. I would recommend putting any scripts you write as hooks in that directory as well, but it doesn t really matter as you get to specify the full path. Also, perl is not necessary or required, just simple for me to write some (silly) examples in:

checkoutlist

# these files will be automatically checked out for you
acceptable

verifymsg

# specifies which file to run as hook, %l is filename of log message
# bar$     /path/to/repo/CVSROOT/verify_ends_in_bar %l
DEFAULT    /path/to/repo/CVSROOT/acceptable %l %s

acceptable

#/usr/bin/perl -w

use strict;
use warnings;

# this would be simpler if cvs passed sane arguments
my ($logfile, $dir, @files) = @ARGV;
my $grep = `grep -i  accept liability  $logfile`;
exit 0 if $grep;

my $found = 0;
foreach my $file (@files) {
    my $path = join  / , $dir, $file;
    die "Can t find file $path" if ! -e $path;
    my $grep = `grep -i  evidence of any deliberation  $path`;
    $found++ if $grep;
}
die "You must accept liability or show evidence of deliberation" if $found < @files;

Caveat emptor: I wrote most of this off the top of my head with no testing so I can t guarantee it works but it should get you at least close.

Edit again, I just realized that I was originally wrong and you can pass both the logfile and the committed filenames to verifymsg making the answer quite a bit simpler.

问题回答

The CVS::Trigger Perl module seems to have an experimental feature that allows for caching values between the call of different triggers. The page explicitly mentions passing the filenames from commitinfo to verifymsg, so maybe it helps you to achieve what you want.

You can use the verifymsg file in the CVSROOT directory. You can configure it to call a script which can verify the contents of the checkin comment. You can reject the commit by returning non-zero.

The default verifymsg file contains more details.

I have been dealing with the same issue. So far my best solution has been to get the parent process Id (getppid()) and use it ina temp file that I can put the list of files into from commitinfo. This parent ID seems to be the same for the verifymsg process (on AIX at least). Good luck.





相关问题
Tracking Versions, Builds, Revisions, with TortiseSVN

I am the sole developer on a project and have been using tortoiseSVN for quite a while. Now Id like to start getting version information working correctly in the project I.E. show Major Version, Minor ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

How to handle different csproj [closed]

I am working in a team of five. We are working on a C# application with five csprojects. The problem is that for each csproject, each of my colleagues has their own ideas on how to reference a DLL; ...

Changing username in SVN+SSH URI on the fly in working copy

I am using SVN+SSH to check out a working copy of repository from an SVN server on which all developers are members of a developer group and have full read/write permissions on the repository ...

How to search for file in subversion server?

Is there a way to search for a file in a subversion repository? Something similar to Unix find command, with which I can find the location of a file in a repository. I know there is svn list, but ...

热门标签