Feedback

Articles → How To Use Locks

This article briefly describes Subversion locking and its implementation in MangenSVN.

Index

Subversion Version Control Models

Using Locks in MagnetSVN

Special Locks Manipulation

Setting Needs Lock Flag

Subversion is a flexible system that allows you to use different versioning models.

Subversion Version Control Models

Subversion can be used in two different ways (or version control models):

  • 1. Copy-modify-merge or
  • 2. Lock-modify-unlock.

First model allows several users to work on the same document at the same time. They modify copies of the repository document on their local computers and then Subversion merges their changes into one document on the server when they press Commit button.

However this model can lead to modification conflicts, when the same part of the file modified differently by different users. Generally Subversion should know how to merge changes in the file to use the first model. This is available only for plain text files, not for binary files, which are in fact Microsoft Office documents in theirs' native format. That's why it's necessary to use the second model when you store Microsoft Office document under Subversion control.

The second model enables one user only to edit the file at any given moment of time while other users can only view the document. Subversion uses locking to make sure that there are no two users that edit the document at the same time.

Using Locks in MagnetSVN

After you've taken the lock for the document you can commit changes in it.
Get Lock

Anybody else except you cannot commit while you have the lock.
Cannot Commit No Lock

You can make as many commits as you need during the time you keep the lock. After you've finished editing release the lock to enable other users making their changes.
Release Lock

If you don't use locks, every concurrent edit will lead to conflict for Microsoft Office documents and you will have to choose using either your or other's changes only. By the way, you can merge Office documents while resolving conflicts but it is rather complicated.

Special Locks Manipulation

There are special cases when you get or release Subversion lock.

When you are trying to get lock for the document which is already locked by somebody else, you will receive warning. You may choose whether to steal other's lock or not.
Steal Lock

After you've stolen the lock you may modify and commit the document while the previous lock owner may not.

Stealing locks is not a good practice. Do it only if you are sure other user doesn't need it anymore. Otherwise ask you colleague to commit her changes and release lock for you to make changes.

Other case is when you need to remove someone's lock without getting new one. It can be done by pressing release lock key and confirming that you want to break lock if any.
Break Lock

Remember that Subversion locks don't guarantee you will never get a conflict. This is a communication mechanism aimed to decrease number of modification conflicts.

Setting Needs Lock Flag

Needs Lock flag is another useful feature of Subversion locking available in MagnetSVN. To set this flag for the document use Toggle Needs Lock button. Confirm getting lock if you want to modify the document after that.
Set Needs Lock

After you pressed set Needs Lock property document status changes to either "Props Modified" or "Locked". Press Commit button to commit Needs Lock property to the repository. This will apply Needs Lock setting for every person who uses the document after she updates it.
Commit Set Needs Lock Property

When Needs Lock property is set for the document it changes default Subversion and Microsoft Office behavior for this document.

1. When Needs Lock property is set and there is no lock exists for the document, it becomes read-only in Microsoft Office.
Read-only When Needs Lock Is Set And No Lock

You cannot save changes in the document with its current name until you get lock.
Cannot Save Read-only Document With Its Name

2. When Needs Lock property is set and you successfully got the lock the document become read-write in Microsoft Office again. You can press Commit button when you have unsaved changes in read-only document and MagnetSVN will prompt to get lock, save your changes and commit them automatically.
Propmt to Get Lock and Commit Unsaved Changes in Document with Needs Lock Property

You can save changes in the document and commit them. Do not forget to release lock when you've finished changing the document.
Propmt to Release Lock and Commit Changes before Document Close

It is a good practice to set Needs Lock property for every document that can be edited by two or more people. Microsoft Office will open document that are not locked as read-only. This will prevent document from accidental modifications and you will not make useless changes anymore.
Propmt to Commit Changes before Document Close

Go back to Article Index.