hgext/journal.py
changeset 50928 d718eddf01d9
parent 50808 e9a2e1c77f28
equal deleted inserted replaced
50927:7a8ea1397816 50928:d718eddf01d9
   101 
   101 
   102 # hooks to record dirstate changes
   102 # hooks to record dirstate changes
   103 def wrapdirstate(orig, repo):
   103 def wrapdirstate(orig, repo):
   104     """Make journal storage available to the dirstate object"""
   104     """Make journal storage available to the dirstate object"""
   105     dirstate = orig(repo)
   105     dirstate = orig(repo)
   106     if util.safehasattr(repo, 'journal'):
   106     if hasattr(repo, 'journal'):
   107         _setupdirstate(repo, dirstate)
   107         _setupdirstate(repo, dirstate)
   108     return dirstate
   108     return dirstate
   109 
   109 
   110 
   110 
   111 def recorddirstateparents(dirstate, old, new):
   111 def recorddirstateparents(dirstate, old, new):
   112     """Records all dirstate parent changes in the journal."""
   112     """Records all dirstate parent changes in the journal."""
   113     old = list(old)
   113     old = list(old)
   114     new = list(new)
   114     new = list(new)
   115     if util.safehasattr(dirstate, 'journalstorage'):
   115     if hasattr(dirstate, 'journalstorage'):
   116         # only record two hashes if there was a merge
   116         # only record two hashes if there was a merge
   117         oldhashes = old[:1] if old[1] == dirstate._nodeconstants.nullid else old
   117         oldhashes = old[:1] if old[1] == dirstate._nodeconstants.nullid else old
   118         newhashes = new[:1] if new[1] == dirstate._nodeconstants.nullid else new
   118         newhashes = new[:1] if new[1] == dirstate._nodeconstants.nullid else new
   119         dirstate.journalstorage.record(
   119         dirstate.journalstorage.record(
   120             wdirparenttype, b'.', oldhashes, newhashes
   120             wdirparenttype, b'.', oldhashes, newhashes
   123 
   123 
   124 # hooks to record bookmark changes (both local and remote)
   124 # hooks to record bookmark changes (both local and remote)
   125 def recordbookmarks(orig, store, fp):
   125 def recordbookmarks(orig, store, fp):
   126     """Records all bookmark changes in the journal."""
   126     """Records all bookmark changes in the journal."""
   127     repo = store._repo
   127     repo = store._repo
   128     if util.safehasattr(repo, 'journal'):
   128     if hasattr(repo, 'journal'):
   129         oldmarks = bookmarks.bmstore(repo)
   129         oldmarks = bookmarks.bmstore(repo)
   130         all_marks = set(b for b, n in oldmarks.items())
   130         all_marks = set(b for b, n in oldmarks.items())
   131         all_marks.update(b for b, n in store.items())
   131         all_marks.update(b for b, n in store.items())
   132         for mark in sorted(all_marks):
   132         for mark in sorted(all_marks):
   133             value = store.get(mark, repo.nullid)
   133             value = store.get(mark, repo.nullid)
   183             fp.write(b'journal\n')
   183             fp.write(b'journal\n')
   184 
   184 
   185 
   185 
   186 def unsharejournal(orig, ui, repo, repopath):
   186 def unsharejournal(orig, ui, repo, repopath):
   187     """Copy shared journal entries into this repo when unsharing"""
   187     """Copy shared journal entries into this repo when unsharing"""
   188     if (
   188     if repo.path == repopath and repo.shared() and hasattr(repo, 'journal'):
   189         repo.path == repopath
       
   190         and repo.shared()
       
   191         and util.safehasattr(repo, 'journal')
       
   192     ):
       
   193         sharedrepo = hg.sharedreposource(repo)
   189         sharedrepo = hg.sharedreposource(repo)
   194         sharedfeatures = _readsharedfeatures(repo)
   190         sharedfeatures = _readsharedfeatures(repo)
   195         if sharedrepo and sharedfeatures > {b'journal'}:
   191         if sharedrepo and sharedfeatures > {b'journal'}:
   196             # there is a shared repository and there are shared journal entries
   192             # there is a shared repository and there are shared journal entries
   197             # to copy. move shared date over from source to destination but
   193             # to copy. move shared date over from source to destination but