You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Noam Tamim <no...@gmail.com> on 2005/11/01 20:51:26 UTC
hook scripts: only commit if locked
Hi,
Our svn repository contains files (VS.Net project files) that must not be
edited by more than one user simultaneously (merging them makes no sense).
For these files, we want to work in a SourceSafe-like mode.
1. What's the correct way to do it? I'm sure we're not the first svn users
to come across this problem, so possibly there's a configuration item for
that.
2. As an attempt to solve this problem, we added the needs-lock property to
these files - so that they are read-only until a user requests the lock. The
problem is that if a user manually resets the read-only flag on the file, he
can change it and then commit - without first acquiring a lock. I read that
we can use the hook scripts for that - but the start-commit and pre-commit
hooks don't pass the file and its state to the script, so it can't verify
the commit. Am I missing something?
3. It's also possible that we totally miss the purpose and usage of locks;
we've been using SourceSafe so far, so please understand (and explain) :-)
Thanks,
Noam.
Re: hook scripts: only commit if locked
Posted by si <ss...@gmail.com>.
> What I really want, is the ability to enforce the following rule:
> A user can only commit changes to a needs-lock file if he/she has locked
> that file.
> Is it possible, with some configuration or hook scripts?
Sure, the pre-commit hook combined with calls to svnlook.
http://svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html#svn.reposadmin.create.hooks
First thing i'd do is see if the svn:needs-lock property is set on
any of the files in the transaction, do this using 'svnlook proplist'.
If there are none, then pass that part of your pre-commit hook.
If you do find svn:needs-lock, find the transaction author:
http://svnbook.red-bean.com/nightly/en/svn.ref.svnlook.c.author.html
Then iterate through each file in the transction (in case they have
different lock owners), 'svnlook changed' gets your list of files.
On each file you call 'svnlook propget [repos] svn:needs-lock [path/to/file]',
and when found, call 'svnlook lock [repos] [path/to/file]' to validate the lock
owner against the transaction author.
Hmmm...that seems a fairly heavy-handed approach, but i'm unsure how
you can (easilly) list all the locks (and their owners) from a transaction?
Personally i'd probably just use locks as per normal, and try to educate
users not to modify read-only files :) You can always revert back to a
previous revision if they break the rules.
peace
si
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Re: hook scripts: only commit if locked
Posted by Alan Barrett <ap...@cequrux.com>.
On Thu, 03 Nov 2005, Noam Tamim wrote:
> What I really want, is the ability to enforce the following rule:
> A user can only commit changes to a needs-lock file if he/she has locked
> that file.
>
> Is it possible, with some configuration or hook scripts?
You should be able to write a pre-commit script that does something like
get list of files from svnlook
for each file:
if needs-lock and not is-locked:
print error message to stderr
remember that there was an error
if there was an error:
exit with error code
Have a look at contrib/hook-scripts/pre-lock-require-needs-lock.py
which does a different job, but contains examples of the programming
techniques you would need to use.
--apb (Alan Barrett)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Re: hook scripts: only commit if locked
Posted by Noam Tamim <no...@gmail.com>.
I will rephrase my question.
What I really want, is the ability to enforce the following rule:
A user can only commit changes to a needs-lock file if he/she has locked
that file.
Is it possible, with some configuration or hook scripts?
Thanks,
Noam.
Re: hook scripts: only commit if locked
Posted by Bruce Webber <br...@fastmail.us>.
--Noam Tamim <no...@gmail.com> wrote:
> Our svn repository contains files (VS.Net project files) that must not be
> edited by more than one user simultaneously (merging them makes no sense).
> For these files, we want to work in a SourceSafe-like mode.
>
> 1. What's the correct way to do it? I'm sure we're not the first svn users
> to come across this problem, so possibly there's a configuration item for
> that.
>
> 2. As an attempt to solve this problem, we added the needs-lock property
> to these files - so that they are read-only until a user requests the
> lock. The problem is that if a user manually resets the read-only flag on
> the file, he can change it and then commit - without first acquiring a
> lock. I read that we can use the hook scripts for that - but the
> start-commit and pre-commit hooks don't pass the file and its state to
> the script, so it can't verify the commit. Am I missing something?
If User A has a file locked, User B cannot commit the file. This behavior
does not depend on the needs-lock property. (You can lock files that do not
have the needs-lock property set.) The needs-lock property makes the file
read-only to act as a warning for users, indicating that they should lock
the file before making changes.
In addition to setting the needs-lock property on your VS.Net files, you
can implement a post-lock hook that emails your group whenever a file is
locked or unlocked. For our group I set up a simple python script to do
this.
> 3. It's also possible that we totally miss the purpose and usage of locks;
> we've been using SourceSafe so far, so please understand (and explain) :-)
I'm fairly new to version control in general and Subversion in particular,
but I believe that for code (text) files merging is recommended (people can
be more productive), but for binary files locking makes sense. So it sounds
like you are on the right track.
--
Bruce Webber
brucewebber@fastmail.us
http://brucewebber.us
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org