[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Group permissions to branches

From: Brian Poynor
Subject: Re: Group permissions to branches
Date: Tue, 9 Apr 2002 15:23:46 -0700
User-agent: Mutt/

On Tue, Apr 09, 2002 at 05:19:58PM -0400, Danial Islam wrote:
> Thanks a lot for the reply. Yes, I did notice the CVS/Tag file before, and I
> wrote a simple shell script with commitinfo and checkoutlist.  But you are
> right that CVS/Entries should be checked instead.   I don't know how to do
> this with a shell script, and I don't know Perl either.

It takes a lot of work to do in shell, but fairly easy in Perl. Might
be worth your time learning Perl or Python, if you do this sort of
thing much.

> Here is my shell script, attached. Perhaps you know how I can fix it up, or
> maybe I can have a look at your code?

In Perl, you can do something like (extracted from a much more
complicated script, not tested as-is):

# read the entries branch info into a hash

foreach $entries ("CVS/Entries", "CVS/Entries.Log") {
    if (open FILE, $entries) {
        while (<FILE>) {
           ($file, $branch) = (split '/')[1,5];
           $branch = 'Trunk' unless $branch =~ s/^T//;
           $branches{$file} = $branch;
        close FILE;

# use the branch of the first committed file as a reference 
# make sure all files are on the same branch

# given: @files is a list of files being committed in this dir

$branch = $branches{shift @files};

foreach (@files) {
    if ($branches{$_} ne $branch) {
        print STDERR
            "You must commit to a single branch in each commit.\n",
            "Attempt to commit to both $branch and $branches{$_}\n\n";
        exit 1;

# check if the user is able to commit to this branch
# keep a list of usernames in a file named "$CVSROOT/writers-$branch"

if (open FILE, "$ENV{CVSROOT}/writers-$branch") {
    $user = getpwuid $<;
    $found = 0;
    while (<FILE>) {
        /^$user\b/o and found = 1, last;
    close FILE;
    unless ($found) {
        if ($branch eq "Trunk") {
            print STDERR
                "You are not allowed to commit to the Trunk\n\n";
        } else {
            print STDERR
                "You are not allowed to commit to branch $branch\n\n";
        exit 1;

Hope this helps.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]