Chapter 2. Working with the Sources

How does it all work?  LiveJournal source code is stored in several separate SVN repositories. The files from these are merged into a single live tree. The live tree is your home directory. It contains the code that actually runs on your server. This is the code you edit and play with. The SVN trees are all stored below $LJHOME/cvs/. The …/cvs directory is a holdover, from when the LiveJournal project used CVS for version control.

The script lets you update the SVN trees with the newest code, copy new files from there to the live tree, create patch files for submission, and more.

Typically, you keep your SVN trees up-to-date, updating them every now and then. You use to copy new stuff from the SVN trees into the live tree, while being careful not to overwrite files in the live tree that you have been working on. You edit source in the live tree, test it on your server, edit again, test again and so on. At some point you create a diff of your changed/added files in the live tree against the up-to-date SVN trees, and you submit it. All these actions are explained in detail below.

Use your preferred text editor to edit your source code. Make sure you use Unix style line-endings, UTF-8 encoding, and spaces not tabs.

Resetting your database.  If you have totally messed-up your database and want to re-create it from scratch, do:

    $ mysqladmin drop livejournal
    $ mysqladmin create livejournal
    $ $LJHOME/bin/upgrading/ -r -p
    $ $LJHOME/bin/upgrading/ load

Staying up to date with SVN It's important to make sure you're developing against the latest “trunk” code, when making changes and contributing patches. Every so often, update from SVN: $ -u

… but that's not all.

The above only updates your $LJHOME/cvs directory to be current. It does not affect your live tree. For that, you also use

Merging your live and cvs trees.  See what's changed where: $ bin/

main -> cvs cgi-bin/
main <- cvs htdocs/create.bml

In the example you can see htdocs/create.bml is newest in your SVN tree, and cgi-bin/ is newest in the live tree (where you should be working).

But maybe you have been working on htdocs/create.bml also and don't want to lose your changes. So, use to make a diff and store it somewhere.

$ bin/ --diff htdocs/create.bml
$ bin/ -d htdocs/create.bml cgi-bin/ (two files in one diff)
$ bin/ -d (without filenames, puts all changes in all files in one diff)

Say you want to copy your cgi-bin/ to the SVN tree (under cvs).

$ --sync cgi-bin/
$ -s cgi-bin/

Maybe later fifty files change in SVN, but you have a few files in your live tree that are not ready to go into your $LJHOME/cvs/ directory.

$ -c -s

(Only syncs stuff from $LJHOME/cvs/ to main). That's the command you will probably want to run the most often. There is usually no reason to copy files from your live tree to $LJHOME/cvs tree (you might think you'd do that to create a diff with svn diff, but -d is easier and creates diffs just the way we like them).

Procedure 2.1. Sending patches…

  1. Update SVN first: $ -u

  2. Now, look at your diff: $ -d htdocs/some_file.bml | less

  3. Look good? Sure SVN hasn't changed and your patch doesn't back out any newer changes? Then send it in.