Advertisement
xdxdxd123

Untitled

May 22nd, 2017
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 204.88 KB | None | 0 0
  1. What Readers Are Saying AboutPragmatic Guide to Subversion
  2. Mike has been around the block with Subversion and knows the toolset
  3. intimately. Just as importantly, he’s seen firsthand how it’s used on real
  4. projects. Those two aspects come together in this book with the fundamen-
  5. tals of source control with Subversion, guided by real-world, pragmatic (of
  6. course!) experience. As a Subversion user and occasional noob, this is the
  7. book I want to guide me day to day and dig me out of those irksome holes.
  8. Jim Webber
  9. Author, REST in Practice
  10. I really like the organization of the book. I found Pragmatic Guide to Sub-
  11. version to be very easy to read, and it really gets the information across in
  12. an engaging way. This book is clear, concise, and comprehensive. It’s an
  13. indispensable reference for anyone working with Subversion.
  14. Ian Bourke
  15. Independent software developer, UK
  16. A good digest of Subversion’s capabilities. The author’s writing style is
  17. terse yet conversational, and the book progressed nicely from basic topics
  18. to those more advanced. Overall, I think the book is an excellent follow-up
  19. to Pragmatic Version Control Using Subversion.
  20. Graham Nash
  21. Retlang, Message-based concurrency in .NET
  22. This is a book worth having since the “full” Pragmatic Subversion book is
  23. too big for every developer on a team to read. I was a fan of Mike’s original
  24. Subversion book, and he’s carried on the style into this pocket reference.
  25. This is a book I recommend.
  26. Mike Roberts
  27. Senior software engineer, DRW Trading Group
  28. Pragmatic Guide to Subversion has everything I needed to get up and run-
  29. ning with SVN on my Mac. Being new to Mac OS X, it was a welcome sur-
  30. prise to have examples in multiple operating systems.
  31. Michael Raczynski
  32. Software architect, Canada
  33. PragmaticGuidetoSubversion
  34. Mike Mason
  35. The Pragmatic Bookshelf
  36. Raleigh, North Carolina Dallas, Texas
  37. Many of the designations used by manufacturers and sellers to distinguish their products are
  38. claimed as trademarks. Where those designations appear in this book, and The Pragmatic Pro-
  39. grammers, LLC was aware of a trademark claim, the designations have been printed in initial
  40. capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic
  41. Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic
  42. Programmers, LLC.
  43. Every precaution was taken in the preparation of this book. However, the publisher assumes no
  44. responsibility for errors or omissions, or for damages that may result from the use of information
  45. (including program listings) contained herein.
  46. Our Pragmatic courses, workshops, and other products can help you and your team create better
  47. software and have more fun. For more information, as well as the latest Pragmatic titles, please
  48. visit us at http://www.pragprog.com.
  49. The team that produced this book includes:
  50. Editor: Jackie Carter
  51. Indexing: Potomac Indexing, LLC
  52. Copy edit: Kim Wimpsett
  53. Layout: Steve Peter
  54. Production: Janet Furlow
  55. Customer support: Ellie Callahan
  56. International: Juliet Benda
  57. Copyright © 2010 Pragmatic Programmers, LLC.
  58. All rights reserved.
  59. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any
  60. form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the
  61. prior consent of the publisher.
  62. Printed in the United States of America.
  63. ISBN-10: 1-934356-61-1
  64. ISBN-13: 978-1-934356-61-6
  65. Printed on acid-free paper.
  66. P1.0 printing, October 2010
  67. Version: 2010-11-12
  68. Contents
  69. Acknowledgments 8
  70. Introduction 9
  71. Who Is This Book For? . . . . . . . . . . . . . . . . . . . . 10
  72. How to Read This Book . . . . . . . . . . . . . . . . . . . . 11
  73. Subversion Versions . . . . . . . . . . . . . . . . . . . . . . 12
  74. Online Resources . . . . . . . . . . . . . . . . . . . . . . . 12
  75. I Getting Started 13
  76. Task 1. Installing a Command-Line Client 16
  77. Task 2. Installing a Graphical Client on Windows 18
  78. Task 3. Installing a Graphical Client on Mac OS X 20
  79. Task 4. Creating a Local Repository 22
  80. Task 5. Creating an Empty Project 24
  81. Task 6. Creating a Project from an Existing Source Tree 26
  82. II Working with Subversion 28
  83. Task 7. Checking Out a Working Copy 32
  84. Task 8. Seeing What You’ve Changed 34
  85. Task 9. Seeing What You’ve Changed Using Tortoise 36
  86. Task 10. Seeing What You’ve Changed Using Cornerstone 38
  87. Task 11. Committing Changes 40
  88. Task 12. Adding Files and Directories 42
  89. CONTENTS 6
  90. Task 13. Removing Files and Directories 44
  91. Task 14. Moving and Renaming Files and Directories 46
  92. Task 15. Reverting Working Copy Changes 48
  93. Task 16. Ignoring Files 50
  94. III Working with a Team 52
  95. Task 17. Updating to the Latest Revision 56
  96. Task 18. Handling Conflicts 58
  97. Task 19. Handling Conflicts Using Tortoise 60
  98. Task 20. Handling Conflicts Using Cornerstone 62
  99. IV Using the History 64
  100. Task 21. Viewing the Log 66
  101. Task 22. Detective Work with svn blame 68
  102. Task 23. Reverting a Committed Revision 70
  103. V Branching, Merging, and Tagging 72
  104. Task 24. Creating a Branch 78
  105. Task 25. Switching to a Branch 80
  106. Task 26. Merging Changes from Trunk to Branch 82
  107. Task 27. Using Change Tracking 84
  108. Task 28. Tagging a Release 86
  109. VI File Locking 88
  110. Task 29. Enabling File Locking 92
  111. Task 30. Obtaining a Lock 94
  112. Task 31. Releasing a Lock 96
  113. Task 32. Breaking Someone Else’s Lock 98
  114. Report erratum
  115. CONTENTS 7
  116. VII Setting Up a Server 100
  117. Task 33. Installing Subversion Server 104
  118. Task 34. Creating a Repository 106
  119. Task 35. Installing Subversion Server on Windows 108
  120. Task 36. Using Third-Party Subversion Hosting 110
  121. Task 37. Migrating a CVS Repository 112
  122. Task 38. Backing Up and Restoring 114
  123. Task 39. Performing Full Weekly Backups 116
  124. Task 40. Performing Incremental Daily Backups 118
  125. Task 41. Securing a Repository 120
  126. Task 42. Using Repository Hooks 122
  127. VIII Advanced Topics 124
  128. Task 43. Working with Properties 126
  129. Task 44. Using Externals 128
  130. Task 45. Organizing Multiple Projects 130
  131. Task 46. Storing Third-Party Code 132
  132. Task 47. Working Directly with the Repository 134
  133. Task 48. Using Patch Files 136
  134. A Bibliography 138
  135. Index 139
  136. Report erratum
  137. Acknowledgments
  138. Every book—even a shorter one like this Pragmatic Guide—represents an
  139. incredible amount of work by a large group of people. As an author, my con-
  140. tribution is only a fraction of the effort that’s required to get a book into the
  141. hands of readers, and I’d like to thank everyone else involved.
  142. First and foremost, I’d like to thank my family for supporting me while writ-
  143. ing another book. I’m a new dad with a young son at home, and despite my
  144. best efforts to write faster, our daughter arrived too before I finished the book.
  145. So, to my wife, Michelle, and her mom, Pat, thanks for taking care of the kids
  146. and letting me have those Sundays in the office writing the book. To Ben and
  147. Natalie, thanks for not being too upset when “Daddy working!” I promise to
  148. always come home.
  149. Next, the Pragmatic Guide series idea came from Travis Swicegood, author of
  150. the excellent Pragmatic Version Control Using Git [Swi08]. I really liked the
  151. idea of a “get up to speed fast” Subversion book, so thank you, Travis. The
  152. folks at Pragmatic Bookshelf were super-awesome to work with as usual,
  153. although the operation is a lot bigger than when I did the original Subversion
  154. book five years ago. To Jackie Carter, my editor, thanks for keeping me on
  155. track and (nicely) pushing me to finish. I always felt that you had lots of time
  156. for me, and thebook is much better as a result. To Dave and Andy, thanks
  157. for building a nontraditional publishing company that creates great books and
  158. gives authors a good deal.
  159. A small army of people helped with the technical content in the book. To
  160. my reviewers, Rob Baillie, Ian Bourke, Kevin Gisi, Leesa Hicks, Michael
  161. Raczynski, Mike Roberts, and Graham Nash, thank you very much indeed.
  162. Your feedback has made this book better, and your encouraging words helped
  163. me finish the writing. To my fellow ThoughtWorks authors, especially Martin
  164. Fowler and Jonathan McCracken, thank you for being a sounding board while
  165. I worked on the book.
  166. Finally, I’d like to thank you, the reader, for choosing this book. I hope you
  167. enjoy reading it—I certainly enjoyed writing it.
  168. Introduction
  169. Subversion is a wildly popular open source version control system, avail-
  170. able for free over the Internet. Subversion is widely considered the de facto
  171. standard 1 for version control tools, even though such a thing is difficult to
  172. measure, and as a developer, you are likely to encounter Subversion as part of
  173. your work.
  174. Subversion is a mature, fully featured system that is commonly used by both
  175. commercial and open source development teams. You can buy commercial
  176. support and consulting services to help you install, configure, and use Sub-
  177. version. If you don’t want the hassle of running a Subversion server, you can
  178. get a third party to do it for you, at a low cost or even for free.
  179. Subversion is a centralized version control system, meaning that it uses a cen-
  180. tral server to store files and enable team collaboration. Clients can work dis-
  181. connected from the network—on an airplane, for example—and need a net-
  182. work connection only if they actually want to commit changes to the server.
  183. This traditional centralized model assumes that development teams have rea-
  184. sonable network connectivity to the server. In contrast, some newer decen-
  185. tralized version control systems use a model where each user acts kind of like
  186. a server. Users can swap changes between each other without needing a cen-
  187. tral server. Most organizations will be fine with the centralized model used
  188. by Subversion, but it’s worth being aware that other collaboration styles are
  189. possible.
  190. Subversion is popular because it has all the features that programmers need
  191. and very few extra bells and whistles. It just does version control, and it does
  192. it well.
  193. Subversioncantrackversioninformation fordirectoriesandmetadata,aswell
  194. as files. Treating directories as first-class objects means that Subversion can
  195. track history across directory moves and renames, unlike some older version
  196. 1. Determining the exact market share for Subversion is difficult, but several online polls
  197. rate Subversion more popular than any other version control tool. Martin Fowler suggests that
  198. within the Agile/XP community, only Subversion, Git, and Mercurial would be recommended:
  199. http://martinfowler.com/bliki/VersionControlTools.html.
  200. W HO I S T HIS B OOK F OR ? 10
  201. control systems. Every file and directory can have arbitrary metadata associ-
  202. ated with it using Subversion properties.
  203. Committing a change is atomic, similar to committing to a database. Either
  204. the whole commit succeeds or is rolled back; other users never see a half-
  205. finished commit. As part of the atomic commit process, Subversion groups
  206. all your changes into a revision (sometimes called a changeset) and assigns
  207. a revision number to the change, unlike older systems that apply a revision
  208. number to each individual file. By grouping changes to multiple files into
  209. a single logical unit, developers are able to better organize and track their
  210. changes.
  211. Subversion has cheap branches and tags that can be created almost instantly.
  212. Branches are used to distinguish different lines of development, most com-
  213. monly to separate code that is in production vs. code that is being actively
  214. developed. Tags are used to “mark” the state of the code at a particular point
  215. in time so that state can be re-created later. Subversion also supports merge
  216. tracking, which helps automatically merge changes between branches.
  217. Subversion is a truly multiplatform tool. You can run Subversion on Win-
  218. dows, Linux, OS X, and many other flavors of Unix. Each of these operating
  219. systems is considered a first-class platform by the Subversion developers, and
  220. you can run a production-strength server on any of them. A Subversion client
  221. can talk to a Subversion server even if the client and server are running on
  222. different operating systems. This is good news for anyone trying to fit Sub-
  223. version into their existing infrastructure. For those evaluating Subversion, the
  224. wide choice of operating system makes things much easier since you can run
  225. a server on pretty much any spare machine.
  226. Who Is This Book For?
  227. Most developers have at least some experience with a source control tool and
  228. are expected to fluidly switch between tools depending on where they are
  229. working. This book was written to bridge the gap between knowing some-
  230. thing about version control and knowing about Subversion specifically.
  231. Pragmatic Guide to Subversion will quickly get you up to speed on Subver-
  232. sion. We don’t spend a lot of time covering the philosophy of version control
  233. or trying to persuade you it’s a good idea to store your files somewhere safe.
  234. If you are interested in a broader discussion of version control concepts and
  235. some of the reasoning behind what we do, check out Pragmatic Version Con-
  236. trol Using Subversion [Mas06], 2 my previous book.
  237. 2. http://pragprog.com/titles/svn2/
  238. Report erratum
  239. H OW TO R EAD T HIS B OOK 11
  240. How to Read This Book
  241. This book is organized into parts that each cover a portion of the Subversion
  242. software management “life cycle.” Each part of the book contains some intro-
  243. ductory pages discussing how Subversion handles particular concepts. You
  244. should read the introductions to get a feel for the overall concepts and how
  245. everything ties together, but after that, feel free to jump straight to a particular
  246. task. If you are new to source control, it’s perfectly OK to read the book in
  247. order—everything will make sense and give you a good grounding in Subver-
  248. sion concepts.
  249. The book is laid out as double-page spreads for each task, with a discussion
  250. of the task on the left page and the actual steps to achieve the task on the right
  251. page. This works naturally for the printed book, but many readers will be
  252. reading a digital version. If you have the screen space for it, try setting your
  253. reader to show two pages side by side to enhance your reading experience.
  254. The parts of the book are organized as follows:
  255. • Part I: Getting Started covers core Subversion concepts such as the
  256. client, server, repository, and working copies. You will learn how to
  257. choose and install a Subversion client, how to set up a local repository,
  258. and how to import your existing code into Subversion.
  259. • Part II: Working with Subversion discusses daily workflow when using
  260. Subversion. You’ll learn how to check out from a repository, examine
  261. or undo your changes, and commit to the repository.
  262. • Part III: Working with a Team covers how to use Subversion in a team
  263. setting, how to stay in sync with your team, and how to resolve con-
  264. flicts.
  265. • Part IV: Using the History shows you Subversion’s powerful history
  266. tools so you can understand changes made to your source tree and who
  267. made them. In some cases, you might want to undo changes that have
  268. been committed to the repository—this part shows you how.
  269. • Part V: Branching, Merging, and Tagging tackles one of the more com-
  270. plex topics in source control. Using branches and tags, you can reliably
  271. release software to production and support it going forward.
  272. • Part VI: File Locking covers Subversion’s optional file locking fea-
  273. tures, which is useful if your repository contains unmergeable files
  274. such as spreadsheets or graphics.
  275. • Part VII: Setting Up a Server shows you how to install a Subversion
  276. server on Linux or Windows, including securing and backing up the
  277. server. If you’d like to use third-party hosting instead of running your
  278. own server, we discuss how to do this too.
  279. Report erratum
  280. S UBVERSION V ERSIONS 12
  281. • Part VIII: Advanced Topics discusses Subversion features that you
  282. might not need every day but that will be important maybe once or
  283. twice when you set up a project. Included here is information on how
  284. to store multiple projects in a single Subversion repository and how to
  285. store third-party code in your own repository.
  286. Subversion Versions
  287. Subversion is developed by a team of programmers collaborating over the
  288. Internet. It’s open source, and the Subversion team regularly releases new
  289. versions. Major versions are given numbers such as 1.6 or 1.7, with patch and
  290. bug fix releases getting numbers like 1.6.3, 1.7.1, and so on.
  291. In general, you should always use the newest release of Subversion, because
  292. new features, bug fixes, and performance improvements are continually being
  293. madebytheSubversiondevelopers.Newmajorversionsarealwaysbackward
  294. compatible with older servers and working copies—so client version 1.5.x
  295. will work with server version 1.6.x—but the opposite is not always true.
  296. Always upgrade all the clients on a computer at the same time. For example,
  297. if you have both the command-line client and a graphical client and you want
  298. to upgrade to Subversion 1.7, upgrade both the command-line and graphi-
  299. cal clients at the same time. If you don’t do this, one or other of the clients
  300. might complain about the working copy being in a new format that they don’t
  301. understand.
  302. In general, it’s always safe to upgrade a Subversion client, but a Subversion
  303. server requires more attention. You should always ensure you have a reposi-
  304. tory backup before doing a server upgrade and that you have tested that the
  305. backup restores correctly.
  306. Online Resources
  307. All Pragmatic books have an online component. You can find the home page
  308. for this book here:
  309. http://pragprog.com/titles/pg_svn/
  310. From here you can download code and the example mBench project used
  311. throughout the book, view the book’s errata, and chat with the author and
  312. other readers in a dedicated online forum.
  313. Subversion is a mature open source system, and there is a lot of community
  314. support for it. A web search will usually turn up loads of extra information
  315. about a topic, most of which is excellent and high quality. Don’t be afraid to
  316. look beyond the tasks in this book and explore for yourself.
  317. Report erratum
  318. Part I
  319. Getting Started
  320. G ETTING S TARTED 14
  321. To use Subversion, you need a server and a client. The server stores
  322. files inside a repository and makes the repository available over a
  323. network, either a LAN or the Internet. The client talks to the server
  324. and creates a working copy of the files from the repository. Users
  325. make changes to their files and then commit the changes to the
  326. repository where other members of their team can see them.
  327. internet
  328. repository
  329. Alice
  330. Bill
  331. Subversion can secure network connections using SSL, the same
  332. technology used to protect credit card information online, or SSH,
  333. the secure shell used to administer Unix machines across the Inter-
  334. net. Subversion can store user credentials in a simple password file
  335. or integrate with an existing store such as Active Directory or LDAP.
  336. Most users won’t need to worry about administering a Subversion
  337. server, since you can easily use a third-party hosting provider over
  338. the Internet or get your company’s server operations team to provi-
  339. sion a Subversion server. If you do need to run a server yourself, it’s
  340. pretty easy; see Task 33, Installing Subversion Server, on page 104 for
  341. more details.
  342. Subversion was designed to be easily extended, so a wide range
  343. of different clients are available. The basic command-line client is
  344. available for most operating systems and will perform all the differ-
  345. ent Subversion functions admirably—you might never need more
  346. than the command-line client. For some operations, it’s nice to have
  347. a GUI to make things easier, so a wide range of graphical Subver-
  348. sion clients are also available. Doing check-ins, merges, and history
  349. browsing can particularly benefit from a GUI.
  350. Report erratum
  351. G ETTING S TARTED 15
  352. For tasks in this book, we are using the command-line client on
  353. Ubuntu Linux. The client is very similar on Windowsand Mac, and
  354. all the command-line examples will work on all three operating sys-
  355. tems. We’ve chosen the TortoiseSVN graphical client for Windows
  356. and the Cornerstone graphical client for Mac OS X. All of the tasks in
  357. the book include instructions on how to do the job using the graph-
  358. ical clients as well as the command-line client.
  359. If you are using an integrated development environment (IDE) such
  360. as IntelliJ, Eclipse, or Xcode, you’ll find that it supports Subversion
  361. out of the box. You can update working copies, fix conflicts, commit
  362. changes, and view history without leaving the IDE. Other IDEs such
  363. as Visual Studio require a plug-in to work with Subversion, but once
  364. you’ve installed the plug-in, you can work with Subversion seam-
  365. lessly. If you’re using an IDE, it’s definitely worth checking out its sup-
  366. port for Subversion. Good IDE integration for your source control tool
  367. can be a significant productivity enhancement.
  368. Covered in this part:
  369. • First you’ll need to install a Subversion client. If you’re on Linux
  370. or prefer a command-line client, refer to Task 1, Installing a
  371. Command-Line Client, on the next page. Windows users should
  372. refer to Task 2, Installing a Graphical Client on Windows, on
  373. page 18. Mac users should read Task 3, Installing a Graphical
  374. Client on Mac OS X, on page 20.
  375. • If you don’t have a Subversion repository already set up, Task
  376. 4, Creating a Local Repository, on page 22 will show you how
  377. to set up a local file repository for learning Subversion.
  378. • Once you have a Subversion repository in place, refer to Task
  379. 5, Creating an Empty Project, on page 24 to start off with a
  380. blank project in your repository.
  381. • If you already have source code that you’d like to store in
  382. Subversion, Task 6, Creating a Project from an Existing Source
  383. Tree, on page 26 shows you how to import your existing source
  384. code into Subversion.
  385. Let’s jump right into installing Subversion.
  386. Report erratum
  387. I NSTALLING A C OMMAND -L INE C LIENT 16
  388. 1 Installing a Command-Line Client
  389. We recommend installing the command-line client even if you intend to do
  390. most of your work with a graphical client. It’s useful to have the basic
  391. functionality available as a fallback, in case you can’t get the GUI to do what
  392. you want.
  393. Installing the client on Windows is fairly straightforward; just double-click
  394. the installer from CollabNet, and it will set everything up for you. You can
  395. get the Windows command-line client from other distributors than
  396. CollabNet, but the installers generally aren’t as friendly.
  397. Installing Subversion on the Mac is somewhat complicated because you have
  398. several options. Depending on which release of OS X you’re using, you may
  399. already have the command-line Subversion client. Snow Leopard comes
  400. with Subversion 1.6, Leopard comes with Subversion 1.4, and older releases
  401. of OS X don’t come with Subversion at all. If you’re using anything older
  402. than Snow Leopard, you should upgrade to the latest release of Subversion.
  403. If you have MacPorts or Fink installed on your system, then you can use their
  404. package managers to install Subversion. If you haven’t heard of these tools,
  405. don’t worry; they’re just a convenient way to get Unix tools on the Mac.
  406. Subversion is available as part of the official Ubuntu distribution, so it might
  407. already be installed on your system. If not, just use the apt package manager
  408. to install it. Graphical Subversion clients are available for Ubuntu such as
  409. Subcommander or RapidSVN, but for the purposes of this book, we’ll stick
  410. to the command-line client.
  411. If you’re more comfortable using the Ubuntu desktop than the command
  412. line, you can also install Subversion using Synaptic, Ubuntu’s graphical
  413. package manager.
  414. Once you’ve installed the Subversion command-line client, you should be
  415. able to open a command prompt and run Subversion commands. To see what
  416. release of Subversion is installed, run svn --version . You should see
  417. something like this:
  418. prompt> svn --version
  419. svn, version 1.6.12 (r955767)
  420. compiled Jun 23 2010, 10:32:19
  421. Make sure you have Subversion 1.6 or newer. The working copy format
  422. changed in Subversion 1.5 and again in 1.6, and older clients cannot use the
  423. new formats.
  424. Report erratum
  425. I NSTALLING A C OMMAND -L INE C LIENT 17
  426. Install the Windows command-line client from CollabNet.
  427. Visit CollabNet, 3 and download the command-line client. Once it’s
  428. downloaded, double-click the file to start the installer. If you’re not
  429. interested in running a Subversion server, uncheck the svnserve and
  430. Apache options during the install.
  431. Install the Mac command-line client from CollabNet.
  432. Visit CollabNet, 4 and download its universal binaries for OS X. After you’ve
  433. run the installer, add the following line to ~/.profile :
  434. export PATH=/opt/subversion/bin:$PATH
  435. If you’re using MacPorts, you can use it to install Subversion:
  436. prompt> sudo port install subversion
  437. If you’re using Fink, you can use it to install Subversion:
  438. prompt> sudo fink install svn-client
  439. Install the Ubuntu client.
  440. prompt> sudo apt-get update
  441. prompt> sudo apt-get install subversion
  442. Alternatively, click System > Administration > Synaptic Package Manager
  443. to start Synaptic. Type subversion into the search box to show just
  444. Subversion-related packages. Click the box next to the subversion package,
  445. and then select “Mark for installation.” Choose to mark any other packages
  446. that are required. Click the Apply button to install the Subversion packages.
  447. Related Tasks
  448. • Task 2, Installing a Graphical Client on Windows, on the next page
  449. • Task 3, Installing a Graphical Client on Mac OS X, on page 20
  450. • Task 33, Installing Subversion Server, on page 104
  451. 3. http://www.collab.net/downloads/subversion/svn1.5.html
  452. 4. http://www.open.collab.net/downloads/community/
  453. Report erratum
  454. I NSTALLING A G RAPHICAL C LIENT ON W INDOWS 18
  455. 2 Installing a Graphical Client on
  456. Windows
  457. TortoiseSVN is an excellent Subversion client for Windows that integrates
  458. directly into Windows Explorer. Once Tortoise is installed, you can
  459. right-click anywhere in a Windows Explorer window and get
  460. context-sensitive Subversion options. If you right-click in a directory that
  461. isn’t a Subversion working copy, Tortoise will offer to let you check it out
  462. from a repository. If you right-click a directory that is a working copy,
  463. Tortoise will offer to let you update or commit. If you right-click a file inside
  464. a working copy, Tortoise will offer to show history for the file, and so on.
  465. Throughout the rest of the book, we’ll use a shorthand to denote choosing
  466. Tortoise menu options, rather than showing screenshots all the time. To
  467. indicate that you should right-click to get the context menu and then click
  468. TortoiseSVN and then Show Log, we will use the abbreviation
  469. TortoiseSVN > Show Log.
  470. Tortoise shows its context-sensitive options both immediately on the context
  471. menu and within the TortoiseSVN flyout menu. Tortoise lets you move
  472. frequently used operations from the flyout to the context menu so you can
  473. save yourself a click or two. To do this, choose TortoiseSVN > Settings, and
  474. then select Context Menu. Select the box next to each operation that you’d
  475. like available directly on the context menu.
  476. Tortoise needs a Subversion repository in order to do anything useful. If you
  477. have a repository already set up, you just need to know the repository URL,
  478. and you can get going. If you are trying Subversion for yourself and need to
  479. set up a local repository for testing, see Task 4, Creating a Local Repository,
  480. on page 22.
  481. Report erratum
  482. I NSTALLING A G RAPHICAL C LIENT ON W INDOWS 19
  483. Install the Tortoise graphical client.
  484. Visit tortoisesvn.net, 5 and download TortoiseSVN. Tortoise is integrated
  485. with Windows Explorer, so you should reboot your system once the installer
  486. finishes.
  487. Once it’s installed, you can right-click inside any Windows Explorer window
  488. to get a context-sensitive TortoiseSVN menu.
  489. Related Tasks
  490. • Task 1, Installing a Command-Line Client, on page 16
  491. • Task 33, Installing Subversion Server, on page 104
  492. 5. http://tortoisesvn.net/downloads
  493. Report erratum
  494. I NSTALLING A G RAPHICAL C LIENT ON M AC OS X 20
  495. 3 Installing a Graphical Client on Mac
  496. OS X
  497. Cornerstone is one of several Subversion clients available for the Mac. It has
  498. a nice, clean interface and a similar feel to other OS X applications.
  499. Cornerstone is commercial software, so you need to buy a license to use it
  500. longer than its free 14-day trial period.
  501. The Cornerstone window has several sections. Along the top is a button bar
  502. with icons for the most common Subversion operations. To the left is a
  503. column containing the working copy source list and the repository source
  504. list. In the center is the main working window, which can show a working
  505. copy browser, a commit view, and a range of other information depending on
  506. what you currently have selected. To the right is the inspector, which shows
  507. more detail about the currently selected item.
  508. If you already know the URL for the repository you want to access, click the
  509. Add Repository... button or click the small + button at the top of the
  510. repository source list. Most repositories will be either HTTP or SVN Server;
  511. ask your administrator if you’re not sure. When adding a repository, it’s best
  512. to omit the trunk directory from the end of the URL so that you can see the
  513. top-level directories and work with them.
  514. If you don’t know the URL for your repository, you should ask the person in
  515. charge of your project. If that person is you, use the instructions in Task 5,
  516. Creating an Empty Project, on page 24 to set up your project. If you’d like to
  517. set up a local repository to get going quickly, see Task 4, Creating a Local
  518. Repository, on page 22.
  519. Adding a repository to the repository source list doesn’t actually copy any
  520. files to your computer; we’ll do that in Task 7, Checking Out a Working
  521. Copy, on page 32. The rest of the Cornerstone examples in this book assume
  522. you have added the Subversion repository for your project.
  523. Report erratum
  524. I NSTALLING A G RAPHICAL C LIENT ON M AC OS X 21
  525. Install the Cornerstone graphical client.
  526. Visit the Cornerstone website, 6 and download Cornerstone. Double-click the
  527. disk image, and drag the Cornerstone application into your Applications
  528. folder.
  529. When running Cornerstone, you’ll be greeted with the main window, as
  530. shown here:
  531. Related Tasks
  532. • Task 1, Installing a Command-Line Client, on page 16
  533. • Task 33, Installing Subversion Server, on page 104
  534. 6. http://www.zennaware.com/cornerstone/
  535. Report erratum
  536. C REATING A L OCAL R EPOSITORY 22
  537. 4 Creating a Local Repository
  538. Most people using Subversion don’t need to worry about creating or
  539. maintaining a repository since it’s an administrative task usually performed
  540. by a server administrator or Unix guru. If you don’t have access to one of
  541. these people or if you’d like to experiment with your own repository, you
  542. can use what’s called a local repository.
  543. A local repository needs to live on your hard drive somewhere. For
  544. Windows, this might be a dedicated directory on the C: drive; for Unix and
  545. Mac OS X, it’s probably somewhere in your home directory. Once you have
  546. created an empty directory, you need to tell Subversion to initialize a
  547. repository in that directory. Command-line users should use the svnadmin
  548. command to achieve this. Tortoise users should right-click the directory to
  549. initialize a repository. Cornerstone users should use the Cornerstone GUI to
  550. create the repository.
  551. Once you have initialized the repository, you can start using it, but you’ll
  552. need to tell Subversion where to find the repository. This is where the
  553. repository base URL is needed. The base URL for a local repository always
  554. starts with file:// and ends with the path within the file system to get to your
  555. repository directory.
  556. You can turn a local repository into a networked repository by running a
  557. Subversion server and pointing it at the repository directory. You can find
  558. more details in Task 33, Installing Subversion Server, on page 104.
  559. Report erratum
  560. C REATING A L OCAL R EPOSITORY 23
  561. Create a base directory for the repository, and then initialize it.
  562. prompt> mkdir -p ~/svn/repos
  563. prompt> svnadmin create ~/svn/repos
  564. The base URL for your local repository is file:///home/myuser/svn/repos .
  565. Create a local repository using Tortoise.
  566. Using Windows Explorer, create an empty directory for your repository.
  567. Something such as C:\Subversion\Repos will work.
  568. Right-click inside the new directory, and choose TortoiseSVN > Create
  569. repository here.
  570. The base URL for your local repository is file:///C:/Subversion/Repos .
  571. Create a local repository using Cornerstone.
  572. Choose File > Add Repository..., or click the plus icon in the repository
  573. source list.
  574. Select the File Repository button at the top, and click Create a New
  575. Repository. Click the Where drop-down, and choose the folder in which you
  576. want to create your repository. Usually a dedicated svn directory within your
  577. home directory will work.
  578. Enter a repository name in the “Create as” box. This is the actual directory
  579. where your new repository will be stored.
  580. Click the Compatibility drop-down, and choose 1.6. Finally, click the Add
  581. button to create the local repository.
  582. The base URL for your local repository is file:///Users/myuser/svn/repos .
  583. Related Tasks
  584. • Task 34, Creating a Repository, on page 106
  585. • Task 5, Creating an Empty Project, on the following page
  586. • Task 36, Using Third-Party Subversion Hosting, on page 110
  587. Report erratum
  588. C REATING AN E MPTY P ROJECT 24
  589. 5 Creating an Empty Project
  590. Most Subversion users won’t often need to create a project—that’s usually
  591. done by a systems administrator or a third-party hosting company. If the
  592. project is already set up and you know the URL, you can jump to Task 7,
  593. Checking Out a Working Copy, on page 32.
  594. Subversion uses directories as its basic unit of organization, dividing the
  595. repository into different projects. By convention, all Subversion projects
  596. have trunk , tags , and branches directories directly within the project’s root
  597. directory. If you had two projects, Kithara and Sesame, you would end up
  598. with the following directory structure:
  599. • /Kithara/trunk
  600. • /Kithara/tags
  601. • /Kithara/branches
  602. • /Sesame/trunk
  603. • /Sesame/tags
  604. • /Sesame/branches
  605. The trunk directory is where all the main development action happens and is
  606. usually the directory you will check out if you want to work on the project.
  607. Remember to specify the trunk when checking out; otherwise, you’ll get the
  608. trunk, all the tags, and all the branches! This could be quite a lot of stuff and
  609. usually isn’t what you want.
  610. The tags directory is used to store named snapshots of the project. For
  611. example, when creating a production release, the team will tag the code that
  612. goes into the release. In the future this can help you re-create the code that
  613. was shipped so that the team can find bugs and fix problems.
  614. The branches directory is used when you want to pursue different lines of
  615. development. A good example would be creating a branch for a production
  616. release. Development on the branch can focus on producing a stable release,
  617. while the trunk can continue to be used to develop new features.
  618. Although you can store multiple projects within a single Subversion
  619. repository, some people use a different repository for each project. This
  620. allows some increased flexibility, for example having different sets of users
  621. or a different backup schedule between projects, but at the cost of extra
  622. administration overhead because each repository needs to be configured and
  623. backed up individually. If you are using a repository-per-project style for
  624. managing your Subversion projects, the trunk , tags , and branches
  625. directories will be at the root of each project’s repository.
  626. Report erratum
  627. C REATING AN E MPTY P ROJECT 25
  628. Create a base directory for the project.
  629. If you are sharing a single repository between multiple projects, create a
  630. directory within the repository for your new project.
  631. prompt> svn mkdir -m "Make base directory" \
  632. http://svn.mycompany.com/myproject
  633. Create a repository for the project.
  634. If you are using a separate repository for each project, follow the steps in
  635. Task 34, Creating a Repository, on page 106 to create a repository for your
  636. project.
  637. Create trunk , tags , and branches directories.
  638. prompt> svn mkdir -m "Initial setup" \
  639. http://svn.mycompany.com/myproject/trunk
  640. prompt> svn mkdir -m "Initial setup" \
  641. http://svn.mycompany.com/myproject/tags
  642. prompt> svn mkdir -m "Initial setup" \
  643. http://svn.mycompany.com/myproject/branches
  644. Use Tortoise to create directories.
  645. Right-click inside any Explorer window, and choose TortoiseSVN >
  646. Repo-browser. Enter the URL for your repository, for example http://svn.
  647. mycompany.com/. Tortoise will show you a repository browser where you
  648. can manipulate your repository. Right-click, and choose “Create folder” as
  649. necessary to create all the directories you need for your project.
  650. Use Cornerstone to create a project.
  651. Select your repository from the repository source list. Cornerstone will show
  652. its repository browser in the main window. Ctrl+click the main window, and
  653. choose “New folder in MyRepo....” Enter a name for the project, and select
  654. the box to create top-level directories for the project. Enter a log message
  655. describing your change, and then click Continue to create your project.
  656. Related Tasks
  657. • Task 34, Creating a Repository, on page 106
  658. • Task 36, Using Third-Party Subversion Hosting, on page 110
  659. Report erratum
  660. C REATING A P ROJECT FROM AN E XISTING S OURCE T REE 26
  661. 6 Creating a Project from an Existing
  662. Source Tree
  663. Often when creating a project in version control, you will already have some
  664. files that are the starting point for the project. This is especially true if you
  665. are starting to use Subversion on a project that didn’t previously have
  666. version control or you are moving from another version control system.
  667. Even if you have done only an afternoon’s work on a new project, you are
  668. likely to have a local directory that represents a good starting point for the
  669. project. Subversion’s import functionality will create a project inside your
  670. repository using your local directory and its contents. Once imported, a copy
  671. of your files will be safely stored on the Subversion server.
  672. Before importing anything, you should make sure you have cleaned up any
  673. temporary files or other garbage that might be lying around. Most build tools
  674. and IDEs have an option to “clean” your project—it’s worth doing this and
  675. generally having a look around to make sure you only import the stuff you
  676. really want. If you accidentally import a file that you don’t want, you can
  677. delete it from the repository, but because Subversion stores the history of all
  678. the files it has ever known about, that file will still be in the repository taking
  679. up space. This isn’t a big deal for small files, but if you have large binaries
  680. such as debugging symbols, you really should clean them up before doing an
  681. import.
  682. Doing an svn import or using one of the GUI tools grabs an entire directory
  683. full of files and checks it into your Subversion repository in one fell swoop.
  684. As long as the repository is valid, Subversion will create any directories it
  685. needs along the way. If you haven’t yet created a trunk folder, for example,
  686. Subversion will create it for you.
  687. Report erratum
  688. C REATING A P ROJECT FROM AN E XISTING S OURCE T REE 27
  689. Clean up your existing source tree.
  690. Delete any temporary files or build artifacts from your source directory. Your
  691. IDE might have a Clean Up option, or if you’re using a command-line build
  692. tool, you should run make clean . 7
  693. Check for hidden files or directories, such as .cvs administrative directories
  694. from the CVS source control system. Remove anything that you don’t want
  695. imported into the new Subversion project.
  696. Import the whole tree to your project directory.
  697. prompt> cd work/myproject-to-import
  698. prompt> svn import -m "Initial import" \
  699. http://svn.mycompany.com/myproject/trunk
  700. Import the whole tree using Tortoise.
  701. Using Windows Explorer, right-click the directory you want to import, and
  702. choose TortoiseSVN > Import.... Enter the repository URL for your project
  703. (make sure to include the trunk directory at the end of the URL), and enter a
  704. message describing what you’re importing. Click OK to complete the import.
  705. Import the whole tree using Cornerstone.
  706. Select your repository from the repository source list. Ctrl+click in the base
  707. of the repository browser, and choose Import....
  708. In the file dialog box, browse to the directory you want to import, select it,
  709. and click the Open button. In the Import As text box, enter myproject/trunk
  710. as the directory to import to. Click Import, enter a log message, and
  711. Cornerstone will import your files.
  712. Use the repository browser to navigate to your newly imported trunk
  713. directory. Create tags and branches directories next to the trunk.
  714. Related Tasks
  715. • Task 5, Creating an Empty Project, on page 24
  716. 7. Substitute the build tool of your choice, such as ant , nant , maven , msbuild , or rake .
  717. Report erratum
  718. Part II
  719. Working with Subversion
  720. W ORKING WITH S UBVERSION 29
  721. Now that we have Subversion installed and a repository set up, we
  722. can begin doing useful work. While Subversion is designed to enable
  723. team collaboration, you can also use it individually. If you are pro-
  724. gramming or authoring on your own, the diff, history, and commit
  725. tools can help you organize your work. You can also use Subversion
  726. as a kind of safe “backup” copy for your files.
  727. In this section, you’ll see how to get a working copy of the files from
  728. Subversion. After you make changes to your files, you commit the
  729. changes to the repository. We’ll also cover renaming and moving
  730. files and directories.
  731. In this section and for the rest of the book, we’ll be using an exam-
  732. ple project called mBench. mBench is a simple benchmarking tool
  733. for MongoDB, one of a new generation of nonrelational databases
  734. (sometimes known as “NoSQL” databases). Mongo is a document-
  735. oriented database with very different performance and reliability
  736. characteristics than a traditional SQL database. Before using
  737. Mongo in production, we’d like to make sure it meets our needs
  738. for speed and reliability. mBench will contain Java code to exercise
  739. Mongo, documentation detailing things we find out about how to
  740. best use Mongo, and other artifacts such as performance testing
  741. results.
  742. The complete source code for mBench is available as part of the
  743. code download for this book. The code, errata, and forums are
  744. available from the Pragmatic Bookshelf at http://pragprog.com/titles/pg_
  745. svn. For all the tasks involving mBench, we assume that it’s available
  746. from a repository at http://svn.mycompany.com/mbench. This URL isn’t real,
  747. so you should substitute your own repository URL when working with
  748. the examples.
  749. Covered in this part:
  750. • To edit files stored in Subversion, you need to first get a copy
  751. of the files on your machine. Task 7, Checking Out a Working
  752. Copy, on page 32 shows you how.
  753. • Task 8, Seeing What You’ve Changed, on page 34 covers how
  754. Subversion shows the edits you have made to files. Task 9, See-
  755. ing What You’ve Changed Using Tortoise, on page 36 and
  756. Task 10, Seeing What You’ve Changed Using Cornerstone, on
  757. page 38 show you how to examine changes using GUI tools.
  758. Report erratum
  759. W ORKING WITH S UBVERSION 30
  760. • Once you have made your changes, you need to commit
  761. them to the repository. I describe the commit process in Task
  762. 11, Committing Changes, on page 40.
  763. • Task 12, Adding Files and Directories, on page 42 covers how
  764. to add new items to your repository, while Task 13, Removing
  765. Files and Directories, on page 44 shows how to remove items.
  766. • Renaming and moving items is covered in Task 14, Moving and
  767. Renaming Files and Directories, on page 46.
  768. • If you make a local change that you’d like to undo, follow the
  769. instructions in Task 15, Reverting Working Copy Changes, on
  770. page 48.
  771. • Subversion allows you to ignore temporary files; Task 16, Ignor-
  772. ing Files, on page 50 shows you how.
  773. Let’s get started by checking out a fresh working copy.
  774. Report erratum
  775. W ORKING WITH S UBVERSION 31
  776. Report erratum
  777. C HECKING O UT A W ORKING C OPY 32
  778. 7 Checking Out a Working Copy
  779. You need to check out the files from your repository before you can access
  780. them on your computer. The files will be stored in a local directory called a
  781. working copy. Your Subversion client will talk to the server and copy the
  782. latest files onto your computer ready to edit. You will be asked for a
  783. username and passwordif your repository is secured.
  784. Subversion projects are usually stored in a trunk directory on the server; this
  785. will be the case if youhave followed the instructions in this book for
  786. creating projects. You need to specify this trunk directory as part of the
  787. repository URL from which you are checking out. If you forget, you’ll end
  788. up checking out everything in the repository—branches, tags, everything—
  789. and this could end up being much more than you really wanted. After
  790. specifying the project’s trunk directory, we tell Subversion that we want to
  791. check out into a local directory called mbench . If you don’t include this
  792. information, Subversion will check out into a folder called trunk , which
  793. probably isn’t what you want and might be quite confusing if you’re working
  794. on more than one project!
  795. After Subversion has copied files from the repository to your computer,
  796. they’ll be saved in a directory known as a working copy. Inside a working
  797. copy, Subversion remembers where all the files came from, knows what
  798. revision they were when they came from the server, and can detect any
  799. changes you make to the files. Subversion uses hidden .svn directories to
  800. track all its bookkeeping information. Don’t alter, delete, or otherwise mess
  801. with these directories because you could corrupt your working copy.
  802. You need to check out from Subversion only the first time you want to work
  803. with a particular project. Once you have a working copy, you can always
  804. update it to get the latest files. We describe the update process in more detail
  805. in Task 17, Updating to the Latest Revision, on page 56.
  806. After you check out a working copy using Cornerstone, it will automatically
  807. add the working copy as an entry in your working copy sources list. You’ll
  808. need to use this entry when manipulating your working copy for the rest of
  809. the tasks in this book.
  810. Report erratum
  811. C HECKING O UT A W ORKING C OPY 33
  812. Check out into a local working copy.
  813. prompt> cd ~/work
  814. prompt> svn checkout http://svn.mycompany.com/mbench/trunk mbench
  815. Check out using Tortoise.
  816. Using Windows Explorer, navigate to your C:\Work directory. Right-click
  817. inside the directory, and choose SVN Checkout.... Then fill in the dialog box
  818. as follows:
  819. Check out using Cornerstone.
  820. Select your repository in the repository source list, and then use the
  821. repository browser to navigate to the trunk directory. Ctrl+click “trunk,” and
  822. choose Check Out Working Copy.... Specify where you’d like to save the
  823. new working copy, and click Check Out.
  824. Related Tasks
  825. • Task 5, Creating an Empty Project, on page 24
  826. • Task 36, Using Third-Party Subversion Hosting, on page 110
  827. Report erratum
  828. S EEING W HAT Y OU ’ VE C HANGED 34
  829. 8 Seeing What You’ve Changed
  830. Subversion keeps track of files in your working copy and will detect any
  831. changes you make. You can see which files or directories you’ve changed
  832. and even see exactly what has changed within each file. As a programmer,
  833. it’s easy to get confused about what changes you have made once you’re
  834. halfway through a feature, and Subversion can help keep you on track.
  835. The status command tells Subversion to scan all the files in your working
  836. copy to see whether they’ve changed. Subversion uses some tricks to make
  837. this process faster, but it still has to look at each file to see whether it has
  838. changed. The scan might take a while if you have lots of files in your
  839. working copy. If you know that you’ve been working in only one particular
  840. directory, you can ask Subversion to tell you the status of that directory
  841. instead of the whole project, which should speed things up.
  842. Subversion marks each file with a letter indicating its status:
  843. A Added in your working copy
  844. C Conflicted, because of an update or merge
  845. D Deleted in your working copy
  846. G Merged with changes from the repository
  847. I Ignored in your working copy
  848. M Modified in your working copy
  849. R Replaced in your working copy
  850. ? Not under version control
  851. ! Missing from your working copy (removed by non- svn command) or
  852. incomplete
  853. The diff command asks Subversion to print out a “unified diff” for each of
  854. the files you have changed. This displays the difference between the file as
  855. you checked it out and the file after you made your changes. A plus indicates
  856. that you have added some new text to the file; a minus means you’ve
  857. removed some text. If you have changed several lines, you might see a group
  858. of pluses and minuses indicating that a whole “block” of your file has
  859. changed.
  860. The command-line client isn’t great at showing diffs—not surprising when a
  861. text interface is all it has to work with. The graphical Subversion clients do a
  862. much better job displaying diffs, as we’ll see in the next tasks.
  863. Report erratum
  864. S EEING W HAT Y OU ’ VE C HANGED 35
  865. See which files have changed in your working copy.
  866. mbench> svn status
  867. M .idea/workspace.xml
  868. M src/mbench.java
  869. See how your files have changed.
  870. prompt> svn diff src/
  871. Index: src/mbench.java
  872. ==========================================================
  873. --- src/mbench.java (revision 6)
  874. +++ src/mbench.java (working copy)
  875. @@ -1,10 +1,13 @@
  876. public class mbench {
  877. - public static int main(String[] args) {
  878. + public static void main(String[] args) {
  879. if(args.length != 3) {
  880. usage();
  881. - return -1;
  882. + return;
  883. }
  884. - return 0;
  885. +
  886. + String dbHost = args[0];
  887. + long docCount = Long.parseLong(args[1]);
  888. + long runTime = Integer.parseInt(args[2]);
  889. }
  890. private static void usage() {
  891. Related Tasks
  892. • Task 21, Viewing the Log, on page 66
  893. • Task 9, Seeing What You’ve Changed Using Tortoise, on the next page
  894. • Task 10, Seeing What You’ve Changed Using Cornerstone, on page 38
  895. • Task 15, Reverting Working Copy Changes, on page 48
  896. Report erratum
  897. S EEING W HAT Y OU ’ VE C HANGED U SING T ORTOISE 36
  898. 9 Seeing What You’ve Changed Using
  899. Tortoise
  900. The Tortoise Check for modifications... command can be used anywhere
  901. inside a working copy and will show any changes you have made. Similar to
  902. the command-line client, it will do its work faster if you know you’re only
  903. interested in changes in a particular directory. Each file listed is color coded
  904. as well as having its state listed in the “text status” column.
  905. There are a number of checkboxes that control how Tortoise shows changes:
  906. Show unversioned files
  907. Shows any new files that haven’t yet been added to Subversion. It’s a
  908. good idea to keep this option selected so you don’t forget to add new
  909. files when committing to the repository.
  910. Show unmodified files
  911. Useful only on really small projects, this will show files that haven’t
  912. been modified.
  913. Show ignored files
  914. Not usually very useful, this will show any files that Subversion is
  915. currently ignoring. For more information on ignored files, see Task
  916. 16, Ignoring Files, on page 50.
  917. Show items in externals
  918. If you are using Subversion externals to pull items from another
  919. repository URL into your working copy, this option will show any
  920. changes to those files. See Task 44, Using Externals, on page 128 for
  921. more information on externals. You should usually keep this option
  922. selected.
  923. Show properties
  924. Shows changes to file properties. You can usually keep this option
  925. deselected unless you’re specifically changing file properties.
  926. You can right-click changed files to see a context-sensitive menu for each
  927. item. You can view the recent history, undo your changes, open the file, and
  928. so on. If you double-click a changed file or right-click and choose “Compare
  929. with base,” Tortoise will pop up a graphical diff window showing the
  930. changes. By default Tortoise uses TortoiseMerge to show diffs, but you can
  931. configure it to use your favorite diff tool.
  932. Report erratum
  933. S EEING W HAT Y OU ’ VE C HANGED U SING T ORTOISE 37
  934. See which files have changed in your working copy.
  935. Right-click the base directory of your working copy, and choose
  936. TortoiseSVN > Check for modifications.... Tortoise will show a window like
  937. this:
  938. See how your files have changed.
  939. In the Tortoise modified files window, double-click a file that you’ve
  940. changed. Tortoise will pop open a diff window showing the changes to that
  941. file.
  942. Related Tasks
  943. • Task 21, Viewing the Log, on page 66
  944. • Task 15, Reverting Working Copy Changes, on page 48
  945. Report erratum
  946. S EEING W HAT Y OU ’ VE C HANGED U SING C ORNERSTONE 38
  947. 10 Seeing What You’ve Changed Using
  948. Cornerstone
  949. When you select a working copy from the working copy sources list, Corner-
  950. stone automatically checks for changes and updates its file list accordingly.
  951. By default Cornerstone will show all the files in your working copy, which
  952. might be too much to look through for anything beyond a small project.
  953. Select the Changed view to show only files that have changed or are new.
  954. Modified files are shown with a little M icon to the right of their name. New
  955. files are shown with a yellow question-mark icon, added files are shown with
  956. a green A icon, and deleted files are shown with a red D icon.
  957. To see exactly what has changed in a particular file, select it and click
  958. Compare with BASE on the menu bar. This shows the changes that you have
  959. made since you last updated the file from the repository. You can also use
  960. Compare with HEAD to show the differences between your version of the
  961. file and the latest one in the repository.
  962. Report erratum
  963. S EEING W HAT Y OU ’ VE C HANGED U SING C ORNERSTONE 39
  964. See which files have changed in your working copy.
  965. Select your working copy from the working copy sources list. Cornerstone
  966. will show you the working copy browser in the main window. Click the
  967. Changed button at the top of the browser to show just files that have changes.
  968. See how your files have changed.
  969. Select a changed file, and click the Compare with BASE button at the
  970. bottom of the working copy browser. Cornerstone will use its built-in
  971. graphical diff tool to show you how the file has changed:
  972. Related Tasks
  973. • Task 21, Viewing the Log, on page 66
  974. • Task 15, Reverting Working Copy Changes, on page 48
  975. Report erratum
  976. C OMMITTING C HANGES 40
  977. 11 Committing Changes
  978. Once you are happy with the changes you have made, you should commit
  979. them back into the repository. Changes committed into the repository are
  980. available to everyone else on your project and are stored securely on your
  981. Subversion server. Committing changes is sometimes also known as
  982. checking in to the repository; these two terms mean the same thing and can
  983. be used interchangeably.
  984. Any time you commit a change into the repository, Subversion will ask for a
  985. commit message. Your changes, along with the commit message, then
  986. become a revision within the Subversion repository. You should always try
  987. to make your commit messages meaningful—they can be used later by
  988. someone else (or more often yourself!) to figure out the intent of the
  989. changes. It’s always better to describe why you made the changes instead of
  990. what the changes are. Subversion can always show the actual content of the
  991. change; it can’t help someone understand the intent of the change.
  992. If you are working on a software project, you should always update from the
  993. repository and run a build before committing changes (see Task 17,
  994. Updating to the Latest Revision, on page 56). This ensures that your changes
  995. will work with the latest code from the repository and that you haven’t
  996. broken anything. Your colleagues will thank you for being so conscientious.
  997. If you don’t want to commit all the changes from your working copy, you
  998. can tell Subversion which files or directories to commit by specifying them
  999. on the command line or choosing them in your GUI. Be extra careful when
  1000. doing this, however. If you are a programmer working on code and you
  1001. check in only half your changes, it’s likely what you checked in will not
  1002. work for someone else.
  1003. When using Tortoise, the commit window acts a little like the “Check for
  1004. modifications...” window. You can type a commit message into the top
  1005. portion and see all the changed files in the lower portion. Double-clicking
  1006. any changed file allows you to review the diff. Unchecking a file will cause it
  1007. not to be committed.
  1008. Committing using Cornerstone shows a window listing the changed files and
  1009. asking for a commit message. If you want to review exactly what you’ve
  1010. changed, double-click a modified file to show an exact graphical diff.
  1011. Unchecking a file will stop Cornerstone from committing it.
  1012. Report erratum
  1013. C OMMITTING C HANGES 41
  1014. Commit your changes back into the repository.
  1015. mbench> svn commit -m "Now parsing command-line options"
  1016. Commit using Tortoise.
  1017. Right-click inside the base of your working copy, and choose SVN
  1018. Commit.... Tortoise will show a commit window like this:
  1019. Commit using Cornerstone.
  1020. Select your project from the working copy sources list, and then click the
  1021. Commit icon on the menu bar. Cornerstone will prompt you for a commit
  1022. message and show a list of modified files; click Commit Changes to finish
  1023. your commit.
  1024. Related Tasks
  1025. • Task 8, Seeing What You’ve Changed, on page 34
  1026. • Task 17, Updating to the Latest Revision, on page 56
  1027. Report erratum
  1028. A DDING F ILES AND D IRECTORIES 42
  1029. 12 Adding Files and Directories
  1030. Subversion will notice new files and directories within your working copy,
  1031. but it won’t automatically add them to the repository. Adding items to the
  1032. repository is a two-step process; first you tell Subversion you want to add
  1033. the items to your working copy, and then you commit your changes to
  1034. actually upload the items to the repository.
  1035. This two-step process is important. When you create a new file, it won’t be
  1036. very useful to anyone else until you add content to the file, but you also need
  1037. to remember to add the file to Subversion. If you wait until you finish your
  1038. programming task, you might forget to add the file. With Subversion, you
  1039. can go ahead and add the file to your working copy right away; this won’t
  1040. change anything on the Subversion server, and no one else can see the file
  1041. yet, but when you finish your work and commit your changes, the new file
  1042. will be uploaded to the repository. This is sometimes called scheduling files
  1043. for addition to the repository.
  1044. The command-line client will add the files or directories you specify. When
  1045. adding a directory, the command-line client will recursively add any files
  1046. and directories within the directory you’re adding.
  1047. When using Tortoise to add files, if you choose to add a directory, Tortoise
  1048. will show you a complete list of the contents of the directory. If there are
  1049. files you don’t want to add, just uncheck them before clicking OK.
  1050. If you’re using Cornerstone to add a directory, clicking the Add button will
  1051. add the directory but not its contents. If you want to add a directory and its
  1052. contents, click and hold the Add button, and then choose Add to Working
  1053. Copy with Contents.
  1054. If you schedule files or directories for addition to the repository but haven’t
  1055. actually committed your changes, you can change your mind by reverting
  1056. the addition. For more information, see Task 15, Reverting Working Copy
  1057. Changes, on page 48.
  1058. Report erratum
  1059. A DDING F ILES AND D IRECTORIES 43
  1060. Add new files and directories from your working copy.
  1061. mbench> svn add README.txt docs/
  1062. mbench> svn commit -m "Adding docs folder for documentation"
  1063. Add files using Tortoise.
  1064. Using Windows Explorer, navigate to the file or directory you want to add.
  1065. Right-click, and choose TortoiseSVN > Add....
  1066. Commit your changes by right-clicking the base of your working copy and
  1067. choosing SVN Commit....
  1068. Add files using Cornerstone.
  1069. Select your project from the working copy sources list, and click the
  1070. Changed button. Find the new file—it should have a yellow question-mark
  1071. icon to its right—and select it. Click the Add button in the bottom toolbar.
  1072. Commit your changes by clicking Commit on the top toolbar.
  1073. Related Tasks
  1074. • Task 8, Seeing What You’ve Changed, on page 34
  1075. • Task 11, Committing Changes, on page 40
  1076. • Task 15, Reverting Working Copy Changes, on page 48
  1077. Report erratum
  1078. R EMOVING F ILES AND D IRECTORIES 44
  1079. 13 Removing Files and Directories
  1080. Similar to adding items, deleting items from the repository is a two-step
  1081. process; first you tell Subversion you want to delete the items from your
  1082. working copy, and then you commit your changes to the repository. Until
  1083. you commit the change, the delete won’t happen on the server.
  1084. As with adding items, this two-step process is important because you are
  1085. likely to want to commit your delete along with some changes to other files.
  1086. For example, if you’re using an IDE to manage your source code and want to
  1087. delete a class, the change consists of both removing the class file and
  1088. changing the IDE project file to no longer reference the file. You should
  1089. commit both these changes in one go.
  1090. When deleting a directory, Subversion will recursively delete any files and
  1091. directories within the directory you’re deleting. Subversion won’t actually
  1092. remove the directory structure, however, because Subversion still needs to
  1093. access its administrative data in the hidden .svn directories. Don’t delete
  1094. these directories yourself—once you commit your changes, Subversion will
  1095. clean up the empty directory structure. The command-line clients, Tortoise,
  1096. and Cornerstone all behave like this, so don’t worry if you see empty
  1097. directories lying around after a delete.
  1098. If you schedule files or directories for deletion from the repository but
  1099. haven’t yet committed your changes, you can change your mind and revert
  1100. the delete. Reverting a delete restores the deleted files and directories to your
  1101. working copy. For more information, see Task 15, Reverting Working Copy
  1102. Changes, on page 48.
  1103. Report erratum
  1104. R EMOVING F ILES AND D IRECTORIES 45
  1105. Delete files and directories from your working copy.
  1106. prompt> svn delete src/app/Widget.cs src/app/utils
  1107. prompt> svn commit -m "Deleted Widget class and utils package"
  1108. Delete files and directories using Tortoise.
  1109. Right-click a file or directory, and choose TortoiseSVN > Delete.
  1110. Commit your changes by right-clicking the base of your working copy and
  1111. choosing SVN Commit....
  1112. Delete files and directories using Cornerstone.
  1113. Select your project from the working copy sources list, and click the All
  1114. button in the browser. Find the file or directory you want to delete,
  1115. Cmd+click the item, and choose Delete....
  1116. Select the base of your working copy in the browser, and then click Commit
  1117. on the toolbar to commit your changes.
  1118. Related Tasks
  1119. • Task 8, Seeing What You’ve Changed, on page 34
  1120. • Task 11, Committing Changes, on page 40
  1121. • Task 15, Reverting Working Copy Changes, on page 48
  1122. Report erratum
  1123. M OVING AND R ENAMING F ILES AND D IRECTORIES 46
  1124. 14 Moving and Renaming Files and
  1125. Directories
  1126. Moving and renaming are almost the same within Subversion. 8 To rename a
  1127. file or directory, you just move it so that it has a new name but is in the same
  1128. location. To move a file or directory to a new location, specify the
  1129. destination directory. You can also move and rename at the same time by
  1130. specifying a renamed file or directory in a new location.
  1131. Moving or renaming an item is a two-phase process, similar to adding or
  1132. deleting; first you tell Subversion you want to move or rename the items, and
  1133. then you commit your changes to the repository.
  1134. If you’re looking closely, Subversion tracks a move or rename as an add of
  1135. the item with a new name or in a new location and a delete of the old item.
  1136. Internally Subversion tracks where the new item came from so you can
  1137. follow history across moves and renames.
  1138. The Subversion command line accepts move , mv , and ren as aliases for
  1139. rename .
  1140. Tortoise has an excellent interface for moving files and directories once you
  1141. discover the “right-drag” feature. Tortoise allows you to move, or move and
  1142. rename, in one operation. To right-drag a file, place your mouse pointer over
  1143. it, and click and hold the right mouse button. Still holding the right mouse
  1144. button, drag the file to its new location, and then let go of the mouse button.
  1145. Cornerstone has an intuitive interface for moving files and directories:
  1146. simply drag the item to a new position using the working copy browser. As
  1147. you drop the item in a new location, Cornerstone will offer to let you change
  1148. the name. If you want to keep the same name, just hit Enter, and Cornerstone
  1149. will move the item without renaming it.
  1150. 8. Subversion isheavily influenced by Unix, where there is no rename command—you just
  1151. move the item to a new name to rename it.
  1152. Report erratum
  1153. M OVING AND R ENAMING F ILES AND D IRECTORIES 47
  1154. Rename a file using the command-line client.
  1155. prompt> svn mv README.txt 001-README.txt
  1156. A 001-README.txt
  1157. D README.txt
  1158. prompt> svn commit -m "README now shows first in directory"
  1159. Move a file using the command-line client.
  1160. prompt> svn mv src/app/Widget.cs src/app/util/
  1161. prompt> svn commit -m "Moved Widget class into util package"
  1162. Rename a file using Tortoise.
  1163. Right-click a file or directory, and choose TortoiseSVN > Rename....
  1164. Commit your changes by right-clicking the base of your working copy and
  1165. choosing SVN Commit....
  1166. Move a file using Tortoise.
  1167. Using Windows Explorer, right-drag the file to a different location in your
  1168. working copy, and choose “SVN Move versioned item(s) here.”
  1169. Commit your changes by right-clicking the base of your working copy and
  1170. choosing SVN Commit....
  1171. Rename a file using Cornerstone.
  1172. Using the working copy browser, select the file you want to rename. Wait a
  1173. moment, and then click the file again. The filename will become editable;
  1174. type a new name for the file, and hit Enter.
  1175. Click Commit on the toolbar to commit your changes.
  1176. Move a file using Cornerstone.
  1177. Using the working copy browser, drag a file to a new location. Cornerstone
  1178. will offer to let you rename the file; hit Enter to confirm a new name and
  1179. move the file.
  1180. Click Commit on the toolbar to commit your changes.
  1181. Related Tasks
  1182. • Task 8, Seeing What You’ve Changed, on page 34
  1183. • Task 11, Committing Changes, on page 40
  1184. • Task 15, Reverting Working Copy Changes, on the next page
  1185. Report erratum
  1186. R EVERTING W ORKING C OPY C HANGES 48
  1187. 15 Reverting Working Copy Changes
  1188. If you decide that you no longer want some or all the changes you have
  1189. made in your working copy, you can revert those changes. The Subversion
  1190. client will restore the files as they were when you last checked out or
  1191. updated. Doing a revert doesn’t get you the latest changes from the
  1192. repository; you need to do an update to get those.
  1193. Subversion stores a pristine copy of each file in its hidden .svn
  1194. administrative directories so it can do a revert without needing to talk to the
  1195. server. This can be useful if you’re editing code on a plane or from home and
  1196. cannot get a network connection to the server.
  1197. Reverting a copied, moved, or renamed item within Cornerstone does not
  1198. delete the newly created copy of the item. These extra files and directories
  1199. will show up in the working copy browser with a yellow question-mark icon
  1200. next to them. Cmd+click, and choose Delete... to clean up these extra items.
  1201. Reverting working copy changes only helps you undo a work in progress. If
  1202. you have committed a change and want to undo it, you’ll need to look at
  1203. Task 23, Reverting a Committed Revision, on page 70.
  1204. Report erratum
  1205. R EVERTING W ORKING C OPY C HANGES 49
  1206. Revert changes to specific files or directories.
  1207. prompt> svn revert Number.txt
  1208. prompt> svn revert -R src/util/
  1209. Revert all the changes in your working copy.
  1210. prompt> cd work/mbench
  1211. prompt> svn revert -R .
  1212. Revert changes using Tortoise.
  1213. Right-click the base directory for your working copy, and choose
  1214. TortoiseSVN > Revert.... You’ll see a window similar to the following:
  1215. Check the items you want to revert, and click OK.
  1216. Revert changes using Cornerstone.
  1217. Select your project from the working copy sources list. In the working copy
  1218. browser, select the file or directory you want to revert, and click the Revert
  1219. button on the toolbar.
  1220. Related Tasks
  1221. • Task 8, Seeing What You’ve Changed, on page 34
  1222. • Task 23, Reverting a Committed Revision, on page 70
  1223. Report erratum
  1224. I GNORING F ILES 50
  1225. 16 Ignoring Files
  1226. Software development projects are complex beasts. A build tool or IDE will
  1227. often create temporary files while you are working on development tasks or
  1228. running a build. These temporary files are usually not useful to anyone else
  1229. and should not be stored in a Subversion repository. Subversion tries to be
  1230. helpful, however, and tells you that it doesn’t know about any file that has
  1231. not been added to the repository. These files will show with a question mark
  1232. when svn status shows the working copy status and will clutter up the
  1233. Tortoise and Cornerstone GUIs.
  1234. You can instruct Subversion to ignore certain files or directories by editing
  1235. the svn:ignore property on the directory containing the items you want to
  1236. ignore. You can find more information on properties in Task 43, Working
  1237. with Properties, on page 126. The svn:ignore property is plain text and
  1238. simply lists items to ignore, one item on each line. Wildcards are supported,
  1239. so, for example, *.tmp will ignore all temporary files.
  1240. Once you have altered the svn:ignore property on the directory, you must
  1241. commit the property change into the repository in order for other users to
  1242. benefit; until you commit, only your working copy is ignoring the specified
  1243. items. When other users update their working copies, their Subversion
  1244. clients will start to ignore the items as well.
  1245. Setting svn:ignore on a directory tells Subversion to ignore particular items
  1246. only in that directory. Matching items in subdirectories will not be ignored.
  1247. To avoid needing to set svn:ignore on lots of directories, you should set up
  1248. your project so that temporary files or binary artifacts are created in one
  1249. directory. Developers often choose a build directory in the rootof the
  1250. working copy. Set svn:ignore to ignore the build directory, and you’re
  1251. done—no more temporary files cluttering up Subversion’s status messages.
  1252. If you make a change to svn:ignore that you want to undo, simply revert
  1253. your working copy changes. Be careful not to revert changes to files,
  1254. however, because this is your work in progress! Just revert the change to the
  1255. directory.
  1256. Report erratum
  1257. I GNORING F ILES 51
  1258. Ignore files and directories using the command-line client.
  1259. mbench> svn status
  1260. ? test
  1261. ? out
  1262. M .idea/workspace.xml
  1263. M src/util/populator.java
  1264. mbench> svn propedit svn:ignore .
  1265. Edit the svn:ignore property so that it lists the test and out directories. Save
  1266. and quit your editor.
  1267. mbench> svn status
  1268. svn status
  1269. M .
  1270. M .idea/workspace.xml
  1271. M src/util/populator.java
  1272. mbench> svn commit -N -m "Ignored test and out directories" .
  1273. Ignore items using Tortoise.
  1274. Right-click the base directory for your working copy, and choose
  1275. TortoiseSVN > Check for modifications. Ensure “Show unversioned files” is
  1276. checked.
  1277. Right-click any file you want to ignore, and choose “Add to ignore list.”
  1278. Commit your changes to the repository.
  1279. Ignore items using Cornerstone.
  1280. Select your project from the working copy sources list. Select the All view,
  1281. and navigate to the files you want to ignore. Files that have not yet been
  1282. added to your repository are indicated with a yellow question-mark icon.
  1283. Ctrl+click each file you want to ignore, and choose Ignore. Commit your
  1284. changes to the repository.
  1285. Related Tasks
  1286. • Task 8, Seeing What You’ve Changed, on page 34
  1287. • Task 15, Reverting Working Copy Changes, on page 48
  1288. Report erratum
  1289. Part III
  1290. Working with a Team
  1291. W ORKING WITH A T EAM 53
  1292. Subversion is primarily a collaboration tool. Although you can use
  1293. Subversion on your own, its real power comes when it enables a
  1294. large team to work together on a single project. This part of the
  1295. book describes how to collaborate with other members of your
  1296. team as you all make changes to files stored in the repository.
  1297. For programming teams, a typical development session will involve
  1298. updating to the latest version of the code, making changes as they
  1299. complete development tasks, and finally committing changes to
  1300. the repository. Many teams accelerate their development cycle to
  1301. include multiple “update, change, commit” cycles throughout the
  1302. day. This is definitely a good way to keep in sync with other people
  1303. working on the project.
  1304. Subversion’s collaboration model doesn’t try to prevent two people
  1305. from changing the same file at the same time. Usually when devel-
  1306. opers are working on different features, they’re mostly working on
  1307. completely different sets of files. If a team does happen to have
  1308. two people working on the same file, you’ll usually find that they’re
  1309. working on different sections of the file. Subversion can automat-
  1310. ically merge these kinds of changes. More rarely, two developers
  1311. will change exactly the same part of a file, and Subversion cannot
  1312. automatically reconcile the two sets of changes. This is known as a
  1313. conflict. Subversion 1.6 also tracks tree conflicts, which occur when
  1314. users change files or directories in an incompatible way, such as
  1315. one user renaming a file while the other user changes its contents.
  1316. Subversion includes tools to help you resolve these conflicts, and we
  1317. cover them in this part of the book.
  1318. Subversion’s copy-modify-merge model is also known as optimistic
  1319. locking. The alternate strategy, pessimistic locking, can be enabled
  1320. for selected files. Task 29, Enabling File Locking, on page 92, de-
  1321. scribes this in more detail. Encountering lots of conflicts usually indi-
  1322. cates that something is going wrong on your project. It might be
  1323. that developers aren’t talking to each other often enough and are
  1324. doing overlapping work (fixing the same bug, for example). It might
  1325. also indicate that your code includes files that need to be edited
  1326. often—restructuring to have smaller files or classes may help.
  1327. Covered in this part:
  1328. • Staying in sync with your team is covered in Task 17, Updating
  1329. to the Latest Revision, on page 56.
  1330. Report erratum
  1331. W ORKING WITH A T EAM 54
  1332. • If multiple people change the same part of a file, Subversion
  1333. will report a conflict. Task 18, Handling Conflicts, on page 58
  1334. shows you how to resolve conflicts.
  1335. • Graphical tools give you a distinct advantage when resolving
  1336. conflicts. Task 19, Handling Conflicts Using Tortoise, on page 60
  1337. and Task 20, Handling Conflicts Using Cornerstone, on page 62
  1338. describe graphical conflict-resolution in detail.
  1339. Let’s start off by keeping in sync with the rest of the team.
  1340. Report erratum
  1341. W ORKING WITH A T EAM 55
  1342. Report erratum
  1343. U PDATING TO THE L ATEST R EVISION 56
  1344. 17 Updating to the Latest Revision
  1345. If you have multiple people working on a project, they will all be making
  1346. changes and committing to the repository. Doing an update gets these
  1347. changes from the repository and incorporates them into your working copy.
  1348. It’s a good idea to update fairly frequently; if you haven’t updated for a
  1349. while, then fixing any conflicts will take more time. You’ll learn how to deal
  1350. with conflicts in Task 18, Handling Conflicts, on page 58. If you have made
  1351. changes in your working copy, it’s still safe to do an update—Subversion
  1352. will incorporate the changes from the repository with your changes; it won’t
  1353. just overwrite or throw away all your hard work!
  1354. During the update process, Subversion will let you know what’s being
  1355. changed in your working copy. It will show files that have been added or
  1356. removed, files that have been updated, and files whose new contents have
  1357. been merged with your local changes.
  1358. TortoiseSVN includes a “Show log...” button once the update completes,
  1359. allowing you to easily see the log messages for recent changes. This can be
  1360. especially useful if the update has caused a conflict.
  1361. Cornerstone is fairly quiet during an update. There is a small activity
  1362. indicator at the bottom left of the window that shows an update is in
  1363. progress. To see everything that Cornerstone has done recently, click the
  1364. Transcript button on the bottom toolbar.
  1365. Report erratum
  1366. U PDATING TO THE L ATEST R EVISION 57
  1367. Update your working copy to the latest revision.
  1368. prompt> cd ~/work/mbench
  1369. prompt> svn update
  1370. Update your working copy using Tortoise.
  1371. Right-click the base directory in your working copy, and choose SVN
  1372. Update. Tortoise will open a status window and update your working copy.
  1373. Update your working copy using Cornerstone.
  1374. Select your project in the working copy sources list, and then click Update
  1375. on the toolbar.
  1376. Related Tasks
  1377. • Task 18, Handling Conflicts, on the following page
  1378. • Task 21, Viewing the Log, on page 66
  1379. Report erratum
  1380. H ANDLING C ONFLICTS 58
  1381. 18 Handling Conflicts
  1382. When two people change the same part of the same file, Subversion cannot
  1383. automatically merge the changes. Conflicts are actually quite rare because
  1384. they indicate that two people were working on exactly the same thing.
  1385. Sometimes two developers will try to fix the same bug and end up changing
  1386. the same file and cause a conflict or will be working on a common data
  1387. structure and both change it. Being on the receiving end of a merge conflict
  1388. is usually an indicator that you should be talking more often with your
  1389. colleagues.
  1390. If Alice and Bob are both working on the same part of the same file and
  1391. Alice checks in first, she won’t notice a problem.When Bob comes to check
  1392. in, he’ll be told that his version of the file is out-of-date; he needs to do an
  1393. update before he can commit. When he updates, Subversion will try to
  1394. merge his changes with Alice’s changes. Since both sets of changes are in
  1395. the same part of the file, Subversion tells Bob that there is a conflict.
  1396. The Subversion command-line client provides various options for resolving
  1397. conflicts. For each conflicted file, Subversion asks you to choose from the
  1398. following commands:
  1399. p Postpone fixing the conflict, and save the file with embedded conflict
  1400. markers. You can find the conflicts by looking for sequences of < < <
  1401. and > > > characters. Pick the text you’d like (your version, indicated
  1402. by the text .mine ; the version from the repository, indicated by a
  1403. revision number; or a combination of the two), and then save the file.
  1404. df Show a full diff of all the changes to the merged file. This shows all
  1405. your changes to the file plus any conflict markers that would be
  1406. inserted to show conflicts.
  1407. e Edit the merged file using an editor. The file will contain conflict
  1408. markers so you can find the conflicts and resolve them.
  1409. r Mark the conflict as resolved, accepting any edits you have made.
  1410. mf “My file”—ignore the changes from the repository, and use your
  1411. version of the file in full.
  1412. tf “Their file”—ignore your changes, and use the version of the file from
  1413. the repository in full.
  1414. l Launch an external merge tool 9 to merge the changes.
  1415. 9. Use the environment variable SVN_MERGE to tell Subversion which merge tool you’d like
  1416. to use.
  1417. Report erratum
  1418. H ANDLING C ONFLICTS 59
  1419. Use the command-line Subversion client to update and merge
  1420. files.
  1421. During an svn update , Subversion could discover conflicting changes and
  1422. need your help to resolve the conflict.
  1423. prompt> svn update
  1424. Conflict discovered in 'src/mbench.java'.
  1425. Select: (p) postpone, (df) diff-full, (e) edit,
  1426. (h) help for more options:
  1427. Enter commands (detailed on the opposite page) to merge the conflicting
  1428. changes. You can keep editing the files until you are happy.
  1429. Mark conflicts as resolved.
  1430. For each file that was conflicted, use svn resolved to tell Subversion that
  1431. you’ve fixed the problem.
  1432. prompt> svn resolved src/mbench.java
  1433. Related Tasks
  1434. • Task 8, Seeing What You’ve Changed, on page 34
  1435. • Task 17, Updating to the Latest Revision, on page 56
  1436. • Task 19, Handling Conflicts Using Tortoise, on the following page
  1437. • Task 20, Handling Conflicts Using Cornerstone, on page 62
  1438. Report erratum
  1439. H ANDLING C ONFLICTS U SING T ORTOISE 60
  1440. 19 Handling Conflicts Using Tortoise
  1441. During an update, Tortoise will keep track of any files that have conflicting
  1442. changes, coloring them red in the update window. At the very end of the
  1443. update log will be a message reminding you that some files were conflicted
  1444. and that you should fix the problem. You can fix conflicts later by
  1445. right-clicking files in Windows Explorer and choosing TortoiseSVN > Edit
  1446. conflicts, but it’s usually easiest to do it from the update window by
  1447. double-clicking each conflicted file.
  1448. The TortoiseMerge window is split into three sections. The top-left pane
  1449. shows “their” changes, that is, the changes someone else made and
  1450. committed to the repository. The top-right pane shows “my” changes, that is,
  1451. the changes we made in our working copy. The bottom pane shows the result
  1452. from the merge.
  1453. In the example screenshot, we can see that both sets of changes have
  1454. added diagnostic output when the mBench worker finishes testing Mongo. In
  1455. the repository version, the source code shows the exact number of reads and
  1456. writes performed. In our version, we simply state that the test is complete.
  1457. Subversion doesn’t know which block of code is correct, so TortoiseMerge
  1458. shows a block of ??? characters as the merge result. We might decide the
  1459. repository version is the correct one; right-click the block in the top-left pane,
  1460. and choose “Use this text block.” TortoiseMerge updates the output pane
  1461. to show the result as you select blocks from the two conflicting change sets.
  1462. Use the red up and down arrows toward the top of the TortoiseMerge
  1463. window to quickly move to the next (or previous) conflict. Once you have
  1464. resolved all the conflicts, click the green tick icon on the menu bar to mark
  1465. the file resolved.
  1466. Report erratum
  1467. H ANDLING C ONFLICTS U SING T ORTOISE 61
  1468. Update from the repository where there is a conflict.
  1469. Right-click the base directory in your working copy, and choose SVN
  1470. Update. If there is a conflict, Tortoise will show conflicted files in red and
  1471. warn you that there was a conflict.
  1472. Use the TortoiseMerge tool to resolve conflicts.
  1473. For each conflicted file, double-click it to launch TortoiseMerge.
  1474. Related Tasks
  1475. • Task 8, Seeing What You’ve Changed, on page 34
  1476. • Task 17, Updating to the Latest Revision, on page 56
  1477. • Task 18, Handling Conflicts, on page 58
  1478. Report erratum
  1479. H ANDLING C ONFLICTS U SING C ORNERSTONE 62
  1480. 20 Handling Conflicts Using Cornerstone
  1481. When you update from the repository, Cornerstone will track any files where
  1482. Subversion encounters a conflict. Unfortunately, Cornerstone is not very
  1483. verbose in telling you that files are conflicted; you need to select the
  1484. Modified or Conflicted view in the working copy browser in order to easily
  1485. see conflicted files.
  1486. Cornerstone includes simple conflict resolution strategies. In most cases, you
  1487. should edit the conflicted file to remove the <<< and >>> conflict markers.
  1488. These markers are labeled so that you can see the difference between your
  1489. version of the file and the repository version. For each conflict, determine
  1490. what the correct code block should be, and edit the file to reflect your choice.
  1491. Once you are satisfied that the conflicts are resolved, use the Resolved
  1492. button to mark the file resolved.
  1493. In some cases, you will know that all conflicts in a file should be resolved by
  1494. using the repository changes or by using your working copy changes. In this
  1495. case, select the file in the working copy browser, and then click and hold the
  1496. Resolve button on the bottom toolbar. Choose Resolve to Latest in
  1497. Repository to have repository changes chosen in favor of your local changes.
  1498. Choose Resolve to My Changes to have local changes chosen in favor of
  1499. repository changes.
  1500. Report erratum
  1501. H ANDLING C ONFLICTS U SING C ORNERSTONE 63
  1502. Update from the repository where there is a conflict.
  1503. Select your project from the working copy sources list, and click Update on
  1504. the toolbar. Click Changed to show just files that have changed and might
  1505. have a conflict. If any of your files have a red C icon next to them, you have
  1506. a conflict.
  1507. Edit the file to resolve conflicts.
  1508. Double-click the conflicted file to launch the default editor for that file. Edit
  1509. the file to remove Subversion’s conflict markers.
  1510. Mark the conflict as resolved.
  1511. Select the conflicted file using the working copy browser. Click the Resolved
  1512. button on the bottom toolbar to mark the conflict resolved.
  1513. Related Tasks
  1514. • Task 8, Seeing What You’ve Changed, on page 34
  1515. • Task 17, Updating to the Latest Revision, on page 56
  1516. • Task 18, Handling Conflicts, on page 58
  1517. Report erratum
  1518. Part IV
  1519. Using the History
  1520. U SING THE H ISTORY 65
  1521. Version control tools like Subversion allow you to do more than sim-
  1522. ply keep your files in a safe place and collaborate with your team.
  1523. Subversion stores every revision of every file that was ever commit-
  1524. ted to the repository. You can think of this detailed history as a kind
  1525. of time machine—you can go back to any point in history if some-
  1526. thing goes wrong.
  1527. More than just being able to go back to a specific point in time
  1528. and do things differently, Subversion’s powerful history functions let
  1529. you understand how things got to be the way they are today. Often
  1530. you’ll need to do some detective work to figure out why or when a
  1531. certain bug was introduced, who last made a particular change, or
  1532. which people were involved in developing certain functionality.
  1533. Subversion’s history functions all depend on a key piece of informa-
  1534. tion: the log messages associated with each revision. It’s all too easy
  1535. to leave the message blank or type something simple like “fixed a
  1536. bug,” but using a good log message will make things much easier
  1537. for others doing detective work later.
  1538. Subversion already stores the textual changes that were made, so
  1539. there’s not much point writing a message that says “added BP net-
  1540. work protocol.” Instead, you should use the log message to indicate
  1541. why you made the change:
  1542. Network connections to our Mars rover won’t work using regular TCP
  1543. networking because, even at the speed of light, signals can take
  1544. twenty minutes to reach the rover. Bundle Protocol solves this prob-
  1545. lem by allowing much higher-latency network connections.
  1546. If the change being made is fixing a bug, you should include the
  1547. bug identifier (number, code name) in the commit message. The
  1548. other information about the bug—description, how to reproduce,
  1549. and so on—doesn’t need to be repeated.
  1550. Covered in this part:
  1551. • Browsing recent repository activity is covered in Task 21, View-
  1552. ing the Log, on the following page.
  1553. • Examining exactly how a portion of a file got to its current
  1554. state is covered in Task 22, Detective Work with svn blame,
  1555. on page 68.
  1556. • Sometimes you’ll want to undo a change that has already
  1557. been committed to the repository. Task 23, Reverting a Com-
  1558. mitted Revision, on page 70 shows how to do this.
  1559. Let’s start by looking at recent repository history.
  1560. Report erratum
  1561. V IEWING THE L OG 66
  1562. 21 Viewing the Log
  1563. When you are working as part of a project team, many people will be
  1564. making changes and committing them to the repository. Depending on the
  1565. size of your team and how often they commit, there might be dozens of
  1566. changes every day. If you have been away from the project for a while, or
  1567. even as part of your daily routine, you might want to check what has been
  1568. committed recently.
  1569. Subversion’s log stores every change ever committed to the repository. To
  1570. see recent changes, you can ask Subversion to show the log for your working
  1571. copy. Subversion shows changes in reverse chronological order, starting with
  1572. the most recent change and then working backward. This might be a long list
  1573. of changes—for the command-line client you should pipe the output into a
  1574. pager program such as less . The graphical clients usually show just the last
  1575. 100 or so changes unless you specifically ask for more.
  1576. Subversion will show log entries only for revisions that have been applied to
  1577. your working copy. If you haven’t updated your working copy for a while
  1578. and ask to see the log, you won’t see any recent changes that have been
  1579. made by other people. To see those log messages, you’ll need to update your
  1580. working copy first.
  1581. Both Tortoise and Cornerstone provide easy ways to browse the log and
  1582. examine changes in detail. You can scroll through the various log messages
  1583. looking for something interesting and then click individual changed files and
  1584. show the exact differences when that revision was committed. The first time
  1585. you show the log, Cornerstone will offer to cache the log to speed up future
  1586. requests. You should allow it to do so if you have a fairly fast connection to
  1587. your Subversion server.
  1588. You can also show the log for a repository URL instead of a working copy.
  1589. The command-line client works as follows:
  1590. prompt> svn log http://svn.mycompany.com/mbench/trunk
  1591. To show the log for a repository URL using TortoiseSVN, start the Repo
  1592. Browser, and enter the URL for your repository. Right-click the base
  1593. directory for your project, and choose Show Log.
  1594. To show the log for a repository using Cornerstone, select a repository from
  1595. the repository source list, and then click the Log button to show the log.
  1596. Report erratum
  1597. V IEWING THE L OG 67
  1598. Show log entries for your working copy.
  1599. prompt> cd ~/work/myproject
  1600. prompt> svn log | less
  1601. Show the log using Tortoise.
  1602. Right-click at the base of your working copy, and choose TortoiseSVN >
  1603. Show Log. Select any log entry to see all the files that were changed, and
  1604. double-click any file to show the diff for that file.
  1605. Show the log using Cornerstone.
  1606. Select your project from the working copy sources list, and then click the
  1607. Log button on the bottom toolbar. Cornerstone will show a list of revisions
  1608. including their log message and when the change was made. Click the
  1609. expander triangle next to Changes to show the full list of files that were
  1610. changed, and double-click any file to show the diff for that file.
  1611. Related Tasks
  1612. • Task 22, Detective Work with svn blame, on the next page
  1613. • Task 23, Reverting a Committed Revision, on page 70
  1614. Report erratum
  1615. D ETECTIVE W ORK WITH SVN BLAME 68
  1616. 22 Detective Work with svn blame
  1617. While working on a programming task, it’s often very useful to find out who
  1618. most recently changed a particular piece of code. You might find the code
  1619. hard to understand or have questions about it, or it might just be plain bad
  1620. code, and you’d like to offer some advice to whoever wrote it.
  1621. The Subversion blame command tells you who is responsible for each line
  1622. in a particular file. You can also use praise , annotate , and ann as
  1623. synonyms for blame .
  1624. When you run the blame command, Subversion goes back through the
  1625. history of the file and determines who most recently changed each line and
  1626. when they changed it. In the command-line example on the facing page, we
  1627. can see that mbench.java has two people who have changed it most
  1628. recently, mike and ian. The numbers that Subversion prints by each line
  1629. aren’t line numbers; they are the revision in which that line was most
  1630. recently changed.
  1631. Subversion is telling us who changed each line in the file and when that
  1632. change was made. This isn’t quite the same as telling us who wrote the
  1633. code—if someone commits a change that adds something to a line, removes
  1634. something, or even just changes whitespace, blame will put their name on
  1635. that line of code. This is a subtle distinction, but blame is still useful because
  1636. if someone is committing a change to a line of code, they should know what
  1637. that code does.
  1638. TortoiseSVN shows the blame information in ascrollable window with
  1639. usernames and revision numbers down the left side. Hover the mouse over a
  1640. particular revision number to see extra information, including the log
  1641. message for that revision. Right-clicking a revision number will give extra
  1642. options, such as viewing the revision in full, including all the files that were
  1643. changed.
  1644. As of this writing, Cornerstone unfortunately does not support showing
  1645. blame information, so you’ll need to use the command-line client instead.
  1646. Report erratum
  1647. D ETECTIVE W ORK WITH SVN BLAME 69
  1648. Show blame information using the command-line client.
  1649. mbench> svn blame src/mbench.java
  1650. 11 mike import com.mongodb.Mongo;
  1651. : : :
  1652. 6 mike public class mbench {
  1653. 11 mike public static void main(String[] args) {
  1654. 11 mike if(args.length != 3) {
  1655. 6 mike usage();
  1656. 7 mike return;
  1657. 6 mike }
  1658. : : :
  1659. 11 mike worker worker = new worker(db, runTime);
  1660. 11 mike worker.go();
  1661. 12 mike
  1662. 14 ian long readsPerSec = worker.getReads() / runTime;
  1663. 14 ian long writesPerSec = worker.getWrites() / runTime;
  1664. 14 ian System.out.println("Reads/sec: " + readsPerSec);
  1665. 14 ian System.out.println("Writes/sec: " + writesPerSec);
  1666. 6 mike }
  1667. Show blame information using Tortoise.
  1668. Navigate to your working copy using Windows Explorer. Right-click a file,
  1669. and choose TortoiseSVN > Blame.... Click OK to use the default settings.
  1670. TortoiseSVN will show blame information from the earliest revision of the
  1671. file.
  1672. Related Tasks
  1673. • Task 8, Seeing What You’ve Changed, on page 34
  1674. • Task 21, Viewing the Log, on page 66
  1675. Report erratum
  1676. R EVERTING A C OMMITTED R EVISION 70
  1677. 23 Reverting a Committed Revision
  1678. Sometimes you will want to undo a change that has been committed to the
  1679. repository. You might find out that a change intended to fix a bug actually
  1680. introduced a new bug, and you want to undo your attempted bug fix. The
  1681. requirements for your software might have changed, meaning that some
  1682. code changes you committed are no longer worthwhile. Whatever the
  1683. reason, Subversion’s history tracking tools allow you to go back and undo
  1684. the changes that were made.
  1685. Subversion doesn’t actually allow us to delete history from the repository;
  1686. we can only keep moving forward. To undo an old revision, we have to
  1687. reverse whatever changes were made in the old revision and then commit a
  1688. new revision. This is called a reverse merge.
  1689. Use Subversion’s history features to determine the change you want to
  1690. revert. A reverse merge will update your working copy files so they no
  1691. longer contain the changes from the original revision—you are not changing
  1692. anything inside the repository so you will get a chance to test that the revert
  1693. has worked properly. As with any merge operation, you might encounter
  1694. conflicts. Task 18, Handling Conflicts, on page 58 has more information on
  1695. dealing with conflicts.
  1696. If you only want to undo part of a committed revision rather than the whole
  1697. revision, you need to revert some of your working copy files after
  1698. Subversion has finished the reverse merge. For these files, you are reverting
  1699. the reverse merge, which gets you back where you started.
  1700. If you want to revertonly changes to a particular directory, then things are
  1701. much easier. For the command-line client, change to the directory you want
  1702. to revert before running the revert command. If you’re using Tortoise,
  1703. right-click the folder containing files you want to revert before using the log
  1704. to find, and revert the change.
  1705. The change you are reverting might be recent, but it could also be quite old.
  1706. Depending on how fast your code base evolves, other parts of the code may
  1707. have changed since the original change was committed. You should always
  1708. run a build before checking in to make sure that everything still works.
  1709. If you are reverting using Cornerstone, be aware that it works slightly
  1710. differently than the command line and Tortoise clients. Reverting to a
  1711. particular revision undoes all the changes made since that revision. In most
  1712. cases this is still useful, but it’s a little less surgical than doing a
  1713. command-line reverse merge.
  1714. Report erratum
  1715. R EVERTING A C OMMITTED R EVISION 71
  1716. Revert a revision using the command-line client.
  1717. mbench> svn merge -r 14:13 .
  1718. --- Reverse-merging r14 into '.':
  1719. G .idea/workspace.xml
  1720. U src/mbench.java
  1721. prompt> svn commit -m "Reverted revision 14"
  1722. Revert a revision using Tortoise.
  1723. Browse to your working copy folder using Windows Explorer. Right-click
  1724. the root folder, and choose TortoiseSVN > Show Log. Find the change you
  1725. want to revert, and then right-click it and choose “Revert changes from this
  1726. revision.” Tortoise will reverse merge the change.
  1727. Run a build to make sure you haven’t broken anything, and then commit
  1728. your changes back into the repository.
  1729. Revert a revision using Cornerstone.
  1730. In the working copy browser, select the items you want to revert to a
  1731. previous revision, and then select Working Copy > Revert... from the
  1732. Cornerstone menu.
  1733. Type a revision number or use the revision picker to choose the revision to
  1734. which you want to revert. Click Revert to set the items back to the selected
  1735. revision.
  1736. Run a build to make sure you haven’t broken anything, and then commit
  1737. your changes back into the repository.
  1738. Related Tasks
  1739. • Task 15, Reverting Working Copy Changes, on page 48
  1740. • Task 21, Viewing the Log, on page 66
  1741. • Task 18, Handling Conflicts, on page 58
  1742. Report erratum
  1743. Part V
  1744. Branching, Merging, and Tagging
  1745. B RANCHING , M ERGING , AND T AGGING 73
  1746. Real-world software projects are rarely straightforward and easy. The
  1747. team must develop the software, stabilize it ready to be released
  1748. into production, and support it once it’s in production.We’ve shown
  1749. how a team can use Subversion to collaborate during develop-
  1750. ment; this chapter will focus on how a team can release and sup-
  1751. port their software.
  1752. Usually when a team is preparing to release their software, they
  1753. want to focus on quality. The team might decide to fix bugs and
  1754. improve performance rather than adding new features. Generally,
  1755. though, the team will want to continue some forward momentum.
  1756. Maybe the team will split, with some developers working on stabiliz-
  1757. ing the code for release and everyone else developing as normal.
  1758. These two activities, stabilization and adding newfeatures, gener-
  1759. ally cannot be done in the same code base. It’s very likely that the
  1760. new features will add instability to the software, which is exactly
  1761. what we don’t want when we’re trying to put a release into pro-
  1762. duction. The solution is to branch the code. Branching splits off a
  1763. new line of development where stabilization and bug fixing can be
  1764. done, while new features can continue to be added on the trunk.
  1765. The following diagram shows the branch and the trunk visually:
  1766. release branch
  1767. trunk
  1768. create
  1769. branch
  1770. stabilize
  1771. for
  1772. release
  1773. new features
  1774. develop
  1775. fix bugs
  1776. The first step is to create a branch. Branches are identified with a
  1777. name and are stored in the branches directory within the Subver-
  1778. sion repository. A branch starts out as an exact copy of the trunk
  1779. but can be modified independently. One team can work on the
  1780. branch, fixing bugs and stabilizing the code. Another team can
  1781. work on the trunk, adding new features. The two teams will never
  1782. accidentally surprise each other because they are working on dif-
  1783. ferent branches.
  1784. Report erratum
  1785. B RANCHING , M ERGING , AND T AGGING 74
  1786. When working on a release branch, there are usually some bug fixes
  1787. or other improvements that we’d like to include in the trunk. Rather
  1788. than making a fix on the branch and then reimplementing the fix
  1789. on the trunk, Subversion allows us to merge the change from the
  1790. branch to the trunk. Subversion can do this because a branch is
  1791. much more than a simple copy of the files. Subversion remembers
  1792. the origin of the files on the trunk and the branch, and it uses their
  1793. shared ancestry to make merges easier and more automatic. The
  1794. dotted lines on the following diagram show changes being merged
  1795. from the release branch to the trunk:
  1796. release branch
  1797. trunk
  1798. create
  1799. branch
  1800. merge all
  1801. branch changes
  1802. stabilize
  1803. for
  1804. release
  1805. new features
  1806. develop
  1807. fix bugs
  1808. The diagram shows a fairly standard release branch strategy but
  1809. does require a lot of merging because every change made on the
  1810. branch needs to be merged back to the trunk. It’s usually best to
  1811. reduce the number of merges in your branching strategy because
  1812. this reduces effort and the potential for a “forgotten” merge. We
  1813. can change the branching strategy to reduce merging as follows.
  1814. Stabilize for release before creating the branch, and then fix any
  1815. bugs on the trunk and merge them to the branch. The branch dia-
  1816. gram looks like this:
  1817. release branch
  1818. trunk
  1819. create
  1820. branch
  1821. merge
  1822. bug fixes
  1823. stabilize
  1824. for
  1825. release
  1826. new features
  1827. develop
  1828. fix bugs
  1829. Report erratum
  1830. B RANCHING , M ERGING , AND T AGGING 75
  1831. You might already be familiar with branching and merging and
  1832. have your own strategy. Thisis fine; just make sure everyone on the
  1833. team understands where they need to make fixes and where they
  1834. should merge. If you’re not careful and disciplined, it’s possible to
  1835. “lose” a change. For example, if you fixed a bug on the release
  1836. branch but forgot to merge the fix to the trunk, the trunk still has that
  1837. bug. The QA team might see the bug in a later release and call it a
  1838. regression since from their perspective it was fixed once already.
  1839. Another strategy worth mentioning is called feature branching. A
  1840. team might use this when a new feature will take a long time or
  1841. cause some instability in the code base. Instead of developing the
  1842. feature on the trunk, the team can create a branch specifically
  1843. for the feature. The rest of development continues on the trunk as
  1844. normal. The feature branch should be updated with trunk changes
  1845. frequently—usually daily—to keep the feature branch “close” to the
  1846. trunk. This merge from the trunk to the feature branch is known as
  1847. rebasing. Once the feature is finished, merge the feature branch
  1848. back to the trunk.
  1849. trunk
  1850. create
  1851. branch
  1852. daily
  1853. merge
  1854. trunk features
  1855. develop
  1856. implement
  1857. feature
  1858. merge to
  1859. trunk
  1860. When a customer calls up with a problem, it’s important to know
  1861. exactly what code they are running so you can diagnose and fix
  1862. the problem. You should only ship software to a customer from a
  1863. release branch, but since the code on the branch can change over
  1864. time, you need a better way to uniquely identify a release. With
  1865. Subversion, you can tag the code that was used to build a release,
  1866. giving it a number such as 2.0.3. To create a tag, you will copy your
  1867. release branch into a named directory within the repository tags
  1868. directory. Usually the tag name is also compiled into the software
  1869. Report erratum
  1870. B RANCHING , M ERGING , AND T AGGING 76
  1871. as a version number. Once you know what version your customer is
  1872. running, you can check out the tagged code and get exactly the
  1873. code that is running in production.
  1874. The following diagram shows a release branch with two tags, R-1.0.0
  1875. and R-1.0.1 :
  1876. release branch
  1877. trun
  1878. fix bugs
  1879. create tags
  1880. R-1.0.0 R-1.0.1
  1881. Covered in this part:
  1882. • Task 24, Creating a Branch, on page 78 shows how to create
  1883. a release branch.
  1884. • If you have a trunk working copy and want to quickly switch
  1885. to a branch, follow the instructions in Task 25, Switching to a
  1886. Branch, on page 80.
  1887. • Task 26, Merging Changes from Trunk to Branch, on page 82
  1888. covers the process for merging changes, such as bug fixes, to
  1889. a branch.
  1890. • Repeated merging, usually used to keep the trunk and a
  1891. branch in sync, is discussed in Task 27, Using Change Tracking,
  1892. on page 84.
  1893. • Tagging is explained in detail in Task 28, Tagging a Release, on
  1894. page 86.
  1895. Let’s start by creating a release branch.
  1896. Report erratum
  1897. B RANCHING , M ERGING , AND T AGGING 77
  1898. Report erratum
  1899. C REATING A B RANCH 78
  1900. 24 Creating a Branch
  1901. Subversion branches are copies of the trunk and are stored in the branches
  1902. directory inside the repository. The branches directory sits alongside the
  1903. trunk directory, as we saw in Task 5, Creating an Empty Project, on page 24.
  1904. This directory organization is a Subversion convention—nothing forces you
  1905. to organize your repository in this way, but if you stick to the convention, it
  1906. makes it easier for people to work with your project.
  1907. To create a branch, use the Subversion copy command to copy the trunk to a
  1908. new location. You should always use repository URLs when creating a
  1909. branch. You can copy the file revisions in a working copy to create a branch,
  1910. but using a repository URL is much faster. It’s also safer because if your
  1911. working copy contains mixed revisions (not all the files in a working copy
  1912. have to be at the same revision), Subversion will faithfully copy the mixed
  1913. revisions to the branch, which usually isn’t what you want to do.
  1914. Branches can be named using any characters that Subversion allows in a
  1915. directory name, including spaces and characters with accents (although we
  1916. suggest sticking to alphanumerics). Use a naming scheme that makes it easy
  1917. to identify branches. Here we’re using “RB” to indicate a release branch,
  1918. followed by the version number of the branch. You could also organize your
  1919. branches into different directories, such as releases/1.0 .
  1920. Once you have created your branch, you can check out a working copy of
  1921. the code. Make sure that you use a working copy directory name that makes
  1922. it easy to identify the branch. In our example, we already have an mbench
  1923. directory for the trunk working copy, so we check out into an mbench-1.0
  1924. directory for the 1.0 release branch.
  1925. Report erratum
  1926. C REATING A B RANCH 79
  1927. Create a release branch.
  1928. prompt> svn copy -m "Create 1.0 release branch" \
  1929. http://svn.mycompany.com/mbench/trunk \
  1930. http://svn.mycompany.com/mbench/branches/RB_1.0
  1931. Check out the branch to a new working copy.
  1932. prompt> cd ~/work
  1933. prompt> svn checkout \
  1934. http://svn.mycompany.com/mbench/branches/RB_1.0 \
  1935. mbench-1.0
  1936. Create a branch using Tortoise.
  1937. Using Windows Explorer, right-click the base directory for your working
  1938. copy, and choose TortoiseSVN > Branch/tag....
  1939. Edit the To URL setting, replacing trunk with branches/RB_1.0 , and click
  1940. OK.
  1941. Enter a log message, and click OK to create the branch.
  1942. Create a branch using Cornerstone.
  1943. Select your repository from the repository source list, and then navigate to
  1944. the trunk directory for your project.
  1945. Drag the trunk directory to the branches directory while holding down the
  1946. Option key. Your mouse pointer will indicate you are about to make a copy
  1947. with a green + icon.
  1948. Give the branch a name, click Copy, and then enter a log message. Click
  1949. Continue to create the branch.
  1950. Related Tasks
  1951. • Task 7, Checking Out a Working Copy, on page 32
  1952. • Task 25, Switching to a Branch, on the following page
  1953. • Task 26, Merging Changes from Trunk to Branch, on page 82
  1954. Report erratum
  1955. S WITCHING TO A B RANCH 80
  1956. 25 Switching to a Branch
  1957. Once you have created a branch, changes made on the trunk will be isolated
  1958. from changes made on the branch. To make changes to the branch, you need
  1959. to have a working copy that is pointing at the branch instead of the trunk.
  1960. The easiest way to get a working copy of the branch is to check out a new
  1961. working copy using the branch URL instead of the usual trunk URL. This
  1962. leaves you with two working copies on your computer: one for the trunk and
  1963. one for the branch. Sometimes it’s not desirable to have two working copies,
  1964. for example when the working copy is large and takes a long time to check
  1965. out or when you have application servers or databases configured to point to
  1966. the working copy.
  1967. The switch command tells Subversion to take an existing working copy and
  1968. update it so that it is pointing at a different branch. Subversion figures out
  1969. what version of the files you have in your working copy and then merges
  1970. changes as necessary to reflect the state of the branch. A switched working
  1971. copy, under most circumstances, is identical to a freshly checked-out copy of
  1972. the branch.
  1973. If you spend a lot of time switching between branches, it’s possible to lose
  1974. track of where a particular working copy is pointing. The svn info command
  1975. will print out this information. If you’re using Tortoise, right-clicking in any
  1976. working copy folder and choosing TortoiseSVN > Repo-browser will always
  1977. pop up the browser pointing to wherever your working copy is pointed.
  1978. Sometimes you might do some work in a working copy, such as fixing a bug,
  1979. and then realize that you should have done the work on a branch instead.
  1980. Your work is not wasted, however. Switching to a branch attempts to leave
  1981. your working copy changes intact, so you can switch your working copy to
  1982. the branch and then check in your changes.
  1983. It’s very easy to lose track of where you are if you switch a working copy a
  1984. lot. We recommend using multiple working copies for each of your branches
  1985. and avoiding switching where possible.
  1986. Cornerstone does not include an option to switch a working copy. Use
  1987. multiple working copies for each of your branches instead.
  1988. Report erratum
  1989. S WITCHING TO A B RANCH 81
  1990. Switch to a branch.
  1991. prompt> cd work/mbench
  1992. mbench> svn switch http://svn.mycompany.com/mbench/branches/RB_1.0
  1993. Switch to a branch using Tortoise.
  1994. Using Windows Explorer, navigate to the base directory for your working
  1995. copy. Right-click the base directory, and choose TortoiseSVN > Switch....
  1996. Edit the To URL setting to reflect the branch you’d like to switch to, or press
  1997. the ... button to use the repo browser to find the branch.
  1998. Click OK to perform the switch.
  1999. Related Tasks
  2000. • Task 24, Creating a Branch, on page 78
  2001. • Task 26, Merging Changes from Trunk to Branch, on the next page
  2002. Report erratum
  2003. M ERGING C HANGES FROM T RUNK TO B RANCH 82
  2004. 26 Merging Changes from Trunk to
  2005. Branch
  2006. When stabilizing your code ready for release, it’s best to fix bugs on the
  2007. trunk and then merge the fixes to the branch. If you do things the other way
  2008. around, you might forget to merge a fix back to the trunk, and it will show up
  2009. as a regression in your next release.
  2010. Fix the bug on the trunk, and note the revision number where the fix was
  2011. checked in. In a branch working copy, merge the revision or revisions from
  2012. the trunk. In most cases, the merge will work automatically without any
  2013. conflicts. The merge works kind of like an update; think of the branch as an
  2014. old working copy that needs to incorporate new changes from the trunk to
  2015. keep it up-to-date. If the trunk and the branch have diverged, though,
  2016. merging the change might create a conflict. See Task 18, Handling Conflicts,
  2017. on page 58 for more information about resolving conflicts.
  2018. After merging the changes, you should run a build to make sure that you
  2019. haven’t broken anything. You should also check to ensure the fix is still
  2020. working and that the bug is no longer present on the branch version of the
  2021. code. Check in the changes to complete the merge.
  2022. When checking in, it’s a good idea to use a log message that includes the
  2023. revisions you merged and the number or identifier for the bug that you’re
  2024. fixing. The other members of your team will thank you for the extra
  2025. information if they have to chase down a bug fix later.
  2026. Tortoise includes some nice GUI tools for finding and merging revisions, so
  2027. you don’t need to do quite as much work remembering revisionnumbers.
  2028. Cornerstone unfortunately does not include merge functionality, so you’ll
  2029. need to use the command-line client for Mac merging.
  2030. Report erratum
  2031. M ERGING C HANGES FROM T RUNK TO B RANCH 83
  2032. Merge a single revision to a branch.
  2033. prompt> cd work/mbench-1.0
  2034. mbench-1.0> svn merge -c 16 http://svn.mycompany.com/mbench/trunk
  2035. mbench-1.0> svn commit -m "Merged r16 (fix bug-7) from the trunk"
  2036. Merge a range of revisions to a branch.
  2037. prompt> cd work/mbench-1.0
  2038. mbench-1.0> svn merge -r 19:22 http://svn.mycompany.com/mbench/trunk
  2039. mbench-1.0> svn commit -m \
  2040. "Merged r19-22 from the trunk (fix bugs 9 and 11)"
  2041. Merge revisions using Tortoise.
  2042. Right-click in the base directory of a branch working copy, and choose
  2043. TortoiseSVN > Merge....
  2044. Select “Merge a range of revisions” as the merge type, and click Next.
  2045. Enter the URL for the project trunk in the “URL to merge from” box.
  2046. Alternatively, click the ... button and use the repo browser to find the trunk.
  2047. Enter revision numbers to merge, or press the “Show log” button to choose
  2048. revisions based on their log message.
  2049. Click Next to go to the Merge options screen, leave all the settings at their
  2050. defaults, and click Merge to complete the merge.
  2051. Check in your changes using a log message that includes a list of the
  2052. revisions you merged.
  2053. Related Tasks
  2054. • Task 24, Creating a Branch, on page 78
  2055. • Task 25, Switching to a Branch, on page 80
  2056. Report erratum
  2057. U SING C HANGE T RACKING 84
  2058. 27 Using Change Tracking
  2059. Sometimes a team will use a feature branch to work on a major change that
  2060. might be disruptive to developers working on the trunk. The work can
  2061. proceed safely on the branch, and when completed, the changes are merged
  2062. to the trunk, and the branch is deleted.
  2063. Afeaturemighttakeawhiletocomplete, increasing theriskthatthetrunkand
  2064. the feature branch diverge and making the impending “merge to trunk” more
  2065. difficult. Developers working on the branch might choose to periodically
  2066. pull changes from the trunk to the feature branch in order to reduce this
  2067. risk, a technique known as rebasing. Subversion’s merge tracking feature
  2068. allows us to automatically merge any trunk changes to a branch that have
  2069. not previously been merged and to repeat this merge as often as we’d like.
  2070. In the example on the facing page, we would like to add internationalization
  2071. to our software in the DEV_i18n branch. We start with the feature
  2072. branch already created and two working copies, mbench for the trunk and
  2073. mbench_i18n for the feature branch. Internationalization might take a while,
  2074. so we periodically reintegrate changes from the trunk. Run the reintegration
  2075. frequently, at least once a week. Each time Subversion will only pick
  2076. up new changes from the trunk that haven’t yet been merged to the branch.
  2077. Once the work on the feature branch is complete, merge from the feature
  2078. branch to the trunk. Subversion will only merge changes that were made on
  2079. the feature branch; it won’t try to merge changes that originally came from
  2080. the trunk. Because we have used merge tracking to keep the trunk and the
  2081. branch close together, merging the feature branch to the trunk should be
  2082. straightforward.
  2083. Merge tracking requires Subversion 1.6 or newer. 10 If you are using an older
  2084. release of Subversion, you can achieve the same effect of keeping the branch
  2085. and the trunk close together, but you’ll need to manually track which
  2086. changes have been merged and do all your merges explicitly. There are
  2087. certain situations that merge tracking cannot handle, such as file renames
  2088. and deletes. If your team does a lot of refactoring, you should ask people to
  2089. avoid doing renames or deletes while you are working on a feature branch.
  2090. 10. Change tracking was first implemented in Subversion 1.5, but the newer 1.6 release includes
  2091. substantial improvements and bug fixes. You really should use Subversion 1.6 or newer if you
  2092. want change tracking.
  2093. Report erratum
  2094. U SING C HANGE T RACKING 85
  2095. Merge outstanding changes from the trunk to a feature branch.
  2096. prompt> cd work/mbench_i18n
  2097. mbench_18n> svn update
  2098. mbench_18n> svn merge --reintegrate \
  2099. http://svn.mycompany.com/mbench/trunk
  2100. mbench_18n> svn commit -m "Merged all pending trunk changes"
  2101. Merge a completed feature branch to the trunk.
  2102. prompt> cd work/mbench
  2103. mbench> svn update
  2104. mbench> svn merge --reintegrate \
  2105. http://svn.mycompany.com/mbench/branches/DEV_i18n
  2106. mbench> svn commit -m "Merged feature branch DEV_i18n"
  2107. Merge trunk changes to a feature branch using Tortoise.
  2108. Right-click the base directory of your branch working copy, and choose
  2109. TortoiseSVN > Merge....
  2110. Select “Reintegrate a branch” as the merge type, and click Next.
  2111. Enter the URL for the project trunk in the “from URL” box.
  2112. Click Next to go to the Merge options screen, leave all the settings at their
  2113. defaults, and click Merge to complete the merge.
  2114. Merge a completed feature branch using Tortoise.
  2115. Right-click the base directory of your trunk working copy, and choose
  2116. TortoiseSVN > Merge....
  2117. Select “Reintegrate a branch” as the merge type, and click Next.
  2118. Enter the URL for the feature branch in the “from URL” box.
  2119. Click Next to go to the Merge options screen, leave all the settings at their
  2120. defaults, and click Merge to complete the merge.
  2121. Related Tasks
  2122. • Task 24, Creating a Branch, on page 78
  2123. • Task 25, Switching to a Branch, on page 80
  2124. • Task 26, Merging Changes from Trunk to Branch, on page 82
  2125. Report erratum
  2126. T AGGING A R ELEASE 86
  2127. 28 Tagging a Release
  2128. When creating a build of your software, especially one that will be released
  2129. to a customer, it’s important to know exactly what source code was used. We
  2130. can use a Subversion tag to record which revisions of files were used in a
  2131. build.
  2132. As part of the release process, someone needs to compile the software.
  2133. Usually this is a manual process done by one of the developers, but it can
  2134. also be automated. You might have a build box that automatically builds your
  2135. software every time a developer makes a change. Either way, you should
  2136. have a process for building the software and assigning it a build number.
  2137. Use the Subversion copy command to copy your working copy to a new
  2138. directory in your project’s tags directory. You should create a tag from the
  2139. working copy that was used to make the build, rather than the repository
  2140. HEAD revision, because other changes could have been checked in since
  2141. you started the build. Creating a tag from your working copy guarantees that
  2142. the tag contains exactly the revisions of the files that were used to make the
  2143. build. If your release is being created by an automated build server, it will
  2144. still have a working copy that it uses to compile the code. The build server
  2145. should create a tag from this working copy as part of the build process.
  2146. Cornerstone does not allow creation of a tag from a working copy, so you’ll
  2147. need to be a little bit more careful when tagging releases. Use the log
  2148. browser to update your working copy to a particular revision, run your build,
  2149. and then use the same revision when creating the tag.
  2150. You might have noticed that creating a tag and creating a branch both create
  2151. a copy of the files within the repository. This means that, in theory at least,
  2152. you could commit changes to a tag. A tag that has changed wouldn’t be
  2153. much use for identifying which files went into a build, so by convention tags
  2154. are read-only. Developers should never commit changes to a tag, and this
  2155. can be enforced by using a hook script in your repository. Task 42, Using
  2156. Repository Hooks, on page 122 includes an example of how to make your
  2157. tags directories read-only.
  2158. Report erratum
  2159. T AGGING A R ELEASE 87
  2160. Create a release tag from a working copy.
  2161. prompt> cd work/mbench-1.0
  2162. mbench-1.0> svn update
  2163. mbench-1.0> svn copy . \
  2164. http://svn.mycompany.com/mbench/tags/REL_1.0.0 \
  2165. -m "Create R1.0.0 tag"
  2166. Create a release tag using Tortoise.
  2167. Right-click the base directory of your working copy, and choose
  2168. TortoiseSVN > Branch/tag....
  2169. Click the ... button, and use the repo browser to navigate to your project’s
  2170. tags directory. Click OK, and then edit the URL so that it ends with the
  2171. desired tag name, for example tags/REL_1.0.0 .
  2172. Pick which revision you’d like to create the tag from, usually either from a
  2173. specific revision or from your working copy.
  2174. Enter a log message, and click OK to create the tag.
  2175. Create a release tag using Cornerstone.
  2176. Select your repository from the repository source list. Use the repository
  2177. browser to find your release branch. Opt+drag the branch folder to the tags
  2178. folder (the cursor will change to a green + icon to indicate the copy), and
  2179. then release the mouse button.
  2180. Enter a name for the new tag such as REL_1.0.0 . Click Copy, write a short log
  2181. message, and then click Continue to create the tag.
  2182. Related Tasks
  2183. • Task 7, Checking Out a Working Copy, on page 32
  2184. • Task 24, Creating a Branch, on page 78
  2185. Report erratum
  2186. Part VI
  2187. File Locking
  2188. F ILE L OCKING 89
  2189. Subversion enables a team to collaborate on a project by sharing
  2190. their files in the central repository. Everyone on the team is allowed
  2191. to edit any file in their working copy, and if two people edit the
  2192. same file at the same time, Subversion helps you merge the two
  2193. edits later. This is effectively an optimistic locking scheme. Subver-
  2194. sion knows that most of the time two people won’t be editing the
  2195. same file, so it allows things to proceed and provides tools to fix the
  2196. occasional collision when it occurs.
  2197. If you’re coming from a different version control tool, you might be
  2198. used to pessimistic locking. This is a scheme where if you want to
  2199. change a file, you first have to lock the file for editing. Once you are
  2200. done making changes, you can commit the changes and release
  2201. the lock. Pessimistic locking avoids the need to merge two people’s
  2202. edits but at a huge cost—only one person can work on a file at any
  2203. particular time. For a development team, this is a disaster. The team
  2204. can spend all day negotiating with each other about who is going
  2205. to lock a file and asking “Are you done yet?” It can be particularly
  2206. grating when someone locks a file and then goes home early—the
  2207. rest of the team is stalled until they get back.
  2208. Subversion’s “copy, modify, merge” scheme allows development to
  2209. flow more naturally, and its merge tools will usually automatically
  2210. merge sets of changes. Merging works great for text-based files—
  2211. source code, XML, SQL, and so on—but it won’t work at all for binary
  2212. files such as spreadsheets, word processing documents, pictures,
  2213. and movies. For these kinds of files, you might want to use pessimistic
  2214. locking to avoid merges.
  2215. Subversion’s file locking features allow you to specify that certain
  2216. files should be locked before they are edited. Subversion will check
  2217. them out as read-only in the working copy. Most good editing tools
  2218. will notice that a file is read-only, prompting the user to obtain a
  2219. lock on the file before doing their work. The user can make edits
  2220. to the file and then commit their changes, which also releases the
  2221. lock. Subversion provides some features so that authorized users can
  2222. break existing locks, which helps get around the “Joe locked a file
  2223. and went on vacation” problem.
  2224. Covered in this part:
  2225. • Instructing Subversion to enforce file locking for a particular file
  2226. is covered in Task 29, Enabling File Locking, on page 92.
  2227. Report erratum
  2228. F ILE L OCKING 90
  2229. • To make changes to a file where locking is enabled, you first
  2230. need to lock the file for your use. Task 30, Obtaining a Lock, on
  2231. page 94 shows you how to do this.
  2232. • Task 31, Releasing a Lock, on page 96 discusses how and
  2233. when you should relinquish a lock.
  2234. • In some circumstances, you’ll need to unlock a file that some-
  2235. one else has already locked. Task 32, Breaking Someone Else’s
  2236. Lock, on page 98 shows you how to do this and discusses
  2237. when it’s appropriate to do so.
  2238. Let’s start by enabling file locking for specific files.
  2239. Report erratum
  2240. F ILE L OCKING 91
  2241. Report erratum
  2242. E NABLING F ILE L OCKING 92
  2243. 29 Enabling File Locking
  2244. Subversion file locking is supported on all files within the repository, so a
  2245. user can in theory lock a file at any time. When someone else tries to commit
  2246. a change to the locked file, Subversion will reject the change because the file
  2247. is locked. This isn’t very useful, though, because someone could have done a
  2248. bunch of work that they now need to throw away because someone else has
  2249. locked the file. A much better solution would be to stop a user from editing a
  2250. file unless they have a lock on it in the first place.
  2251. Subversion’s advisory locking is enabled by setting the special
  2252. svn:needs-lock property on a file. It doesn’t matter what value the property
  2253. is set to; if the property is present, the file has locking enabled. Most teams
  2254. set svn:needs-lock to something simple like * or yes .
  2255. Once you have set the property on any files that need locking, you need to
  2256. commit the changes to the repository. After that point, anyone updating a
  2257. working copy will find those files marked read-only on their computer. If a
  2258. team member doesn’t update their working copy for a while, they won’t
  2259. know about the new locking requirement on the files. For this reason, it’s a
  2260. good idea to enable file locking as soon as you add a nonmergeable file to
  2261. the repository.
  2262. There is nothing forcing you to enable locking on all nonmergeable files in
  2263. your repository. You might decide that small website graphics used primarily
  2264. by your development team change so infrequently that it’s not worth locking
  2265. them. A spreadsheet containing critical reference data might be changed
  2266. daily and be a much better candidate for locking. In general, try to keep file
  2267. locking to a minimum. Locking imposes an overhead every time anyone
  2268. wants to edit a file and is worth doing only if your team is regularly wasting
  2269. effort on unmergeable changes.
  2270. To disable file locking on a particular file, just remove the svn:needs-lock
  2271. property by using the svn propdel command. If you’re using Tortoise,
  2272. choose TortoiseSVN > Properties, and delete the property. If you’re using
  2273. Cornerstone, set Needs Lock back to No inside the file Inspector panel.
  2274. Report erratum
  2275. E NABLING F ILE L OCKING 93
  2276. Mark a file that needs locking.
  2277. mbench> svn propset svn:needs-lock yes docs/benchmarks.xlsx
  2278. mbench> svn commit -m "Spreadsheet requires a lock before editing"
  2279. Mark a file that needs locking using Tortoise.
  2280. Using Windows Explorer, right-click the file, and choose TortoiseSVN >
  2281. Properties.
  2282. Click the New... button, and then use the Property name drop-down to
  2283. choose svn:needs-lock . Type any text you like into the property value,
  2284. usually something like yes or true is best.
  2285. Click OK twice to save your changes to the file’s properties, and then
  2286. commit your changes to save the new property to the repository.
  2287. Mark a file that needs locking using Cornerstone.
  2288. Select your project from the working copy sources list, and then expand the
  2289. working copy browser until you find the file you want to lock.
  2290. Select the file, and click the Inspector icon on the Cornerstone toolbar. The
  2291. Inspector panel will open on the right side of the Cornerstone window.
  2292. Select the Properties button within the Inspector panel, and set the Needs
  2293. Lock drop-down to yes. Click Save Changes, and then press the Commit
  2294. button on the toolbar to save your changes to the repository.
  2295. Related Tasks
  2296. • Task 30, Obtaining a Lock, on the next page
  2297. • Task 31, Releasing a Lock, on page 96
  2298. • Task 32, Breaking Someone Else’s Lock, on page 98
  2299. Report erratum
  2300. O BTAINING A L OCK 94
  2301. 30 Obtaining a Lock
  2302. Files that are tagged with the special svn:needs-lock property are read-only
  2303. in your working copy. How “read-only” is implemented depends on your
  2304. operating system. On Windows, a file has a read-only attribute that you can
  2305. see by right-clicking and choosing Properties. On a Unix system the file’s
  2306. write flag is disabled, and on a Mac the file will be set to read-only if you
  2307. look in Finder’s Sharing and Permissions section.
  2308. The Subversion client marks files read-only to give you a reminder that you
  2309. should lock them before making changes. Depending on what software you
  2310. use to edit the files, you may or may not get some kind of a prompt or
  2311. warning indicating that the files are read-only. For example, using Paint on
  2312. Windows to edit a graphics file, you’ll be told the file is read-only only when
  2313. you try to save it. Using Microsoft Excel to open a spreadsheet will put
  2314. [Read-Only] in the window title to indicate the file is read-only but will still
  2315. let you edit the spreadsheet. If you’re going to use file locking, you should
  2316. make sure that you understand how your editing tool will let you know the
  2317. file is read-only.
  2318. When obtaining a lock, you can include a comment indicating why you’ve
  2319. locked the file. This is useful if you are going to have the file locked for a
  2320. while, because other users can query the repository to see your lock message.
  2321. If no one else has locked the file, your lock operation should succeed. Your
  2322. Subversion client will mark the file read-write in your working copy.
  2323. The lock operation can fail if someone else has already locked the file. In
  2324. this case, your Subversion client will tell you their username so you can go
  2325. ask them when they will be done making their changes and maybe wait for
  2326. them to unlock the file. In some cases, you might need to forcibly break or
  2327. “steal” a lock; see Task 32, Breaking Someone Else’s Lock, on page 98 for
  2328. more information.
  2329. Locking a file will fail if your working copy is out-of-date. The
  2330. command-line client and Tortoise will tell you what’s wrong, with Tortoise
  2331. even offering to update the file for you and try again. Unfortunately,
  2332. Cornerstone will just quietly fail to lock the file; you won’t get a little
  2333. padlock icon indicating a lock. If locking fails, update your working copy
  2334. and then try the lock again.
  2335. Report erratum
  2336. O BTAINING A L OCK 95
  2337. Lock a file for editing.
  2338. docs> svn update
  2339. docs> svn lock benchmarks.xlsx -m "Adding 64-bit results"
  2340. 'benchmarks.xlsx' locked by user 'mike'.
  2341. Lock a file using Tortoise.
  2342. Using Windows Explorer, right-click the file you want to lock, and choose
  2343. “SVN Get lock....”
  2344. Enter a message describing why you are locking the file, and then click OK
  2345. to lock the file.
  2346. Lock several files using Tortoise.
  2347. Using Windows Explorer, right-click the base directory of your working
  2348. copy, and choose “TortoiseSVN > Get lock....”
  2349. Tortoise will display all the files in your working copy, along with a column
  2350. indicating whether the files are marked as needing a lock.
  2351. Check the files you want to lock, enter a message describing why you are
  2352. locking the files, and then click OK to lock the files.
  2353. Lock a file using Cornerstone.
  2354. Using the working copy browser, find the file you want to lock. Files that
  2355. need locks are indicated with a little tag icon just after the revision column in
  2356. the browser.
  2357. Cmd+click the file, and choose Lock.... Provide a message indicating why
  2358. you are locking the file, and then click Lock. A padlock icon will appear,
  2359. signifying that you have locked the file.
  2360. Related Tasks
  2361. • Task 29, Enabling File Locking, on page 92
  2362. • Task 31, Releasing a Lock, on the following page
  2363. • Task 32, Breaking Someone Else’s Lock, on page 98
  2364. Report erratum
  2365. R ELEASING A L OCK 96
  2366. 31 Releasing a Lock
  2367. After locking a file, you might change your mind and decide not to modify
  2368. it. Subversion releases all the locks in a working copy when you commit a
  2369. change, but if you’re not going to check in for a while, it would probably be
  2370. polite to release the lock straightaway so someone else can lock the file if
  2371. they need to do so.
  2372. Subversion will happily let you release a lock even if you have modified the
  2373. locked file. If you later check in changes to the unlocked file, you have
  2374. essentially avoided Subversion’s locking mechanism. This is bad news.
  2375. Someone else could edit the file in the meantime, and your commit could
  2376. force them to redo their work. You should always revert changes to a file
  2377. when you release a lock.
  2378. Report erratum
  2379. R ELEASING A L OCK 97
  2380. Unlock a file.
  2381. docs> svn unlock benchmarks.xlsx
  2382. 'benchmarks.xlsx' unlocked.
  2383. Unlock a file using Tortoise.
  2384. Using Windows Explorer, right-click a locked file, and choose TortoiseSVN
  2385. > Release lock.
  2386. Alternatively, right-click a working copy folder, and choose TortoiseSVN >
  2387. Release lock. Tortoise will display all locked files within that directory.
  2388. Check the files you want to unlock, and then click OK.
  2389. Unlock a file using Cornerstone.
  2390. Using the working copy browser, find the file you want to unlock. Locked
  2391. files are indicated with a padlock icon.
  2392. Cmd+click the file, and choose Unlock.
  2393. Related Tasks
  2394. • Task 29, Enabling File Locking, on page 92
  2395. • Task 30, Obtaining a Lock, on page 94
  2396. • Task 32, Breaking Someone Else’s Lock, on the following page
  2397. Report erratum
  2398. B REAKING S OMEONE E LSE ’ S L OCK 98
  2399. 32 Breaking Someone Else’s Lock
  2400. File locking is a consensual activity; it’s designed to save a team effort
  2401. where more than one person might change an unmergeable file. Sometimes,
  2402. though, someone might not play by the rules. If a team member locks a file
  2403. and goes home for the night (or worse goes on vacation!), then no one else is
  2404. able to lock and edit the file. Subversion allows us to forcibly break a lock or
  2405. more commonly to steal a lock from someone else.
  2406. Stealing a lock is usually preferred, because the Subversion server will
  2407. unlock the file and relock it for a different user all in one atomic operation. If
  2408. instead we unlock the file and then try to relock it, there’s a small chance that
  2409. another user can get in first and lock the file ahead of us. Once the file has
  2410. been relocked or the lock stolen, the person with the new lock can continue
  2411. as usual.
  2412. If you are the unfortunate user who went home for the night and had their
  2413. lock stolen, things aren’t so great. The Subversion client still sees a locked
  2414. file in the working copy, but the lock is no longer valid. In Subversion terms,
  2415. the lock is defunct. If you try to commit a change using the defunct lock,
  2416. Subversion will refuse, and you’ll have no choice but to revert your changes,
  2417. lock the file again, and make the changes again.
  2418. The Subversion client notices defunct locks any time a working copy is
  2419. updated from the repository, so it’s good practice to update frequently. It
  2420. would also be polite, should you break someone else’s lock, to email them to
  2421. let them know.
  2422. By default, Subversion allows any user to break or steal a lock. If you want
  2423. to restrict this ability, Subversion’s pre-lock and pre-unlock hook scripts
  2424. can allow or prevent lock and unlock operations. The post-lock and
  2425. post-unlock hook scripts can be used to perform additional processing such
  2426. as sending an email when a lock is broken. Task 42, Using Repository
  2427. Hooks, on page 122 covers hooks in more detail.
  2428. Report erratum
  2429. B REAKING S OMEONE E LSE ’ S L OCK 99
  2430. Forcibly unlock a file.
  2431. docs> svn lock benchmarks.xlsx
  2432. svn: warning: Path '/trunk/docs/benchmarks.xlsx' is already locked
  2433. by user 'mmason' in filesystem '/home/svn/mbench/db'
  2434. docs> svn unlock --force benchmarks.xlsx
  2435. 'benchmarks.xlsx' unlocked.
  2436. Steal a lock.
  2437. docs> svn lock benchmarks.xlsx
  2438. svn: warning: Path '/trunk/docs/benchmarks.xlsx' is already locked
  2439. by user 'mmason' in filesystem '/home/svn/mbench/db'
  2440. docs> svn lock --force benchmarks.xlsx
  2441. 'benchmarks.xlsx' locked by user 'mike'.
  2442. Steal a lock using Tortoise.
  2443. Using Windows Explorer, navigate to the file for which you want to steal the
  2444. lock, right-click, and choose “SVN Get lock....”
  2445. Enter an optional message describing why you are locking the file, and then
  2446. check the “Steal the locks” option. Click OK to steal the locks.
  2447. Steal a lock using Cornerstone.
  2448. In the Cornerstone menu, select the View menu, and ensure Show
  2449. Repository Status is enabled. This instructs Cornerstone to query the
  2450. repository looking for locks; files that are locked by someone else will be
  2451. indicated with a gray padlock icon.
  2452. Select your project from the working copy sources list, and then expand the
  2453. working copy browser to find the file for which you want to steal the lock.
  2454. Cmd+click the file, and choose Lock... to attempt to lock the file.
  2455. Related Tasks
  2456. • Task 29, Enabling File Locking, on page 92
  2457. • Task 30, Obtaining a Lock, on page 94
  2458. • Task 31, Releasing a Lock, on page 96
  2459. Report erratum
  2460. Part VII
  2461. Setting Up a Server
  2462. S ETTING U P A S ERVER 101
  2463. Subversion stores your files inside a repository, which itself is just a col-
  2464. lection of files on a disk somewhere. Subversion allows you to create
  2465. an arbitrary directory structure inside the repository to organize your
  2466. projects and files. Usually a repository will contain multiple projects,
  2467. each inside their own directory. The top level of a repository like
  2468. this will contain a directory for each project, and then each of the
  2469. project directories will contain the usual trunk , tags , and branches
  2470. directories. Alternatively, you might have a repository dedicated to
  2471. each project. In this type of repository, the trunk , tags , and branches
  2472. directories appear at the top level of the repository.
  2473. This might sound like a complicated choice, but don’t worry. Unless
  2474. you have a specific reason to separate projects into their own repos-
  2475. itories, just set up a single repository and host multiple projects inside
  2476. it. Once the repository is exposed using a URL, a user actually can’t
  2477. tell which hosting style is in use—this really is just an administrative
  2478. decision.
  2479. To make a repository useful for a development team, we need to
  2480. add a Subversion server so the files are available over a network. A
  2481. variety of different servers are available for Subversion; you need to
  2482. pick one that matches your needs.
  2483. svnserve is the simplest and easiest-to-use server. It’s very lightweight
  2484. and speaks a custom svn protocol. Unfortunately, svnserve doesn’t
  2485. provide encryption so is usually limited to LAN use where you have
  2486. control of all the network traffic.
  2487. Secure Shell can be used to protect svnserve connections by adding
  2488. a secure, encrypted SSH connection. This provides bulletproof secu-
  2489. rity but at quite a high administrative cost since each Subversion
  2490. user needs to have a corresponding Unix user account.
  2491. The Apache web server can be used to allow Subversion repository
  2492. access using http and https connections, just like those used by a
  2493. web browser. This is by far the most popular way to put a Subversion
  2494. repository online. Using an SSL certificate, you get the same secu-
  2495. rity used by websites to protect credit card information. You can
  2496. also integrate with an existing user credentials store such as LDAP
  2497. or even Active Directory. Using Apache makes it easy to serve mul-
  2498. tiple repositories from a single machine, and it allows you to apply
  2499. fine-grained security to each repository, right down to the directory
  2500. level.
  2501. Report erratum
  2502. S ETTING U P A S ERVER 102
  2503. This part of the book focuses on using Apache as a Subversion server
  2504. on the Ubuntu Linux operating system, but we also show how to run
  2505. a server on Windows using svnserve . We also include some recipes
  2506. for backing up and restoring your repository and some tips on repos-
  2507. itory security.
  2508. Covered in this part:
  2509. • Task 33, Installing Subversion Server, on page 104 shows how
  2510. to install Subversion on Ubuntu Linux.
  2511. • Once you have a Subversion server running, you need to cre-
  2512. ate a repository that will be served up over the network. Task
  2513. 34, Creating a Repository, on page 106 shows how to do this.
  2514. • Task 35, Installing Subversion Server on Windows, on page 108
  2515. covers using Windows as a Subversion server.
  2516. • Not everyone wants to run their own Subversion server. Task
  2517. 36, Using Third-Party Subversion Hosting, on page 110 discusses
  2518. how to use a third-party hosting service.
  2519. • If you have an existing CVS repository, you can convert it to a
  2520. Subversion repository and keep all your history, branches, and
  2521. tags. Task 37, Migrating a CVS Repository, on page 112 covers
  2522. this in detail.
  2523. • Repository backup and subsequent restoration is covered in
  2524. Task 38, Backing Up and Restoring, on page 114.
  2525. • Task 39, Performing Full Weekly Backups, on page 116 and
  2526. Task 40, Performing Incremental Daily Backups, on page 118
  2527. together describe an efficient backup regime.
  2528. • You should never put an unsecured repository online. Task 41,
  2529. Securing a Repository, on page 120 shows how to apply sim-
  2530. ple user- and group-based security to your repository.
  2531. • Task 42, Using Repository Hooks, on page 122 covers how to
  2532. influence Subversion’s revision commit life cycle so you can
  2533. do interesting stuff such as blocking commits or sending post-
  2534. commit emails.
  2535. Let’s start by getting a Subversion server installed.
  2536. Report erratum
  2537. S ETTING U P A S ERVER 103
  2538. Report erratum
  2539. I NSTALLING S UBVERSION S ERVER 104
  2540. 33 Installing Subversion Server
  2541. Apache is by far the most popular method for getting a Subversion
  2542. repository online. Most Linux servers come with Apache preinstalled, and at
  2543. last count Apache runs more than half of all the servers on the Internet. 11
  2544. Using Apache makes your repository available via HTTP, and you can take
  2545. advantage of all of Apache’s other features such as SSL security, LDAP user
  2546. authentication, and so on.
  2547. The Apache Subversion modules add extra directives that you can use in
  2548. Apache configuration files. If you’re hosting multiple websites on a single
  2549. server, you can add a Subversion repository to a particular site by
  2550. configuring its virtual host rather than using the global dav_svn.conf .
  2551. In this example, we’re using the SVNParentPath directive so that every
  2552. directory underneath /home/svn will be assumed to contain a repository. If
  2553. you need a new repository, simply create one; you don’t need to reconfigure
  2554. Apache. If you instead use the SVNPath directive, you will host a single
  2555. repository. Sometimes it’s better to use just a single repository because it’s
  2556. less hassle to administer, back up, and so on. Even a single repository can
  2557. host multiple projects, so both approaches can work.
  2558. If you use the configuration described here, a repository created in
  2559. /home/svn/myrepo will be available on your Apache server at http://
  2560. myserver.com/svn/myrepo.
  2561. When using htpasswd , you only need to use the -c argument when you first
  2562. create the file. After that, drop the argument to add new users to an existing
  2563. file. This isn’t particularly intuitive, but htpasswd has been around a lot
  2564. longer than Subversion and isn’t quite as friendly. If you are using virtual
  2565. hosts with Apache, you can use a different password file for each site. If
  2566. you’re using SVNPath , you can have a different password file for each
  2567. repository.
  2568. Once you complete the configuration, you need to restart Apache. You can
  2569. then create repositories, as described in Task 34, Creating a Repository, on
  2570. page 106.
  2571. 11. http://news.netcraft.com/archives/2010/06/16/june-2010-web-server-survey.html
  2572. Report erratum
  2573. I NSTALLING S UBVERSION S ERVER 105
  2574. Install Apache and the Subversion modules.
  2575. prompt> sudo apt-get update
  2576. prompt> sudo apt-get install apache2 libapache2-svn
  2577. You can also use the Synaptic package manager to install the apache2 and
  2578. libapache2-svn packages and any dependencies.
  2579. Create a repositories directory.
  2580. prompt> sudo mkdir /home/svn
  2581. prompt> sudo chown www-data /home/svn
  2582. Configure Apache to serve your Subversion repositories.
  2583. Edit /etc/apache2/mods-enabled/dav_svn.conf to configure
  2584. Subversion. Your configuration should look like this:
  2585. <Location /svn>
  2586. DAV svn
  2587. SVNParentPath /home/svn
  2588. AuthType Basic
  2589. AuthName "Subversion Repository"
  2590. AuthUserFile /home/svn/passwd
  2591. </Location>
  2592. Create a Subversion password file.
  2593. prompt> sudo htpasswd -c /home/svn/passwd fred
  2594. prompt> sudo htpasswd /home/svn/passwd barney
  2595. prompt> sudo chown www-data /home/svn/passwd
  2596. Restart Apache to apply your changes.
  2597. prompt> sudo service apache2 restart
  2598. Related Tasks
  2599. • Task 35, Installing Subversion Server on Windows, on page 108
  2600. • Task 5, Creating an Empty Project, on page 24
  2601. • Task 36, Using Third-Party Subversion Hosting, on page 110
  2602. Report erratum
  2603. C REATING A R EPOSITORY 106
  2604. 34 Creating a Repository
  2605. Subversion stores files inside a repository, which is simply a directory on the
  2606. server that has been initialized using the svnadmin create command. If you
  2607. are using Apache to host the Subversion server, as described in Task 33,
  2608. Installing Subversion Server, on page 104, you also need to set the
  2609. permissions on the directory so the www-user user can modify and create
  2610. files in the directory.
  2611. If you’re using the SVNParentPath directive, you’re telling Apache that
  2612. within a particular directory on your server, any subdirectory is a Subversion
  2613. repository, and Apache should make each repository available over the
  2614. network. Most often with this style of configuration you’re creating a
  2615. separate repository for each project, in which case you should name the
  2616. directory after the project rather than calling it myrepos .
  2617. If you use the configuration described here, a repository created in
  2618. /home/svn/myproject will be available on your Apache server at http://
  2619. myserver.com/svn/myproject.
  2620. Report erratum
  2621. C REATING A R EPOSITORY 107
  2622. Create a directory for the repository.
  2623. prompt> cd /home/svn
  2624. svn> sudo mkdir myrepos
  2625. Initialize the new repository.
  2626. svn> sudo svnadmin create myrepos
  2627. svn> sudo chown -R www-data myrepos
  2628. Related Tasks
  2629. • Task 33, Installing Subversion Server, on page 104
  2630. • Task 5, Creating an Empty Project, on page 24
  2631. • Task 36, Using Third-Party Subversion Hosting, on page 110
  2632. Report erratum
  2633. I NSTALLING S UBVERSION S ERVER ON W INDOWS 108
  2634. 35 Installing Subversion Server on
  2635. Windows
  2636. CollabNet is the commercial sponsor for the Subversion project and builds a
  2637. number of products using Subversion. They also offer training and support
  2638. services, as well as a number of prebuilt binaries for Subversion. The
  2639. instructions on the facing page allow you to install svnserve for Windows,
  2640. but the CollabNet installer also allows you to install Apache. You might use
  2641. Apache if you need more flexibility or to make a Subversion repository
  2642. available over the Web.
  2643. The CollabNet configuration for svnserve ensures that any directory created
  2644. inside C:\svn_repos is served as a repository. If you want to create multiple
  2645. repositories, just create several directories, and use svnadmin create to
  2646. initialize a repository in each directory.
  2647. Inside the repository Subversion stores configuration files in a conf
  2648. directory. These are plain-text files, and you can edit them with any text
  2649. editor.
  2650. The svnserve.conf file contains settings for access control, password files,
  2651. and path-based access control. The file is well commented; read through and
  2652. uncomment settings to configure svnserve to your liking.
  2653. Once you have configured svnserve , you need to use Control Panel to start
  2654. the service. On Windows XP, you’ll find this under Administrative Tools.
  2655. For Windows Vista onward, you can just search for services. You only need
  2656. to start the service manually once; the service will start automatically the
  2657. next time the computer is rebooted.
  2658. Point a Subversion client at svn://localhost/repos to test that your
  2659. installation has succeeded. If the client connection succeeds, you can start
  2660. creating project directories within the repository, as described in Task 5,
  2661. Creating an Empty Project, on page 24.
  2662. Report erratum
  2663. I NSTALLING S UBVERSION S ERVER ON W INDOWS 109
  2664. Download and install CollabNet Subversion server.
  2665. Visit http://www.open.collab.net/downloads/subversion/, and download the
  2666. Subversion “server and client” for Windows. Double-click the installer to
  2667. start the installation process.
  2668. When the installer asks you to choose components, ensure svnserve is
  2669. selected and Apache is not selected.
  2670. On the svnserve configuration screen, accept the default options. Make sure
  2671. “install as Windows service” is selected, and then click Next a few times to
  2672. complete the installation.
  2673. Create a repository directory, and initialize the repository.
  2674. Click Start > Run..., and type cmd to start a command prompt. Enter the
  2675. following commands:
  2676. C:\users\mmason> cd \svn_repository
  2677. C:\svn_repository> md repos
  2678. C:\svn_repository> svnadmin create repos
  2679. Configure security for your repository.
  2680. Edit C:\svn_repository\repos\conf\svnserve.conf , and uncomment the
  2681. password-db line to enable a password database. Save the file.
  2682. Edit C:\svn_repository\repos\conf\passwd . Enter users and passwords
  2683. in the file as follows:
  2684. [users]
  2685. mike = s3cr3t
  2686. jim = b4n4n4
  2687. Start svnserve using Windows Control Panel.
  2688. Scroll down until you find CollabNet Subversion svnserve . Select it, and
  2689. then click the green “play” icon on the toolbar.
  2690. Related Tasks
  2691. • Task 5, Creating an Empty Project, on page 24
  2692. • Task 36, Using Third-Party Subversion Hosting, on the next page
  2693. Report erratum
  2694. U SING T HIRD -P ARTY S UBVERSION H OSTING 110
  2695. 36 Using Third-Party Subversion Hosting
  2696. If you don’t want to run and maintain your own Subversion server, there are
  2697. a number of third-party hosting services that will provide a server for you.
  2698. If you are developing open source software, SourceForge 12 will host your
  2699. Subversion repository for free. Sign up on the website, and create your
  2700. project. SourceForge will create a repository for your project, and you can
  2701. begin using it. Remember to create the trunk , tags , and branches
  2702. directories before starting work.
  2703. Commercial hosting is available if you want to keep your source code
  2704. private. Many hosting providers are available, and they often include
  2705. additional features such as bug trackers, wikis, and mailing lists. You can
  2706. usually try these services for free, either for a certain trial period or with
  2707. restrictions on the size of your repository or the number of developers. A
  2708. free trial is a good way to check out a particular service provider.
  2709. Unfuddle 13 is one such provider, offering free trials with one project and a
  2710. repository up to 200MB. After you’ve created your account, click the
  2711. Repositories tab and then New Repository. As with SourceForge, remember
  2712. to create trunk , tags , and branches directories before starting work.
  2713. Beanstalk 14 is another commercial hosting service that offers both
  2714. Subversion and Git repositories. Their free account allows you to create one
  2715. repository with up to three users and is limited to 100MB of storage.
  2716. 12. http://www.sourceforge.net/
  2717. 13. http://unfuddle.com/
  2718. 14. http://beanstalkapp.com/
  2719. Report erratum
  2720. U SING T HIRD -P ARTY S UBVERSION H OSTING 111
  2721. Create a project on SourceForge.
  2722. Visit SourceForge, and create an account for yourself. Log in, and create a
  2723. new project. Once active, you can check out from your project’s new
  2724. Subversion repository:
  2725. prompt> svn mkdir
  2726. https://myproject.svn.sourceforge.net/svnroot/myproject/trunk
  2727. prompt> svn mkdir
  2728. https://myproject.svn.sourceforge.net/svnroot/myproject/tags
  2729. prompt> svn mkdir
  2730. https://myproject.svn.sourceforge.net/svnroot/myproject/branches
  2731. prompt> cd /home/work
  2732. work> svn checkout
  2733. https://myproject.svn.sourceforge.net/svnroot/myproject/trunk
  2734. Create a project using Unfuddle.
  2735. Visit Unfuddle, and create an account for yourself. Log in, and create a new
  2736. trial project. You can check out from your project’s new Subversion
  2737. repository:
  2738. prompt> svn mkdir http://myuser.unfuddle.com/svn/myuser_myproject/trunk
  2739. prompt> svn mkdir http://myuser.unfuddle.com/svn/myuser_myproject/tags
  2740. prompt> svn mkdir http://myuser.unfuddle.com/svn/myuser_myproject/branches
  2741. prompt> cd /home/work
  2742. work> svn checkout http://myuser.unfuddle.com/svn/myuser_myproject/trunk
  2743. Create a project on Beanstalk.
  2744. Visit Beanstalk, and choose Pricing & Signup and then Free Account. After
  2745. signing up for an account, you should create a new Subversion repository.
  2746. Use the default settings, which on Beanstalk will automatically create trunk ,
  2747. tags , and branches directories for you.
  2748. The trunk for your new project will be available at http://user.svn.
  2749. beanstalkapp.com/myproject/trunk/.
  2750. Related Tasks
  2751. • Task 5, Creating an Empty Project, on page 24
  2752. Report erratum
  2753. M IGRATING A CVS R EPOSITORY 112
  2754. 37 Migrating a CVS Repository
  2755. If you are using CVS for version control and want to upgrade to Subversion,
  2756. you can do so quite easily. Subversion is designed to be a drop-in
  2757. replacement for CVS; it will run on the same hardware and has a user
  2758. interface similar to CVS. Subversion includes a tool called cvs2svn that
  2759. allows you to convert an existing CVS repository to a Subversion repository.
  2760. The tool preserves all your files, tags, branches, and history, making the
  2761. upgrade pretty seamless.
  2762. Converting from a CVS repository works best on a real Unix system, so
  2763. we’ve only included instructions for Ubuntu Linux. If you’re in a real pinch,
  2764. you can also try the conversion using Cygwin 15 on Windows, but we really
  2765. don’t recommend it. Borrow an account on a Unix box if you have to; it’ll
  2766. make the conversion much smoother.
  2767. The first and most important step is to make a copy of your CVS repository.
  2768. Absolutely do not run the conversion against the primary copy of your CVS
  2769. repository. cvs2svn should (in theory) only be reading files from CVS, not
  2770. writing to them, but you can never be too careful with your data. We’ll say it
  2771. again: run cvs2svn on a copy of your CVS repository, not the actual
  2772. repository.
  2773. Converting from CVS will preserve all your history, branches, and tags. If
  2774. you don’t need all of that, you can run a faster conversion by specifying the
  2775. --trunk-only option. Once complete, you will have a Subversion dump file
  2776. containing all your CVS history. Dump files are Subversion’s way of
  2777. backing up a repository; you need to load the dump file into an empty
  2778. Subversion repository in order to see the converted files.
  2779. The --encoding option specifies different ISO file encodings to use when
  2780. trying to convert from the CVS files. The two most common are UTF8 and
  2781. Latin-1. If these don’t work for you, find the correct one from the full Python
  2782. encodings list. 16
  2783. 15. http://www.cygwin.com/
  2784. 16. http://docs.python.org/library/codecs.html#standard-encodings
  2785. Report erratum
  2786. M IGRATING A CVS R EPOSITORY 113
  2787. Install cvs2svn.
  2788. prompt> sudo apt-get update
  2789. prompt> sudo apt-get install cvs2svn
  2790. Create a copy of your CVS repository.
  2791. prompt> mkdir /tmp/cvs-convert
  2792. prompt> cp -r /home/cvs/some-project /tmp/cvs-convert
  2793. Convert your CVS repository to a Subversion dump file.
  2794. prompt> cd /tmp/cvs-convert
  2795. cvs-convert> cvs2svn --dumpfile=some-project.dump
  2796. --encoding=UTF8 --encoding=latin1 some-project/
  2797. Use the dump file to create a new repository.
  2798. prompt> cd /home/svn
  2799. svn> sudo mkdir some-project
  2800. svn> sudo svnadmin create some-project/
  2801. svn> sudo svnadmin load some-project/ \
  2802. < /tmp/cvs-convert/some-project.dump
  2803. Related Tasks
  2804. • Task 5, Creating an Empty Project, on page 24
  2805. Report erratum
  2806. B ACKING U P AND R ESTORING 114
  2807. 38 Backing Up and Restoring
  2808. The development team is relying on their Subversion repository to be a safe
  2809. place to store all their hard work. Anyone who’s worked as a systems
  2810. administrator will know that disks can go bad at any time and that servers
  2811. can get hacked, dropped, magnetized, and even accidentally reinstalled at
  2812. any time. It’s very important to have backups and to test those backups
  2813. regularly.
  2814. The simplest way to create a backup is to use svnadmin dump to create a
  2815. dump file. The dump file will contain the complete history of everything that
  2816. happened to your repository—every file added, every file deleted, and every
  2817. file changed. Subversion can replay this history to re-create the repository if
  2818. anything bad happens to the original. Once you have created a dump file,
  2819. you should store it on a different server.
  2820. Since Subversion 1.2, most repositories are simple collections of files on
  2821. disk rather than something complicated like a database. In theory, if your
  2822. server already has a full disk backup solution configured, your Subversion
  2823. repository is also backed up. However, if someone checks in a change while
  2824. the backup is running, you could end up with an inconsistent backup. To
  2825. avoid this, create a dump file. Even if a check-in occurs while the dump is
  2826. running, you’ll end up with a consistent backup.
  2827. For large repositories, a full dump file could be quite large. You might prefer
  2828. to do an incremental dump every evening and a complete dump at the
  2829. weekend. The --incremental and -r REV arguments tell svnadmin to do an
  2830. incremental dump starting at a particular revision. With a little bit of Unix
  2831. scripting, you can create a backup regimen for your repository that does
  2832. daily incremental backups and weekly complete backups. Task 39,
  2833. Performing Full Weekly Backups, on page 116 and Task 40, Performing
  2834. Incremental Daily Backups, on page 118 show how to accomplish this.
  2835. In addition to backing up your repository, it’s a good idea to make sure it’s
  2836. not become corrupted over time. The svnadmin verify command will scan a
  2837. repository and check whether everything is OK. This takes quite a while to
  2838. run for larger repositories and will slow down the server, so you should run a
  2839. verify only during off-peak hours.
  2840. Report erratum
  2841. B ACKING U P AND R ESTORING 115
  2842. Create a Subversion dump file for your repository.
  2843. prompt> svnadmin dump /home/svn/mbench > mbench.dump
  2844. Load the dump file to restore to a new repository.
  2845. prompt> svnadmin load /home/svn/mbench2 < mbench.dump
  2846. Verify the integrity of a repository.
  2847. prompt> svnadmin verify /home/svn/mbench
  2848. Related Tasks
  2849. • Task 34, Creating a Repository, on page 106
  2850. • Task 36, Using Third-Party Subversion Hosting, on page 110
  2851. Report erratum
  2852. P ERFORMING F ULL W EEKLY B ACKUPS 116
  2853. 39 Performing Full Weekly Backups
  2854. The Subversion administrative dump and load commands are an excellent
  2855. base upon which to build backup scripts for your repository. Depending on
  2856. how large your repository is and the frequency with which you want to run
  2857. backups, you might not always want to wait for a full backup to complete.
  2858. This script and the script in the next task form a basic full and incremental
  2859. backup regimen for your repository.
  2860. Most users will be comfortable running a full backup once a week and an
  2861. incremental backup every day. If you are more paranoid, you could run the
  2862. full backup every night and the incremental backup every hour. Some
  2863. administrators even use a post-commit hook script to run an incremental
  2864. backup after every check-in, but this is probably overkill most of the time.
  2865. full-backup.pl uses the svnadmin dump command to run a complete
  2866. backup of the repository. The script then uses the svnlook command to
  2867. determine the youngest (most recent) revision in the repository. This
  2868. revision number is saved into a last-backed-up file, which the incremental
  2869. backup script uses. Knowing what we have already backed up in the full
  2870. backup allows the incremental backup to run much faster.
  2871. The backup script also compresses the backup using gzip. Once the backup
  2872. is finished, remember to copy the backup files to a secure location such as a
  2873. network drive or tape drive. Simply having some compressed dump files on
  2874. the same disk as your Subversion repository isn’t providing much safety!
  2875. Report erratum
  2876. P ERFORMING F ULL W EEKLY B ACKUPS 117
  2877. Create a full backup script for your repository.
  2878. Download full-backup.pl
  2879. #!/usr/bin/env perl
  2880. #
  2881. # Perform a full backup of a Subversion repository.
  2882. $svn_repos = "/home/svn/repos";
  2883. $backups_dir = "/home/svn/backups";
  2884. $backup_file = "full-backup." . `date +%Y%m%d%H%M%S`;
  2885. $youngest = `svnlook youngest $svn_repos`;
  2886. chomp $youngest;
  2887. print "Backing upto revision $youngest\n";
  2888. $svnadmin_cmd = "svnadmin dump --revision 0:$youngest " .
  2889. "$svn_repos > $backups_dir/$backup_file";
  2890. `$svnadmin_cmd`;
  2891. print "Compressing dump file...\n";
  2892. print `gzip -9 $backups_dir/$backup_file`;
  2893. open(LOG, ">$backups_dir/last_backed_up");
  2894. print LOG $youngest;
  2895. close LOG;
  2896. Run the script to perform a full backup.
  2897. prompt> full-backup.pl
  2898. Backing up to revision 17
  2899. * Dumped revision 0.
  2900. * Dumped revision 1.
  2901. * Dumped revision 2.
  2902. : : :
  2903. * Dumped revision 17.
  2904. Compressing dump file...
  2905. Related Tasks
  2906. • Task 38, Backing Up and Restoring, on page 114
  2907. • Task 40, Performing Incremental Daily Backups, on the next page
  2908. • Task 42, Using Repository Hooks, on page 122
  2909. Report erratum
  2910. P ERFORMING I NCREMENTAL D AILY B ACKUPS 118
  2911. 40 Performing Incremental Daily
  2912. Backups
  2913. Building on the full backup script in the previous task, daily-backup.pl
  2914. performs an incremental backup. You should run this incremental backup
  2915. script at least daily, but you might run it more often if you’re extra paranoid.
  2916. The script loads the last_backed_up file created by the full backup, checks
  2917. to see whether there are any new revisions in the repository, and backs up
  2918. just those new revisions. If there have been no check-ins since the last full
  2919. backup, the script exits early and doesn’t create an incremental backup. The
  2920. script saves the last-backed-up revision back into last_backed_up so that
  2921. future incremental backups work correctly too.
  2922. Running the script produces output such as the following:
  2923. prompt> daily-backup.pl
  2924. Backing up revisions 18 to 18...
  2925. * Dumped revision 18.
  2926. Compressing dump file...
  2927. Once your backup regimen has been running for a while, you’ll have weekly
  2928. full backups alongside daily incremental backups. Your
  2929. /home/svn/backups directory might look like this:
  2930. prompt> ls -t /home/svn/backups
  2931. incremental-backup.20100517010008.gz
  2932. full-backup.20100516010011.gz
  2933. incremental-backup.20100515010002.gz
  2934. incremental-backup.20100514010004.gz
  2935. incremental-backup.20100513010011.gz
  2936. incremental-backup.20100512010008.gz
  2937. incremental-backup.20100511010003.gz
  2938. incremental-backup.20100510010011.gz
  2939. full-backup.20100509010014.gz
  2940. If disaster strikes and you need to restore from a backup, first use svnadmin
  2941. load to load the most recent full backup into a new repository. Then load
  2942. each subsequent incremental backup into the same repository. In the
  2943. example shown earlier, you should load the full backup from May 16 and
  2944. then load the incremental backup from May 17. All of the other backup files
  2945. have been superceded by the most recent full backup and subsequent
  2946. incremental backups.
  2947. Report erratum
  2948. P ERFORMING I NCREMENTAL D AILY B ACKUPS 119
  2949. Create an incremental backup script for your repository.
  2950. Download daily-backup.pl
  2951. #!/usr/bin/env perl
  2952. #
  2953. # Perform an incremental backup of a Subversion repository.
  2954. $svn_repos = "/home/svn/repos";
  2955. $backups_dir = "/home/svn/backups";
  2956. $backup_file = "incremental-backup." . `date +%Y%m%d%H%M%S`;
  2957. open(IN, "$backups_dir/last_backed_up");
  2958. $previous_youngest = <IN>;
  2959. chomp $previous_youngest;
  2960. close IN;
  2961. $youngest = `svnlook youngest $svn_repos`;
  2962. chomp $youngest;
  2963. if($youngest eq $previous_youngest) {
  2964. print "No new revisions to back up.\n";
  2965. exit 0;
  2966. }
  2967. # We need to backup from the last backed up revision
  2968. # to the latest (youngest) revision in the repository
  2969. $first_rev = $previous_youngest + 1;
  2970. $last_rev = $youngest;
  2971. print "Backing uprevisions $first_rev to $last_rev...\n";
  2972. $svnadmin_cmd = "svnadmin dump --incremental " .
  2973. "--revision $first_rev:$last_rev " .
  2974. "$svn_repos > $backups_dir/$backup_file";
  2975. `$svnadmin_cmd`;
  2976. print "Compressing dump file...\n";
  2977. print `gzip -9 $backups_dir/$backup_file`;
  2978. open(LOG, ">$backups_dir/last_backed_up");
  2979. print LOG $last_rev;
  2980. close LOG;
  2981. Related Tasks
  2982. • Task 38, Backing Up and Restoring, on page 114
  2983. • Task 39, Performing Full Weekly Backups, on page 116
  2984. Report erratum
  2985. S ECURING A R EPOSITORY 120
  2986. 41 Securing a Repository
  2987. Most organizations should use a single Subversion repository for all their
  2988. projects. You should consider using multiple repositories only if you have
  2989. run into a roadblock using a single repository, such as needing to support
  2990. hundreds of users and not having enough room on a single server. Given that
  2991. a typical Subversion repository supports multiple projects, you’ll often want
  2992. to limit access to each project to certain groups of users. If you’re hosting
  2993. your Subversion repository using Apache or svnserve , Subversion’s
  2994. path-based security can solve the problem.
  2995. Path-based security is enabled in Apache by including the
  2996. AuthzSVNAccessFile directive for your repository. If you’re using svnserve ,
  2997. you need to edit svnserve.conf and set the authz-db configuration property.
  2998. Either way, the configuration file for path-based security has the same
  2999. format.
  3000. The [ groups ] section allows you to define groups of users. In our example,
  3001. we have defined administrators, developers, and a web development team.
  3002. Each of the subsequent configuration sections defines a path within the
  3003. repository and the security we want to apply to that path. Users are specified
  3004. by name or group. You can refer to all authenticated users with the special
  3005. token $authenticated and to all anonymous users with $anonymous .
  3006. Security for each user or group can be r for read-only access, rw for
  3007. read-write access, or blank for no access.
  3008. In our example, we have security definitions for three paths in the repository.
  3009. The root of the repository is writable by the administrators so they can create
  3010. new projects, readable by all others users, and not accessible for anonymous
  3011. users. The /mbench project directory is read-write for administrators and
  3012. developers and read-only for everyone else. The /website_project directory
  3013. is read-write for the web development team and not accessible for everyone
  3014. else. Presumably the new corporate website is super-secret and needs to be
  3015. kept locked down!
  3016. Once you have configured path-based security, you need to restart Apache
  3017. for the new settings to take effect. Once Apache has restarted, you can edit
  3018. dav_svn.authz to make security changes, and Subversion will notice
  3019. modifications to the file and reconfigure security on the fly.
  3020. Report erratum
  3021. S ECURING A R EPOSITORY 121
  3022. Enable Apache’s path-based security module.
  3023. Edit /etc/apache2/mods-enabled/dav_svn.conf , and ensure that for
  3024. your repository the following Apache directive is uncommented:
  3025. AuthzSVNAccessFile /etc/apache2/dav_svn.authz
  3026. Configure path-based security for your repository.
  3027. Create /etc/apache2/dav_svn.authz , and edit it to reflect the security
  3028. configuration for your repository and users:
  3029. [groups]
  3030. admins = mike, ian
  3031. developers = mike, ian, ben
  3032. web_team = ben, natalie
  3033. [/]
  3034. admins = rw
  3035. * = r
  3036. [/mbench]
  3037. admins = rw
  3038. developers = rw
  3039. * = r
  3040. [/website_project]
  3041. web_team = rw
  3042. * =
  3043. Restart Apache to enable the new configuration.
  3044. prompt> sudo /etc/init.d/apache2 restart
  3045. Related Tasks
  3046. • Task 33, Installing Subversion Server, on page 104
  3047. • Task 34, Creating a Repository, on page 106
  3048. • Task 5, Creating an Empty Project, on page 24
  3049. Report erratum
  3050. U SING R EPOSITORY H OOKS 122
  3051. 42 Using Repository Hooks
  3052. Subversion exposes a number of integration points into its transaction life
  3053. cycle.Theseintegrationpointsarecalledhooks,andtheycorrespondtoevents
  3054. in the repository such as committing a change, locking and unlocking files,
  3055. and altering revision properties. When Subversion gets to each point in its
  3056. transactionlifecycle,itwillcheckforandexecutetheappropriatehookscript.
  3057. Hook scripts have access to the in-flight transaction as it is being processed
  3058. and are passed different command-line arguments depending on which hook
  3059. script is executing. For example, the pre-commit hook is told the repository
  3060. path and the transaction ID for the currently executing commit. If a hook
  3061. script returns a nonzero exit code, Subversion will abort the transaction and
  3062. return the script’s standard error output as a message to the user.
  3063. Your repository’s hooks directory contains example scripts for each hook,
  3064. with a .tmpl extension. To use one of the example scripts, rename it, and
  3065. drop the .tmpl extension. Windows hook scripts should have a .bat or .exe
  3066. extension. The example hook scripts are an excellent resource for learning
  3067. what each script should do—they are well commented and explain a lot
  3068. about what’s going on when the script is executed.
  3069. The following hook scripts are used most often:
  3070. pre-commit Executed before a change is committed to the repository.
  3071. Often used to check log messages, to format files, and to perform
  3072. custom security or policy checking.
  3073. pre-lock Executed before a lock is granted. Usually used to enforce rules
  3074. around which users are allowed to lock files.
  3075. pre-unlock Executed before an unlock operation completes. Usually used
  3076. to enforce rules around which users are allowed to steal locks.
  3077. post-commit Executed once the commit has completed. Often used to
  3078. inform users about a completed commit, for example by sending an
  3079. email to the team.
  3080. Although hook scripts have access to the transaction, they absolutely must
  3081. not alter the content of the transaction. Some teams want to ensure all their
  3082. source code is formatted to a particular standard and try to use a hook script
  3083. to do the formatting. The problem with this approach is that the server has
  3084. no way to inform the client that their files were modified during the commit,
  3085. leading to out-of-sync working copies. The best choice in this case is to use
  3086. a pre-commit hook to reject code that violates your standard, forcing a
  3087. developer to reformat before they commit.
  3088. Report erratum
  3089. U SING R EPOSITORY H OOKS 123
  3090. Use a pre-commit hook to validate log messages.
  3091. Inside your repository hooks directory, create a file pre-commit with the
  3092. following content:
  3093. #!/usr/bin/perl
  3094. $repos=$ARGV[0];
  3095. $txn=$ARGV[1];
  3096. $svnlook = "/usr/bin/svnlook";
  3097. $wc = "/usr/bin/wc";
  3098. $log_words = `$svnlook log -t "$txn" "$repos" | $wc -w`;
  3099. if($log_words < 1) {
  3100. print STDERR "You must enter a log message.\n";
  3101. exit 1;
  3102. }
  3103. exit 0;
  3104. Make sure the script is executable.
  3105. hooks> chmod +x pre-commit
  3106. Use a pre-commit hook to ensure tags are read-only.
  3107. Create a pre-commit script with the following content:
  3108. #!/usr/bin/perl
  3109. $repos=$ARGV[0];
  3110. $txn=$ARGV[1];
  3111. $svnlook = "/usr/bin/svnlook";
  3112. @log_lines = `$svnlook changed -t "$txn" "$repos"`;
  3113. foreach $line (@log_lines) {
  3114. if($line =~ /^U. * \/tags\//) {
  3115. print STDERR "You cannot modify a tagged file.\n";
  3116. exit 1;
  3117. }
  3118. }
  3119. hooks> chmod +x pre-commit
  3120. Related Tasks
  3121. • Task 34, Creating a Repository, on page 106
  3122. • Task 41, Securing a Repository, on page 120
  3123. Report erratum
  3124. Part VIII
  3125. Advanced Topics
  3126. A DVANCED T OPICS 125
  3127. Subversion includes some advanced features that you might not
  3128. need every day. Questions do often come up about these subjects,
  3129. so we wanted to include extra information for advanced users.
  3130. Covered in this part:
  3131. • Subversion uses properties to control some of its features. One
  3132. example is ignoring files using the svn:ignore property on a
  3133. directory. So far we’ve glossed over what properties really are;
  3134. Task 43, Working with Properties, on the following page ex-
  3135. plains the topic in full.
  3136. • Subversion’s directory-based structure is flexible and free-
  3137. form, with only community conventions to tell you how to
  3138. structure projects inside your repository. Handling multiple
  3139. projects is a common area of concern. Task 45, Organizing
  3140. Multiple Projects, on page 130 covers a proven strategy for
  3141. storing many projects in a single repository.
  3142. • Some users may want to store third-party source code inside a
  3143. Subversion repository for safety in case a vendor disappears or
  3144. to provide some control over the kind of third-party code that
  3145. is used within their organization. If you want to properly track
  3146. third-party code within your repository, you’ll need to learn a
  3147. few tricks, covered in this part of the book.
  3148. • Some users dealing with large files or repositories might need
  3149. to work directly with the repository, bypassing a working copy.
  3150. We discuss why you might want to do this, and how you
  3151. should do it, in Task 47, Working Directly with the Repository,
  3152. on page 134.
  3153. • If you have changes that you want to move around without
  3154. checking in, for example via email, Task 48, Using Patch Files,
  3155. on page 136 describes how you can do this.
  3156. Report erratum
  3157. W ORKING WITH P ROPERTIES 126
  3158. 43 Working with Properties
  3159. Subversion tracks changes for directories and file contents, but it also tracks
  3160. changes for properties attached to files and directories. Properties each have
  3161. a name and text or binary content. Subversion tracks properties just like file
  3162. content, so you must commit changes to properties, you can revert changes
  3163. you no longer want, and it’s possible for properties to be in conflict.
  3164. Subversion reserves properties whose names begin with svn: for
  3165. special Subversion features. Ignoring files, enabling file locking, and setting
  3166. up Subversion externals all use properties to tell Subversion how to behave.
  3167. Properties can also be used by a development team if there are pieces of
  3168. informationthatshouldbeattached toafilebutaren’tpartofthefile’scontent.
  3169. The example on the facing page shows how to use a custom reviewed-by
  3170. property to mark Java source code as being “reviewed” by another
  3171. developer. When the code review is complete, we set the property to indicate
  3172. who did the review. Other users can retrieve the property and see who, if
  3173. anyone, reviewed the file. Of course, this isn’t avery good system for doing
  3174. code reviews—as soon as someone changes the file content, the review no
  3175. longer applies to the new version of the file—but you can see how a team
  3176. might build elements of their process around Subversion properties.
  3177. The Subversion command-line client includes a number of commands for
  3178. manipulating properties. In addition to propset , propget , and propdel ,
  3179. proplist will list all properties on a file or directory, and propedit will fire up
  3180. an editor to make changes to a property.
  3181. Tortoise provides a sophisticated graphical interface for manipulating
  3182. properties. It even allows the import and export of property values so you
  3183. can set a property to be binary content, such as an image. Cornerstone
  3184. restricts property editing so you can only manipulate Subversion-specific
  3185. properties such as svn:needs-lock .
  3186. Once you have finished altering properties, you need to commit your
  3187. changes to the repository, just like file content changes. If you change your
  3188. mind, you can revert a file to undo property changes. Bear in mind that
  3189. reverting a file will also undo any changes to the file’s contents.
  3190. Report erratum
  3191. W ORKING WITH P ROPERTIES 127
  3192. Seta text property on a file.
  3193. mbench> svn propset reviewed-by "mike mason: code is good" \
  3194. src/mbench.java
  3195. property 'reviewed-by' set on 'src/mbench.java'
  3196. mbench> svn commit -m "Add code review comment"
  3197. Retrieve a text property on a file.
  3198. mbench> svn propget reviewed-by src/mbench.java
  3199. mike mason - code looks good
  3200. Remove a property from a file.
  3201. mbench> svn propdel reviewed-by src/mbench.java
  3202. property 'reviewed-by' deleted from 'src/mbench.java'.
  3203. Edit a text property on a file.
  3204. mbench> svn propedit reviewed-by src/mbench.java
  3205. Alter properties using Tortoise.
  3206. Right-click a file or directory, and choose TortoiseSVN > Properties. Use the
  3207. New..., Edit..., and Remove buttons to alter properties. Commit your changes
  3208. once you are happy with the new properties.
  3209. Alter properties using Cornerstone.
  3210. Use the working copy browser to find the file or directory for which you
  3211. want to change properties. Ensure the Inspector panel is active, and then
  3212. click the Properties button in the Inspector panel. Alter properties, and then
  3213. commit your changes to the repository.
  3214. Related Tasks
  3215. • Task 16, Ignoring Files, on page 50
  3216. • Task 29, Enabling File Locking, on page 92
  3217. • Task 44, Using Externals, on the following page
  3218. Report erratum
  3219. U SING E XTERNALS 128
  3220. 44 Using Externals
  3221. Within an organization, it’s quite likely that development teams will want to
  3222. share assets between projects. It might be a goal for projects to use a
  3223. common set of third-party components or for certain projects to share parts
  3224. of their source code for other projects to use. Subversion’s externals provide
  3225. an easy way to include portions of a repository within a project.
  3226. Externals are controlled through the svn:externals property, which can be
  3227. set on any directory within a repository. When a Subversion client sees the
  3228. external, it attempts to contact the specified Subversion repository and check
  3229. out a portion of that repository into the working copy. An external can refer
  3230. to a directory or a single file that you want to include in your working copy.
  3231. Once you have set svn:externals on a directory, doing an update causes the
  3232. Subversion client to pull in the extra directories or files.
  3233. svn:externals is a multiline property with each line specifying a source URL
  3234. for the external and a target directory in the working copy. Source URLs can
  3235. be absolute or relative; you should always use a relative URL if you are
  3236. referring to the current repository.
  3237. Relative URLs always refer to the repository in which the external is
  3238. defined, and they’re especially useful when a repository has multiple access
  3239. methods or names. For example, on my machine, I might refer to http://svn.
  3240. mycompany.com/mbench, and you might refer to https://svn/mbench. Both
  3241. these URLs point to the same repository—which one is right to use in an
  3242. external? Subversion solves this problem by providing the following relative
  3243. URL definitions:
  3244. ../ Relative to the directory on which svn:externals is set
  3245. ^/ Relative to the root of the repository in which svn:externals is set
  3246. // Relative to the scheme of the URL of the directory on which
  3247. svn:externals is set
  3248. / Relative to the root URL of the server on which svn:externals is set
  3249. In our example, we use ^/libraries to mean the libraries directory in the root
  3250. of the current repository. Clients using different access schemes such as svn ,
  3251. http , and https will all translate the external correctly.
  3252. Once you have made a change to svn:externals , as with any other property
  3253. change, you must commit to the repository before anyone else will see the
  3254. new externals.
  3255. Report erratum
  3256. U SING E XTERNALS 129
  3257. Add libraries to your project using externals.
  3258. Use svn propedit or the Tortoise or Cornerstone GUI to edit the
  3259. svn:externals property on the base directory of your project.
  3260. ^/libraries/MongoDB/1.4 libraries/mongo
  3261. Run an update to ensure the new external works as you expect, and then
  3262. commit your changes to the repository.
  3263. mongo> svn update
  3264. Fetching external item into 'libraries/mongo'
  3265. A libraries/mongo/mongo.jar
  3266. Updated external to revision 25.
  3267. Updated to revision 25.
  3268. mongo> svn commit -m "Pulled in Mongo 1.4 library"
  3269. Add third-party code to your project using externals.
  3270. Use svn propedit or the Tortoise or Cornerstone GUI to edit the
  3271. svn:externals property on the base directory of your project.
  3272. http://svn.apache.org/repos/asf/subversion/trunk/notes/
  3273. dependencies/subversion
  3274. Run an update to ensure the new external works as you expect, and then
  3275. commit your changes to the repository.
  3276. mongo> svn update
  3277. Fetching external item into 'dependencies/subversion'
  3278. A dependencies/subversion/repos_upgrade_HOWTO
  3279. A dependencies/subversion/sasl.txt
  3280. A dependencies/subversion/svnsync.txt
  3281. : : :
  3282. A dependencies/subversion/wc-ng/transitions
  3283. A dependencies/subversion/asp-dot-net-hack.txt
  3284. Updated external to revision 947760.
  3285. Updated to revision 25.
  3286. mongo> svn commit -m "Added Subversion notes as dependencies"
  3287. Related Tasks
  3288. • Task 43, Working with Properties, on page 126
  3289. • Task 45, Organizing Multiple Projects, on the following page
  3290. Report erratum
  3291. O RGANIZING M ULTIPLE P ROJECTS 130
  3292. 45 Organizing Multiple Projects
  3293. One of the most common questions asked by teams new to Subversion is,
  3294. “How can we host multiple projects within a repository?” Subversion uses
  3295. directories to organize projects, and directories are also used to store tags
  3296. and branches, so there are many different project structures that can work.
  3297. The simplest organization strategy is to have a root-level directory for each
  3298. project. Within each project directory, you should create the usual trunk ,
  3299. tags , and branches subdirectories. Each project is then free to evolve
  3300. independently, branching and creating release tags as they see fit. If you
  3301. want to share artifacts between projects, you can use Subversion externals to
  3302. include directories from one project inside another project. You might do
  3303. this if one of the projects is a utility designed to be shared across projects.
  3304. More complex organization schemes are possible. One common question is
  3305. around dependent projects that need to have a similar life cycle, for example
  3306. components of a services ecosystem. These components are interdependent,
  3307. so you might put them all inside a single trunk directory and then branch and
  3308. tag them as a unit. This approach can work but is usually a mistake—as soon
  3309. as one of the components wants to evolve at a different rate than the others,
  3310. the model is broken.
  3311. If you are using externals to share code or libraries between projects, you
  3312. need to take extra care when dealing with release branches. On a release
  3313. branch, we want to be able to re-create the exact state of the code and any
  3314. dependencies, but an external that references the trunk of another project can
  3315. change over time. On a release branch, always update your externals so that
  3316. they point to a tagged release from another project, or use pegged revisions 17
  3317. for all your externals.
  3318. When deciding on how to structure your Subversion repository, make sure to
  3319. think about the kinds of projects you want to store, whether those projects
  3320. have interdependencies, and how the projects evolve over time. Try a few
  3321. thought experiments to see how branching, releasing, and bug fixing would
  3322. work with your structure. Finally, make sure both developers and Subversion
  3323. administrators understand your organization strategy.
  3324. 17. http://svnbook.red-bean.com/en/1.5/svn.advanced.externals.html
  3325. Report erratum
  3326. O RGANIZING M ULTIPLE P ROJECTS 131
  3327. Create repository directories for your projects.
  3328. In the root of your repository, create a base directory for each project. Inside
  3329. each project directory, create trunk , tags , and branches subdirectories.
  3330. repository
  3331. root
  3332. trunk
  3333. tags
  3334. branches
  3335. mbench
  3336. mbench
  3337. mbench
  3338. kithara
  3339. mbench
  3340. services
  3341. client
  3342. trunk
  3343. tags
  3344. branches
  3345. trunk
  3346. tags
  3347. branches
  3348. Use externals to share code or other artifacts between projects.
  3349. If one of your projects is creating a shared library for use by other projects,
  3350. use svn:externals to include part of a project inside another project.
  3351. mbench
  3352. kithara
  3353. services
  3354. client
  3355. trunk
  3356. trunk
  3357. dependencies
  3358. src
  3359. mbench
  3360. services
  3361. client
  3362. svn:externals
  3363. Related Tasks
  3364. • Task 5, Creating an Empty Project, on page 24
  3365. • Task 44, Using Externals, on page 128
  3366. Report erratum
  3367. S TORING T HIRD -P ARTY C ODE 132
  3368. 46 Storing Third-Party Code
  3369. Most third-party libraries are distributed in binary format, usually as a .dll or
  3370. .jar file that you can link directly into your project. Some vendors provide
  3371. source code in addition to binaries, and it can be useful to track that source
  3372. code yourself. If the vendor ever goes away, you’ll still have all the source
  3373. code and will be able to make changes and bug fixes to the library.
  3374. You should store all your vendor source code in one place in your repository.
  3375. In the instructions on the facing page, we put all vendor code in named
  3376. directories beneath /vendorsrc . Start by unzipping the source code
  3377. (sometimes called a code drop) to a temporary directory. Next, import the
  3378. code drop into a current directory inside the repository. We’ll use the
  3379. current directory for future code drops. Finally, create a tag for the release.
  3380. When other projects want to use the third-party source code, they should
  3381. always use a tagged version, never current .
  3382. When a new version of the library becomes available, we need to update our
  3383. current version to match the new code drop. We’re trying to mimic inside
  3384. Subversion what would have happened during the vendor’s development of a
  3385. new release. The vendor has probably added files, removed files, and updated
  3386. file content. To mimic this, we might check out a working copy of current
  3387. and then unzip the new code drop over the top. This would give us a working
  3388. copy with all the updated files, but it wouldn’t help us with files that the
  3389. vendor added or removed in the new code drop. Manually figuring out how
  3390. to sync a working copy of current with a new code drop is a lot of work.
  3391. Fortunately, there’s a Python tool that does all the heavy lifting for us.
  3392. svn-load is available online 18 and requires the Python Subversion bindings.
  3393. If you’re using Ubuntu, run apt-get install svn-load to install svn-load and
  3394. its dependencies.
  3395. Unzip the new code drop in a temporary directory. Run svn-load , telling it
  3396. the new tag version you’d like to apply, the URL for the current directory,
  3397. and the location of the new code drop on your local machine. svn-load will
  3398. automatically figure out which files have been added, removed, or changed
  3399. by the vendor. svn-load will update the current directory in the repository
  3400. and tag it with the new version number. Teams can then update their projects
  3401. and use the new release.
  3402. 18. http://free.linux.hp.com/~dannf/svn-load/
  3403. Report erratum
  3404. S TORING T HIRD -P ARTY C ODE 133
  3405. Import third-party source code.
  3406. Extract the third-party source code to a temporary directory. Here we use
  3407. /temp/NUnit-2.5.0 .
  3408. temp> svn import -m "Import NUnit 2.5.0" NUnit-2.5.0 \
  3409. http://svn.mycompany.com/vendorsrc/nunit/current
  3410. Adding NUnit-2.5.0/NUnitTests.config
  3411. Adding NUnit-2.5.0/NUnitFitTests.html
  3412. : : :
  3413. Adding NUnit-2.5.0/install/NUnit.wxs
  3414. Adding NUnit-2.5.0/license.rtf
  3415. Create a tagged version of the third-party code.
  3416. temp> svn copy -m"Tag 2.5.0 vendor drop" \
  3417. http://svn.mycompany.com/vendorsrc/nunit/current \
  3418. http://svn.mycompany.com/vendorsrc/nunit/2.5.0
  3419. Committed revision 29.
  3420. Update to a new third-party release.
  3421. Extract the new code drop to a temporary directory. Here we use
  3422. /temp/NUnit-2.5.5 .
  3423. temp> svn-load -t2.5.5 http://svn.mycompany.com/vendorsrc/nunit \
  3424. current NUnit-2.5.5
  3425. Deleted Added
  3426. 0 doc/img/assemblyReloadOptions.JPG___ doc/assemblyIsolation.html
  3427. 1 doc/img/testResultOptions.JPG_______ doc/runningTests.html
  3428. 2 doc/img/textOutputOptions.jpg_______ doc/runtimeSelection.html
  3429. : : :
  3430. Enter two indexes for each column to rename,
  3431. (R)elist, or (F)inish: F
  3432. Related Tasks
  3433. • Task 6, Creating a Project from an Existing Source Tree, on page 26
  3434. • Task 28, Tagging a Release, on page 86
  3435. Report erratum
  3436. W ORKING D IRECTLY WITH THE R EPOSITORY 134
  3437. 47 Working Directly with the Repository
  3438. Most of the time you should make changes to a Subversion working copy
  3439. and then commit those changes to the repository. This gives you a chance to
  3440. think about the changes, revert unwanted or erroneous modifications, and
  3441. even run a build to make sure everything works before you commit. There
  3442. are times, though, when you might want to work directly with the repository.
  3443. For some Subversion commands, you can use a repository URL instead of
  3444. referring to working copy files.
  3445. You can copy, move, rename, and delete items directly in the repository. You
  3446. might want to do this if the files are large and would take a long time to
  3447. manipulate in a working copy. You might alsowant to do this if you recently
  3448. imported a large number of files and need to rearrange them. If developers
  3449. are working on files when they are moved, Subversion will report a tree
  3450. conflict when they attempt to commit their changes. If a user has a file
  3451. locked, it cannot be moved, renamed, or deleted within the repository until
  3452. the lock is released.
  3453. Subversion stores history forever. In our example, we’re deleting a password
  3454. file that someone has accidentally added to the repository. Deleting a file
  3455. only removes it from Subversion’s “current” view of what’s in the repository.
  3456. If someone knows that the password file is there, they can go back in time
  3457. using Subversion’s history features and retrieve the file. If you do
  3458. accidentally commit confidential information to a Subversion repository, you
  3459. will have to do a lot of work to really remove the data by dumping the
  3460. repository and then reloading it using svndumpfilter to filter out the
  3461. confidential file. 19 The dump/load process can be quite time-consuming and
  3462. will involve downtime on the repository. Be careful what you commit!
  3463. 19. http://svnbook.red-bean.com/en/1.5/svn.reposadmin.html has more information about the
  3464. svndumpfilter command.
  3465. Report erratum
  3466. W ORKING D IRECTLY WITH THE R EPOSITORY 135
  3467. Copy an item directly on the repository.
  3468. mbench> svn cp http://svn.mycompany.com/mbench/trunk/lib/mongo-1.4.jar \
  3469. http://svn.mycompany.com/libraries/mongo \
  3470. -m"Copy Mongo jar to shared libraries directory"
  3471. Rename an item directly on the repository.
  3472. mbench> svn mv http://svn.mycompany.com/mbench/trunk/docs \
  3473. http://svn.mycompany.com/mbench/trunk/documentation \
  3474. -m"Renaming to make us look more professional"
  3475. Delete an item from the repository.
  3476. mbench> svn rm http://svn.mycompany.com/mbench/trunk/config/passwd \
  3477. -m "Removing accidentally added password file"
  3478. Rename a repository item using Tortoise.
  3479. Right-click in your project working copy, and choose TortoiseSVN >
  3480. Repo-browser. Navigate to the item you want to rename, right-click it, and
  3481. choose Rename. Type a new name for the item, and press Enter.
  3482. Enter a log message explaining the reason for the change, and then click OK
  3483. to complete the change.
  3484. Rename a repository item using Cornerstone.
  3485. Select your repository from the repository source list. Using the repository
  3486. browser, navigate to the item you want to rename. Select the item, pause for
  3487. a second, and then click the item name again to make it editable. Type a new
  3488. name for the item, and press Enter.
  3489. Enter a log message explaining the reason for the change, and then click
  3490. Continue to complete the change.
  3491. Related Tasks
  3492. • Task 13, Removing Files and Directories, on page 44
  3493. • Task 14, Moving and Renaming Files and Directories, on page 46
  3494. Report erratum
  3495. U SING P ATCH F ILES 136
  3496. 48 Using Patch Files
  3497. Occasionally you might want to save a copy of your working copy changes
  3498. without committing them to the repository. You might decide your changes
  3499. aren’t yet ready for prime time and that you want to keep them for later
  3500. (although in this case, creating a feature branch and checking in to the
  3501. branch is safer). Alternatively, you might be working on an open source
  3502. project on the Internet and not have commit access to the repository. Instead
  3503. of committing your changes directly, you need to send them to someone else
  3504. on the project who has commit access.
  3505. Patch files are the Unix world’s solution to this problem. A patch file is a
  3506. description of changes you have made to some files. You can send the patch
  3507. file to someone else who has the original files, and they can apply the patch
  3508. to get your changes. Patch files include a special syntax that often allows
  3509. them to work even if the person you’re sending the patch to doesn’t have
  3510. exactly the same revision of the files as were used to create the patch.
  3511. Subversion’s diff command shows working copy modifications in “unified
  3512. diff” format so you can create a patch file by saving svn diff results to a file.
  3513. Tortoise and Cornerstone allow you to select a file or directory and save any
  3514. modifications to a patch file.
  3515. Once you have a patch file, you can send it to someone else or keep it
  3516. somewhere safe for your own use. To apply a patch file, use the Unix patch
  3517. command or the Tortoise or Cornerstone “apply patch” functionality.
  3518. Applying a patch takes the changes described in the patch file and attempts
  3519. to perform them on another set of files. For our purposes, this should always
  3520. be another Subversion working copy.
  3521. If the patch does not apply cleanly, it’s usually because the new working
  3522. copy where the patch is being applied has a different revision of the files
  3523. than were used to create the patch. The various different patch tools handle
  3524. this in different ways.
  3525. The command-line and Cornerstone clients both use the Unix patch
  3526. command to apply patches. If a patch can’t be applied successfully, patch
  3527. saves rejected “hunks” to a copy of the file with a .rej suffix. You can look at
  3528. the reject files and attempt to resolve the conflicts yourself. If Tortoise can’t
  3529. apply a patch cleanly, you can use the TortoiseMerge tool to resolve
  3530. conflicts, as describedin Task 19, Handling Conflicts Using Tortoise, on
  3531. page 60.
  3532. Report erratum
  3533. U SING P ATCH F ILES 137
  3534. Create a patch file using the command-line client.
  3535. mbench> svn diff > mychanges.patch
  3536. Apply a patch file using the command-line client.
  3537. mbench2> patch < mychanges.patch
  3538. Create a patch file using Tortoise.
  3539. Right-click the base directory for your working copy, and choose
  3540. TortoiseSVN > Create patch.... Select the files you want to include in the
  3541. patch, and click OK.
  3542. Specify a file in which to save the patch, and then click Save. Tortoise will
  3543. create the patch file, save it to disk, and then display it in a graphical browser.
  3544. Apply a patch file using Tortoise.
  3545. Right-click the base directory for your working copy, and choose
  3546. TortoiseSVN > Apply patch.... Browse to your patch file, select it, and click
  3547. Open.
  3548. Tortoise will open two windows, one listing the files in the patch and the
  3549. other a large TortoiseMerge window. For each file to be patched,
  3550. double-click the filename to apply the changes in the merge window. If
  3551. you’re happy that the changes applied correctly, press Ctrl+S to save the
  3552. changes.
  3553. Create a patch file using Cornerstone.
  3554. Select your working copy from the working copy sources list. Click the File
  3555. menu, and choose Save Differences in “mbench” as Patch.... Enter a
  3556. filename, and click Save to create the patch file.
  3557. Apply a patch file using Cornerstone.
  3558. Select your working copy from the working copy sources list. Click the File
  3559. menu, and choose Apply Patch to “mbench2”.... Browse to your patch file,
  3560. and click Apply.
  3561. Related Tasks
  3562. • Task 8, Seeing What You’ve Changed, on page 34
  3563. • Task 11, Committing Changes, on page 40
  3564. Report erratum
  3565. Bibliography
  3566. [Mas06] Mike Mason. Pragmatic Version Control Using Subversion.
  3567. The Pragmatic Programmers, LLC, Raleigh, NC, and Dallas,
  3568. TX, second edition, 2006.
  3569. [Swi08] Travis Swicegood. Pragmatic Version Control using Git. The
  3570. Pragmatic Programmers, LLC, Raleigh, NC, and Dallas, TX,
  3571. 2008.
  3572. Index
  3573. A
  3574. access controls, 14, 120
  3575. add command, 43
  3576. annotate command, 68
  3577. Apache
  3578. repository security, 120
  3579. Subversion server installation, 104–106
  3580. atomic commit, 10
  3581. B
  3582. backups, 114–118
  3583. base directory, 23, 25
  3584. base URL, 22
  3585. Beanstalk, 111
  3586. blame command, 68
  3587. branches
  3588. checking out, 79
  3589. creating, 78
  3590. directory structure, 24
  3591. feature branches, 75, 84
  3592. merging changes from trunk, 82
  3593. merging changes to trunk, 84
  3594. release branches, 73–75
  3595. switching to, 80
  3596. C
  3597. change tracking
  3598. blame information, 68
  3599. history, 65–71
  3600. merge tracking, 84
  3601. in working copy, 34–39
  3602. changesets, see revisions
  3603. check-in, see commit command
  3604. checkout command, 33
  3605. client-server model, 14
  3606. clients for Subversion
  3607. command-line, 17
  3608. Mac OS X, 21
  3609. Windows, 18
  3610. CollabNet, 17, 108
  3611. command-line client, 16, 17
  3612. commit command, 41
  3613. commit messages, 40, 65
  3614. commit process, 10
  3615. concurrency, 53, 58, 89
  3616. conflicts, 53, 58–63
  3617. copy command, 79, 87
  3618. Cornerstone
  3619. adding files and directories, 43
  3620. adding repositories, 20
  3621. altering properties, 127
  3622. applying patch files, 137
  3623. checking out a working copy, 33
  3624. committing changes, 41
  3625. conflict handling, 62
  3626. creating branches, 79
  3627. creating local repositories, 23
  3628. creating patch files, 137
  3629. creating projects, 25
  3630. creating release tags, 87
  3631. enabling locks, 93
  3632. ignoring files and directories, 51
  3633. importing source trees, 27
  3634. installing, 20
  3635. locking files, 95
  3636. moving files and directories,46
  3637. removing files and directories, 45
  3638. renaming files and directories, 46
  3639. renaming repository items, 135
  3640. reverting changes, 48
  3641. reverting committed revisions, 70
  3642. stealing locks, 99
  3643. unlocking files, 97
  3644. updating to latest revision, 56
  3645. viewing change logs, 67
  3646. viewing changes, 38
  3647. viewing update messages, 56
  3648. cross-platform operation, 10
  3649. CVS repositories, 112
  3650. cvs2svn tool, 112
  3651. DELETE COMMAND REPOSITORIES
  3652. D
  3653. delete command, 45
  3654. diff command, 34, 136
  3655. dump files, 114
  3656. E
  3657. Eclipse, 15
  3658. externals, 128
  3659. externals property, 128
  3660. F
  3661. feature branches, 75, 84
  3662. files
  3663. adding to working copy, 42
  3664. change tracking, 34–39
  3665. checking out, 32
  3666. committing changes, 40
  3667. conflicts in, 53, 58–63
  3668. ignoring, 50
  3669. importing into project, 26
  3670. locking/unlocking, 92–99
  3671. moving, 46
  3672. patch files, 136
  3673. removing, 44
  3674. renaming, 46
  3675. reverting changes, 48
  3676. viewing blame information, 68
  3677. viewing changes, 34
  3678. Fink, 17
  3679. forks, see branches
  3680. H
  3681. history, 65–71
  3682. hook scripts, 122
  3683. I
  3684. ignore property, 50
  3685. import command, 27
  3686. info command, 80
  3687. IntelliJ, 15
  3688. L
  3689. libraries (third-party), 132
  3690. local repositories, 22
  3691. lock command, 95, 99
  3692. locks, 89, 92–99
  3693. log command, 66
  3694. log messages, 65
  3695. M
  3696. MacPorts, 17
  3697. merge command, 71, 83, 85
  3698. merge conflicts, 58
  3699. merge tracking, 84
  3700. meta data, see properties
  3701. mkdir command, 25
  3702. move command, 46
  3703. mv command, 47
  3704. N
  3705. needs-lock property, 92
  3706. network security, 14
  3707. O
  3708. optimistic locking, 53
  3709. P
  3710. patch files, 136
  3711. pessimistic locking, 89
  3712. projects
  3713. checking out, 32
  3714. creating, 24
  3715. directory structure, 24
  3716. history, 65–71
  3717. importing source trees to, 26
  3718. security, 120
  3719. properties, 126
  3720. R
  3721. RapidSVN, 16
  3722. rebasing, 84
  3723. reintegration, 84
  3724. releases, 86
  3725. rename command, 46
  3726. repositories
  3727. adding files and directories, 42
  3728. backups, 114–118
  3729. base URL, 22
  3730. branches, 73–75, 78, 82
  3731. change logs, 66–71
  3732. committing changes to, 40
  3733. creating, on Apache, 106
  3734. creating, on Windows, 108
  3735. direct changes to, 134
  3736. directory structure, 24, 130
  3737. externals, 128
  3738. history, 65–71
  3739. hooks, 122
  3740. importing source trees to, 26
  3741. local, 22
  3742. migrating from CVS, 112
  3743. moving files and directories,46
  3744. multiple projects in, 24, 130
  3745. removing files and directories, 44
  3746. renaming files and directories, 46
  3747. 140
  3748. RESOLVED COMMAND V ISUAL S TUDIO
  3749. restoring from dump files, 114, 118
  3750. security, 14, 120
  3751. third-party code in, 132
  3752. undoing committed changes, 70
  3753. resolved command, 59
  3754. reverse merges, 70
  3755. revert command, 48
  3756. revision numbers, 10
  3757. revisions
  3758. creating, 40
  3759. history, 65
  3760. merging to a branch, 83
  3761. reverting, 70
  3762. updating to latest, 56
  3763. S
  3764. security
  3765. access controls, 14, 120
  3766. network connections, 14
  3767. servers
  3768. Apache on Ubuntu Linux, 104
  3769. svnserve on a LAN, 101
  3770. svnserve on Windows, 108
  3771. third-party hosting, 110
  3772. SourceForge, 111
  3773. status command, 34
  3774. Subcommander, 16
  3775. Subversion
  3776. availability, 16
  3777. centralized model, 9
  3778. client installation, 16–21
  3779. client-server model, 14
  3780. commit process, 10
  3781. cross-platform operation, 10
  3782. security model, 120
  3783. server installation, 104–109
  3784. versions of, 12, 16
  3785. .svn directories, 32, 48
  3786. svn-load tool, 132
  3787. svn:externals property, 128
  3788. svn:ignore property, 50
  3789. svn:needs-lock property, 92
  3790. svnadmin command
  3791. create , 23, 106, 109
  3792. dump , 114
  3793. load , 114, 118
  3794. verify , 114
  3795. svnlook command, 116
  3796. svnserve server, 101, 108
  3797. switch command, 80
  3798. Synaptic package manager, 17
  3799. sync, see update command
  3800. T
  3801. tags
  3802. creating, 86
  3803. directory structure, 24
  3804. when to use, 75
  3805. third-party code, 132
  3806. TortoiseMerge tool, 60
  3807. TortoiseSVN
  3808. adding files and directories, 43
  3809. altering properties, 127
  3810. applying patch files, 137
  3811. checking out a working copy, 33
  3812. committing changes, 41
  3813. conflict handling, 60
  3814. context menu settings, 18
  3815. creating branches, 79
  3816. creating local repositories, 23
  3817. creating patch files, 137
  3818. creating projects, 25
  3819. creating release tags, 87
  3820. enabling locks, 93
  3821. ignoring files and directories, 51
  3822. importing source trees, 27
  3823. installing, 19
  3824. locking files, 95
  3825. merging changes to trunk, 85
  3826. merging revisions to branch, 83
  3827. moving files and directories,46
  3828. removing files and directories, 45
  3829. renaming files and directories, 46
  3830. renaming repository items, 135
  3831. reverting changes, 49
  3832. reverting committed revisions, 71
  3833. stealing locks, 99
  3834. switching to branches, 81
  3835. unlocking files, 97
  3836. updating to latest revision, 56
  3837. viewing blame information, 68
  3838. viewing change logs, 67
  3839. viewing changes, 36
  3840. viewing update messages, 56
  3841. trunk directory, 24, 32
  3842. U
  3843. Unfuddle, 111
  3844. unlock command, 97, 99
  3845. update command, 56, 58
  3846. V
  3847. version command, 16
  3848. Visual Studio, 15
  3849. 141
  3850. WORKING COPY X CODE
  3851. W
  3852. working copy
  3853. adding files and directories, 42
  3854. change logs, 66
  3855. checking out, 32, 79
  3856. committing changes, 41
  3857. creating release tags, 86
  3858. ignoring files and directories, 50
  3859. moving files and directories, 46
  3860. removing files and directories, 44
  3861. renaming files and directories, 46
  3862. reverting changes, 48
  3863. updating to latest revision, 56
  3864. viewing changes, 34
  3865. X
  3866. Xcode, 15
  3867. 142
  3868. ThePragmaticBookshelf
  3869. Available in paperback and DRM-free eBooks, our titles are here to help you stay on top of
  3870. your game. The following are in print as of October 2010; be sure to check our website at
  3871. pragprog.com for newer titles.
  3872. Title Year ISBN Pages
  3873. Advanced Rails Recipes: 84 New Ways to Build Stunning
  3874. Rails Apps
  3875. 2008 9780978739225 464
  3876. Agile Coaching 2009 9781934356432 248
  3877. Agile Retrospectives: Making Good Teams Great 2006 9780977616640 200
  3878. Agile Web Development with Rails 2009 9781934356166 792
  3879. Beginning Mac Programming: Develop with Objective-C
  3880. and Cocoa
  3881. 2010 9781934356517 300
  3882. Behind Closed Doors: Secrets of Great Management 2005 9780976694021 192
  3883. Best of Ruby Quiz 2006 9780976694076 304
  3884. Cocoa Programming: A Quick-Start Guide for
  3885. Developers
  3886. 2010 9781934356302 450
  3887. Core Animation for Mac OS X and the iPhone: Creating
  3888. Compelling Dynamic User Interfaces
  3889. 2008 9781934356104 200
  3890. Core Data: Apple’s API for Persisting Data on Mac OS X 2009 9781934356326 256
  3891. Data Crunching: Solve Everyday Problems using Java,
  3892. Python, and More
  3893. 2005 9780974514079 208
  3894. Debug It! Find, Repair, and Prevent Bugs in Your Code 2009 9781934356289 232
  3895. Deploying Rails Applications: A Step-by-Step Guide 2008 9780978739201 280
  3896. Design Accessible Web Sites: 36 Keys to Creating
  3897. Content for All Audiences and Platforms
  3898. 2007 9781934356029 336
  3899. Desktop GIS: Mapping the Planet with Open Source
  3900. Tools
  3901. 2008 9781934356067 368
  3902. Domain-Driven Design Using Naked Objects 2009 9781934356449 375
  3903. Enterprise Integration with Ruby 2006 9780976694069 360
  3904. Enterprise Recipes with Ruby and Rails 2008 9781934356234 416
  3905. Everyday Scripting with Ruby: for Teams, Testers, and
  3906. You
  3907. 2007 9780977616619 320
  3908. ExpressionEngine 2: A Quick-Start Guide 2010 9781934356524 250
  3909. From Java To Ruby: Things Every Manager Should Know 2006 9780976694090 160
  3910. FXRuby: Create Lean and Mean GUIs with Ruby 2008 9781934356074 240
  3911. GIS for Web Developers: Adding Where to Your Web
  3912. Applications
  3913. 2007 9780974514093 275
  3914. Google Maps API: Adding Where to Your Applications 2006 PDF-Only 83
  3915. Grails: A Quick-Start Guide 2009 9781934356463 200
  3916. Groovy Recipes: Greasing the Wheels of Java 2008 9780978739294 264
  3917. Hello, Android: Introducing Google’s Mobile
  3918. Development Platform
  3919. 2010 9781934356562 320
  3920. Continued on next page
  3921. Title Year ISBN Pages
  3922. Interface Oriented Design 2006 9780976694052 240
  3923. iPad Programming: A Quick-Start Guide for iPhone
  3924. Developers
  3925. 2010 9781934356579 248
  3926. iPhone SDK Development 2009 9781934356258 576
  3927. Land the Tech Job You Love 2009 9781934356265 280
  3928. Language Implementation Patterns: Create Your Own
  3929. Domain-Specific and General Programming Languages
  3930. 2009 9781934356456 350
  3931. Learn to Program 2009 9781934356364 240
  3932. Manage It! Your Guide to Modern Pragmatic Project
  3933. Management
  3934. 2007 9780978739249 360
  3935. Manage Your Project Portfolio: Increase Your Capacity
  3936. and Finish More Projects
  3937. 2009 9781934356296 200
  3938. Mastering Dojo: JavaScript and Ajax Tools for Great
  3939. Web Experiences
  3940. 2008 9781934356111 568
  3941. Metaprogramming Ruby: Program Like the Ruby Pros 2010 9781934356470 240
  3942. Modular Java: Creating Flexible Applications with OSGi
  3943. and Spring
  3944. 2009 9781934356401 260
  3945. No Fluff Just Stuff 2006 Anthology 2006 9780977616664 240
  3946. No Fluff Just Stuff 2007 Anthology 2007 9780978739287 320
  3947. Pomodoro Technique Illustrated: The Easy Way to Do
  3948. More in Less Time
  3949. 2009 9781934356500 144
  3950. Practical Programming: An Introduction to Computer
  3951. Science Using Python
  3952. 2009 9781934356272 350
  3953. Practices of an Agile Developer 2006 9780974514086 208
  3954. Pragmatic Guide to Git 2010 9781934356722 168
  3955. Pragmatic Project Automation: How to Build, Deploy,
  3956. and Monitor Java Applications
  3957. 2004 9780974514031 176
  3958. Pragmatic Thinking and Learning: Refactor Your
  3959. Wetware
  3960. 2008 9781934356050 288
  3961. Pragmatic Unit Testing in C# with NUnit 2007 9780977616671 176
  3962. Pragmatic Unit Testing in Java with JUnit 2003 9780974514017 160
  3963. Pragmatic Version Control using CVS 2003 9780974514000 176
  3964. Pragmatic Version Control Using Git 2008 9781934356159 200
  3965. Pragmatic Version Control using Subversion 2006 9780977616657 248
  3966. Programming Clojure 2009 9781934356333 304
  3967. Programming Cocoa with Ruby: Create Compelling Mac
  3968. Apps Using RubyCocoa
  3969. 2009 9781934356197 300
  3970. Programming Erlang: Software for a Concurrent World 2007 9781934356005 536
  3971. Programming Groovy: Dynamic Productivity for the Java
  3972. Developer
  3973. 2008 9781934356098 320
  3974. Programming Ruby: The Pragmatic Programmers’ Guide 2004 9780974514055 864
  3975. Programming Ruby 1.9: The Pragmatic Programmers’
  3976. Guide
  3977. 2009 9781934356081 960
  3978. Continued on next page
  3979. Title Year ISBN Pages
  3980. Programming Scala: Tackle Multi-Core Complexity on
  3981. the Java Virtual Machine
  3982. 2009 9781934356319 250
  3983. Prototype and script.aculo.us: You Never Knew
  3984. JavaScript Could Do This!
  3985. 2007 9781934356012 448
  3986. Rails for .NET Developers 2008 9781934356203 300
  3987. Rails for Java Developers 2007 9780977616695 336
  3988. Rails for PHP Developers 2008 9781934356043 432
  3989. Rails Recipes 2006 9780977616602 350
  3990. Rapid GUI Development with QtRuby 2005 PDF-Only 83
  3991. Release It! Design and Deploy Production-Ready
  3992. Software
  3993. 2007 9780978739218 368
  3994. Scripted GUI Testing with Ruby 2008 9781934356180 192
  3995. Seven Languages in Seven Weeks: A Pragmatic Guide to
  3996. Learning Programming Languages
  3997. 2010 9781934356593 300
  3998. Ship It! A Practical Guide to Successful Software Projects 2005 9780974514048 224
  3999. SQL Antipatterns: Avoiding the Pitfalls of Database
  4000. Programming
  4001. 2010 9781934356555 352
  4002. Stripes ...and Java Web Development Is Fun Again 2008 9781934356210 375
  4003. Test-Drive ASP.NET MVC 2010 9781934356531 296
  4004. TextMate: Power Editing for the Mac 2007 9780978739232 208
  4005. The Agile Samurai: How Agile Masters Deliver Great
  4006. Software
  4007. 2010 9781934356586 280
  4008. The Definitive ANTLR Reference: Building
  4009. Domain-Specific Languages
  4010. 2007 9780978739256 384
  4011. The Passionate Programmer: Creating a Remarkable
  4012. Career in Software Development
  4013. 2009 9781934356340 200
  4014. ThoughtWorks Anthology 2008 9781934356142 240
  4015. Ubuntu Kung Fu: Tips, Tricks, Hints, and Hacks 2008 9781934356227 400
  4016. Web Design for Developers: A Programmer’s Guide to
  4017. Design Tools and Techniques
  4018. 2009 9781934356135 300
  4019. ThePragmaticBookshelf
  4020. The Pragmatic Bookshelf features books written by developers for developers. The titles continue
  4021. the well-known Pragmatic Programmer style and continue to garner awards and rave reviews. As
  4022. development gets more and more difficult, the Pragmatic Programmers will be there with more
  4023. titles and products to help you stay on top of your game.
  4024. VisitUsOnline
  4025. Pragmatic Guide to Subversion
  4026. http://pragprog.com/titles/pg_svn
  4027. Source code from this book, errata, and other resources. Come give us feedback, too!
  4028. Register for Updates
  4029. http://pragprog.com/updates
  4030. Be notified when updates and new books become available.
  4031. Join the Community
  4032. http://pragprog.com/community
  4033. Read our weblogs, join our online discussions, participate in our mailing list, interact with our
  4034. wiki, and benefit from the experience of other Pragmatic Programmers.
  4035. New and Noteworthy
  4036. http://pragprog.com/news
  4037. Check out the latest pragmatic developments, new titles and other offerings.
  4038. BuytheBook
  4039. If you liked this eBook, perhaps you’d like to have a paper copy of the book. It’s available for
  4040. purchase at our store: pragprog.com/titles/pg_svn.
  4041. ContactUs
  4042. Online Orders: www.pragprog.com/catalog
  4043. Customer Service: support@pragprog.com
  4044. Non-English Versions: translations@pragprog.com
  4045. Pragmatic Teaching: academic@pragprog.com
  4046. Author Proposals: proposals@pragprog.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement