tests/test-hgk.t
author Adrian Buehlmann <adrian@cadifra.com>
Wed, 18 May 2011 09:12:27 +0200
changeset 14413 5ef18e28df19
parent 12431 d911aa2b8570
child 16913 f2719b387380
permissions -rw-r--r--
pure: provide more correct implementation of posixfile for Windows requires ctypes Why is posixfile a class? Because the implementation needs to use the Python library call os.fdopen [1], which sets the 'name' attribute on the Python file object it creates to the mostly meaningless string '<fdopen>', since file descriptors don't have a name. But users of posixfile depend on the name attribute [2] being set to a proper value, like Python's built-in 'open' function sets it on file objects. Python file's name attribute is read-only, so we can't just assign to it after the file object has alrady been created. To solve this problem, we save the name of the file on a wrapper object, and delegate the file function calls to the wrapped (private) file object using __getattr__. [1] http://docs.python.org/library/os.html#os.fdopen [2] http://docs.python.org/library/stdtypes.html#file.name

Minimal hgk check

  $ echo "[extensions]" >> $HGRCPATH
  $ echo "hgk=" >> $HGRCPATH
  $ hg init repo
  $ cd repo
  $ echo a > a
  $ hg ci -Am adda
  adding a
  $ hg debug-cat-file commit 0
  tree a0c8bcbbb45c
  parent 000000000000
  author test 0 0
  committer test 0 0
  revision 0
  branch default
  
  adda