1 σχόλιο »

    • #1
    • Giorgos Keramidas
    • Yep. The only “unique” identifier of a changeset is the full sha256 hash :D

      You can get hold of the sha256 changeset ID by referring to the ‘{node}’ in output templates like the one below:

      $ hg tip --template '{node} | {date|age} | {desc|strip|firstline}\n'
      d94151e1092123062d75fae5f57736629be5f541 | 2 days | cron.d: import a copy of my latest user-crontab file

      In Python, here’s a short ’standalone’ implementation of the “hg branches” command:

      #!/usr/bin/env python
       
      from os import getcwd
      from mercurial import hg, ui, node
       
      cwd = getcwd()
       
      ui = ui.ui()
      try:
          repo = hg.repository(ui, cwd)
      except Exception, inst:
          print "Cannot open repository a %s: %s" % (cwd, str(inst))
       
      activebranches = repo.heads()
       
      print "%s branches:" % cwd
      for bname, n in repo.branchtags().items():
          tag = ""
          if n in activebranches:
              tag = " (active)"
          print "%s %s%s" % (node.hex(n)[:20], bname, tag)

      I’ve trimmed node.hex() output to 20 hex characters, but if you don’t limit the string output you’ll get the full node hash. The active/inactive branch test is also less Pythonic than the similar code in Mercurial’s source tree (see “def branches” in mercurial/commands.py), but it’s probably simpler to understand as an example of node.hex() than the list-comprehension version:

      activebranches = repo.heads()
      for bname, n, isactive in [(b, n, n in activebranches) for b, n in repo.branchtags().items()]:
          print "%s %s%s" % (node.hex(n)[:20], bname, tag)

      Anyway, this is getting too long-winded. All I wanted to write as “don’t rely on revision ‘numbers’, use the changeset hash as a UUID of changesets.” If you are worried about the space/time it takes to compare hg node strings, use the hg.node object to store them as raw-data/binary values and convert them to strings only at the last possible moment before display.


Σχολιάστε!




Νιώστε ελεύθερα να πείτε τη γνώμη σας!

Παρακαλώ διαβάστε την πολιτική σχολίων πριν σχολιάσετε.

Η email διεύθυνση σας δεν θα δημοσιοποιηθεί ποτέ. Το πεδίο υπάρχει απλά για να σας στείλω κάποια απάντηση αν θελήσω. Να 'στε σίγουροι, απεχθάνομαι κι εγώ το spam.

XHTML ετικέτες που επιτρέπονται: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . Για τις παραθέσεις χρησιμοποιήστε <blockquote> HTML ετικέτες.

 


Reduce textarea size Increase textarea size


 
π
Τελευταία καταχώρηση: August 17 2008, 20:44 PDT