11.07.2015 Views

Version Control with Subversion - Login

Version Control with Subversion - Login

Version Control with Subversion - Login

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advanced TopicsThe second is working copy locks, used internally by <strong>Subversion</strong> to prevent clashesbetween multiple <strong>Subversion</strong> clients operating on the same working copy. This is thesort of lock indicated by an L in the third column of svn status output, and removedby the svn cleanup command, as described in the section called “Sometimes YouJust Need to Clean Up”.Third, there are database locks, used internally by the Berkeley DB backend to preventclashes between multiple programs trying to access the database. This is thesort of lock whose unwanted persistence after an error can cause a repository to be“wedged,” as described in the section called “Berkeley DB Recovery”.You can generally forget about these other kinds of locks until something goes wrongthat requires you to care about them. In this book, “lock” means the first sort unlessthe contrary is either clear from context or explicitly stated.Creating LocksIn the <strong>Subversion</strong> repository, a lock is a piece of metadata that grants exclusive access toone user to change a file. This user is said to be the lock owner. Each lock also has aunique identifier, typically a long string of characters, known as the lock token. The repositorymanages locks, ultimately handling their creation, enforcement, and removal. If anycommit transaction attempts to modify or delete a locked file (or delete one of the parentdirectories of the file), the repository will demand two pieces of information—that the clientperforming the commit be authenticated as the lock owner, and that the lock token hasbeen provided as part of the commit process as a form of proof that the client knows whichlock it is using.To demonstrate lock creation, let's refer back to our example of multiple graphic designersworking on the same binary image files. Harry has decided to change a JPEG image. Toprevent other people from committing changes to the file while he is modifying it (as well asalerting them that he is about to change it), he locks the file in the repository using the svnlock command.$ svn lock banana.jpg -m "Editing file for tomorrow's release."'banana.jpg' locked by user 'harry'.$The preceding example demonstrates a number of new things. First, notice that Harrypassed the --message (-m) option to svn lock. Similar to svn commit, the svn lockcommand can take comments—via either --message (-m) or --file (-F)—to describethe reason for locking the file. Unlike svn commit, however, svn lock will not demand amessage by launching your preferred text editor. Lock comments are optional, but still recommendedto aid communication.Second, the lock attempt succeeded. This means that the file wasn't already locked, andthat Harry had the latest version of the file. If Harry's working copy of the file had been outof date, the repository would have rejected the request, forcing Harry to svn update andreattempt the locking command. The locking command would also have failed if the filehad already been locked by someone else.As you can see, the svn lock command prints confirmation of the successful lock. At thispoint, the fact that the file is locked becomes apparent in the output of the svn status andsvn info reporting subcommands.$ svn statusK banana.jpg64

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!