hgext/journal.py
changeset 46113 59fa3890d40a
parent 43506 9f70512ae2cf
child 47012 d55b71393907
equal deleted inserted replaced
46112:d6afa9c149c3 46113:59fa3890d40a
    17 import errno
    17 import errno
    18 import os
    18 import os
    19 import weakref
    19 import weakref
    20 
    20 
    21 from mercurial.i18n import _
    21 from mercurial.i18n import _
       
    22 from mercurial.node import (
       
    23     bin,
       
    24     hex,
       
    25     nullid,
       
    26 )
    22 
    27 
    23 from mercurial import (
    28 from mercurial import (
    24     bookmarks,
    29     bookmarks,
    25     cmdutil,
    30     cmdutil,
    26     dispatch,
    31     dispatch,
    29     extensions,
    34     extensions,
    30     hg,
    35     hg,
    31     localrepo,
    36     localrepo,
    32     lock,
    37     lock,
    33     logcmdutil,
    38     logcmdutil,
    34     node,
       
    35     pycompat,
    39     pycompat,
    36     registrar,
    40     registrar,
    37     util,
    41     util,
    38 )
    42 )
    39 from mercurial.utils import (
    43 from mercurial.utils import (
   111     """Records all dirstate parent changes in the journal."""
   115     """Records all dirstate parent changes in the journal."""
   112     old = list(old)
   116     old = list(old)
   113     new = list(new)
   117     new = list(new)
   114     if util.safehasattr(dirstate, 'journalstorage'):
   118     if util.safehasattr(dirstate, 'journalstorage'):
   115         # only record two hashes if there was a merge
   119         # only record two hashes if there was a merge
   116         oldhashes = old[:1] if old[1] == node.nullid else old
   120         oldhashes = old[:1] if old[1] == nullid else old
   117         newhashes = new[:1] if new[1] == node.nullid else new
   121         newhashes = new[:1] if new[1] == nullid else new
   118         dirstate.journalstorage.record(
   122         dirstate.journalstorage.record(
   119             wdirparenttype, b'.', oldhashes, newhashes
   123             wdirparenttype, b'.', oldhashes, newhashes
   120         )
   124         )
   121 
   125 
   122 
   126 
   125     """Records all bookmark changes in the journal."""
   129     """Records all bookmark changes in the journal."""
   126     repo = store._repo
   130     repo = store._repo
   127     if util.safehasattr(repo, 'journal'):
   131     if util.safehasattr(repo, 'journal'):
   128         oldmarks = bookmarks.bmstore(repo)
   132         oldmarks = bookmarks.bmstore(repo)
   129         for mark, value in pycompat.iteritems(store):
   133         for mark, value in pycompat.iteritems(store):
   130             oldvalue = oldmarks.get(mark, node.nullid)
   134             oldvalue = oldmarks.get(mark, nullid)
   131             if value != oldvalue:
   135             if value != oldvalue:
   132                 repo.journal.record(bookmarktype, mark, oldvalue, value)
   136                 repo.journal.record(bookmarktype, mark, oldvalue, value)
   133     return orig(store, fp)
   137     return orig(store, fp)
   134 
   138 
   135 
   139 
   246             oldhashes,
   250             oldhashes,
   247             newhashes,
   251             newhashes,
   248         ) = line.split(b'\n')
   252         ) = line.split(b'\n')
   249         timestamp, tz = time.split()
   253         timestamp, tz = time.split()
   250         timestamp, tz = float(timestamp), int(tz)
   254         timestamp, tz = float(timestamp), int(tz)
   251         oldhashes = tuple(node.bin(hash) for hash in oldhashes.split(b','))
   255         oldhashes = tuple(bin(hash) for hash in oldhashes.split(b','))
   252         newhashes = tuple(node.bin(hash) for hash in newhashes.split(b','))
   256         newhashes = tuple(bin(hash) for hash in newhashes.split(b','))
   253         return cls(
   257         return cls(
   254             (timestamp, tz),
   258             (timestamp, tz),
   255             user,
   259             user,
   256             command,
   260             command,
   257             namespace,
   261             namespace,
   261         )
   265         )
   262 
   266 
   263     def __bytes__(self):
   267     def __bytes__(self):
   264         """bytes representation for storage"""
   268         """bytes representation for storage"""
   265         time = b' '.join(map(pycompat.bytestr, self.timestamp))
   269         time = b' '.join(map(pycompat.bytestr, self.timestamp))
   266         oldhashes = b','.join([node.hex(hash) for hash in self.oldhashes])
   270         oldhashes = b','.join([hex(hash) for hash in self.oldhashes])
   267         newhashes = b','.join([node.hex(hash) for hash in self.newhashes])
   271         newhashes = b','.join([hex(hash) for hash in self.newhashes])
   268         return b'\n'.join(
   272         return b'\n'.join(
   269             (
   273             (
   270                 time,
   274                 time,
   271                 self.user,
   275                 self.user,
   272                 self.command,
   276                 self.command,