Developer Basics

This page has some basic code examples to get you started hacking on hg. See also MercurialApi.

Looking at changesets

Here's some simple code to look at a changeset:

   1 from mercurial import ui, hg
   2 
   3 u = ui.ui()  # get a ui object
   4 r = hg.repository(u, ".") # get a repo object for the current directory
   5 c = r.changectx("tip") # get a context object for the "tip" revision
   6 
   7 # show some information about the changeset
   8 print c # represented as the changeset hash
   9 print c.user()
  10 print c.description()
  11 print
  12 
  13 # let's take a peek at the files
  14 files = c.files()
  15 for f in files:
  16  fc = c[f]
  17  print " ", f, len(fc.data())

And the output looks like this:

$ python lc.py
534ec2689c94
Matt Mackall <mpm@selenic.com>
copy: more cleanups

- remove copyfile src variable
- add some comments
- simplify actual copy logic
- simplify 'undelete' logic
- make the error counting actually work

  mercurial/cmdutil.py 41944


CategoryDeveloper

DeveloperBasics (last edited 2010-10-15 21:57:56 by abuehl)