I'd like to read the source code of one of the popular revision control tools to learn how revision control works. I'd like to read the one that is most readable.
I don't know of an objective, quantitative measure of this, so in the spirit of the WTFs/min comic, I'd like to ask those who have read the source codes of these tools, h开发者_运维问答ow many WTFs/min do you estimate each project has?
If you read C well (and some Perl and bash too), adymitruk is right. Git is a good choice.
However, if you're more comfortable with Python, read Mercurial's source. Many of the WTFs/min are going to come from your familiarity with the language and style that the DVCS is written in. Git is written in C, Perl, and Bourne shell, Mercurial is Python (with a bit of C IIRC), and Bzr is written in Python, Pyrex, and C.
You'll also want to take into account what your tool of choice is. If you use Git, you'll understand what each file is implementing. Likewise with Mercurial or Bzr.
Basically, when choosing what tool or language to use (or study), a good axiom is this: go with what you know. You're trying to learn how to implement a DVCS, not how to use a particular system or language :)
What can be much better than Python in the context of understandable and beautiful code?
Go for Mercurial. I have done it and It's absolutely lovely :)
Git is your best option because it is layered. Commands are based on lower level commands. This will allow you to understand what I'd going on conceptually. You can re implement commands yourself from the lower level ones. Finally, implement the low level ones to manipulate the files themselves.
Git was designed with a lot of thought put into it and will give you the best learning avenue.
Also, take a look at Scott Chacon's git internals posts and screen casts.
Before diving into the code it is useful to first get a architectural overview to know where to dive in. For bazaar the following might help: http://doc.bazaar.canonical.com/bzr.2.3/en/user-guide/core_concepts.html http://doc.bazaar.canonical.com/bzr.2.3/developers/overview.html
I found the bazaar code base well organised, clean and readable, probably because it is python and each code change gets reviewed so code documentation is normally amended as per review which in general makes things a lot clearer. If you get stuck you can always ask on IRC or the mailinglist, but I have not needed to do that much at all.
I wonder how much value there is in looking at bad examples, to get an idea of what not to do, rather than just looking at good examples. I've never looked at the source of Subversion or CVS but it might be worth looking through them and understanding why they don't work as well as the DVCSes you mentioned.
精彩评论