##// END OF EJS Templates
phase: add an archived phase...
phase: add an archived phase This phase allows for hidden changesets in the "user space". It differs from the "internal" phase which is intended for internal by-product only. There have been discussions at the 4.8 sprint to use such phase to speedup cleanup after history rewriting operation. Shipping it in the same release as the 'internal-phase' groups the associated `requires` entry. The important bit is to have support for this phase in the earliest version of mercurial possible. Adding the UI to manipulate this new phase later seems fine. The current plan for archived usage and user interface are as follow. On a repository with internal-phase on and evolution off: * history rewriting command set rewritten changeset in the archived phase. (This mean updating the cleanupnodes method). * keep `hg unbundle .hg/strip-backup/X.hg` as a way to restore changeset for now (backup bundle need to contains phase data) * [maybe] add a `hg strip --soft` advance flag (a light way to expose the feature without getting in the way of a better UI) Mercurial 4.8 freeze is too close to get the above in by then. We don't introduce a new repository `requirement` as we reuse the one introduced with the 'archived' phase during the 4.8 cycle.

File last commit:

r34464:718f7acd default
r40463:49c7b701 stable
Show More
state.py
134 lines | 4.4 KiB | text/x-python | PythonLexer
Martijn Pieters
fsmonitor: new experimental extension...
r28433 # state.py - fsmonitor persistent state
#
# Copyright 2013-2016 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import errno
import os
import socket
import struct
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205 from mercurial.i18n import _
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 from mercurial import (
pathutil,
util,
)
Martijn Pieters
fsmonitor: new experimental extension...
r28433
_version = 4
_versionformat = ">I"
class state(object):
def __init__(self, repo):
Durham Goode
fsmonitor: remove use of repo.opener...
r31215 self._vfs = repo.vfs
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self._ui = repo.ui
self._rootdir = pathutil.normasprefix(repo.root)
self._lastclock = None
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat(None)
Martijn Pieters
fsmonitor: new experimental extension...
r28433
Gregory Szorc
fsmonitor: use configitem...
r34464 self.mode = self._ui.config('fsmonitor', 'mode')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self.walk_on_invalidate = self._ui.configbool(
Gregory Szorc
fsmonitor: use configitem...
r34464 'fsmonitor', 'walk_on_invalidate')
self.timeout = float(self._ui.config('fsmonitor', 'timeout'))
Martijn Pieters
fsmonitor: new experimental extension...
r28433
def get(self):
try:
Durham Goode
fsmonitor: remove use of repo.opener...
r31215 file = self._vfs('fsmonitor.state', 'rb')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 except IOError as inst:
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat(None)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 if inst.errno != errno.ENOENT:
raise
return None, None, None
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat.fromfp(file)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 versionbytes = file.read(4)
if len(versionbytes) < 4:
self._ui.log(
'fsmonitor', 'fsmonitor: state file only has %d bytes, '
'nuking state\n' % len(versionbytes))
self.invalidate()
return None, None, None
try:
diskversion = struct.unpack(_versionformat, versionbytes)[0]
if diskversion != _version:
# different version, nuke state and start over
self._ui.log(
'fsmonitor', 'fsmonitor: version switch from %d to '
'%d, nuking state\n' % (diskversion, _version))
self.invalidate()
return None, None, None
state = file.read().split('\0')
# state = hostname\0clock\0ignorehash\0 + list of files, each
# followed by a \0
Simon Farnsworth
fsmonitor: be robust in the face of bad state...
r30539 if len(state) < 3:
self._ui.log(
'fsmonitor', 'fsmonitor: state file truncated (expected '
'3 chunks, found %d), nuking state\n', len(state))
self.invalidate()
return None, None, None
Martijn Pieters
fsmonitor: new experimental extension...
r28433 diskhostname = state[0]
hostname = socket.gethostname()
if diskhostname != hostname:
# file got moved to a different host
self._ui.log('fsmonitor', 'fsmonitor: stored hostname "%s" '
'different from current "%s", nuking state\n' %
(diskhostname, hostname))
self.invalidate()
return None, None, None
clock = state[1]
ignorehash = state[2]
# discard the value after the last \0
notefiles = state[3:-1]
finally:
file.close()
return clock, ignorehash, notefiles
def set(self, clock, ignorehash, notefiles):
if clock is None:
self.invalidate()
return
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 # Read the identity from the file on disk rather than from the open file
# pointer below, because the latter is actually a brand new file.
identity = util.filestat.frompath(self._vfs.join('fsmonitor.state'))
if identity != self._identity:
self._ui.debug('skip updating fsmonitor.state: identity mismatch\n')
return
Martijn Pieters
fsmonitor: new experimental extension...
r28433 try:
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 file = self._vfs('fsmonitor.state', 'wb', atomictemp=True,
checkambig=True)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 except (IOError, OSError):
self._ui.warn(_("warning: unable to write out fsmonitor state\n"))
return
Simon Farnsworth
fsmonitor: be robust in the face of bad state...
r30539 with file:
Martijn Pieters
fsmonitor: new experimental extension...
r28433 file.write(struct.pack(_versionformat, _version))
file.write(socket.gethostname() + '\0')
file.write(clock + '\0')
file.write(ignorehash + '\0')
if notefiles:
file.write('\0'.join(notefiles))
file.write('\0')
def invalidate(self):
try:
os.unlink(os.path.join(self._rootdir, '.hg', 'fsmonitor.state'))
except OSError as inst:
if inst.errno != errno.ENOENT:
raise
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat(None)
Martijn Pieters
fsmonitor: new experimental extension...
r28433
def setlastclock(self, clock):
self._lastclock = clock
def getlastclock(self):
return self._lastclock