1. Store Any Kind of File
Let’s imagine that you have a binary document that you want to store in the repository. Such a file might be a user manual or some other file for which there generally should be just one copy. On the other hand, you might decide to add your digital photo files to the repository.
The point is that it’s very easy to add a text or binary file to a Subversion repository as illustrated in Listing 6, in which I created a Word document named WDoc.doc and then added it to the C:\repworkarea\repo working copy subfolder:
Listing 6 A new file is added to the trunk
C:\repworkarea\repo>dir Volume in drive C has no label. Volume Serial Number is C05C-1CEC Directory of C:\repworkarea\repo 07/20/2007 05:44 PM <DIR> . 07/20/2007 05:44 PM <DIR> .. 07/20/2007 05:43 PM 11 aFile.txt 07/20/2007 05:43 PM 11 anotherFile.txt 07/20/2007 05:29 PM 19,456 WDoc.doc
Now, how do we get this new file into the repository? Easy, just run the command in Listing 7:
Listing 7 Adding a binary file to the repository
C:\repworkarea\repo>svn add WDoc.doc A (bin) WDoc.doc
The result of adding the file in Listing 7 is that it is then automatically scheduled for addition to the central repository the next time you do a commit. The format for the commit command is illustrated at the beginning of Listing 8. The message can include more information than my rather pithy New file. In multiuser environments, it’s good practice to include meaningful text descriptions.
The second command in Listing 8 includes an information request about the file just committed.
Listing 8 Committing the new file and requesting information
C:\repworkarea\repo>svn commit -m "New file" Adding (bin) WDoc.doc Transmitting file data . Committed revision 2. C:\repworkarea\repo>svn info WDoc.doc Path: WDoc.doc Name: WDoc.doc URL: file:///c:/repository/repo/WDoc.doc Repository Root: file:///c:/repository/repo Repository UUID: c4d4b254-7f37-4741-9e14-aed34f2e59a2 Revision: 2 Node Kind: file Schedule: normal Last Changed Author: Stephen Last Changed Rev: 2 Last Changed Date: 2007-07-20 18:38:54 +0100 (Fri, 20 Jul 2007) Text Last Updated: 2007-07-20 17:29:31 +0100 (Fri, 20 Jul 2007) Properties Last Updated: 2007-07-20 17:44:32 +0100 (Fri, 20 Jul 2007) Checksum: a78597ec1bcea5d0ebb476b07a68975b
Notice the informational details that are used to describe the file WDoc.doc. The same level of information applies for all files that reside in the repository including the following:
- The central repository file
- The repository UUID—a unique number that differentiates each repository
- The revision level
- The type of entity
So we now have a binary file and two text files stored in the repository. Any changes to those files will be available to all the client working copies. In other words, our files are now under version control.
Instead of just storing a few text files and a Word file, it’s more likely you’ll be using Subversion to store a great many source code files. The latter also generally includes script files (for example, using Ant) to actually build the software.