Skip to content

Commit

Permalink
remove dead code written for format migration
Browse files Browse the repository at this point in the history
Summary: BE - remove dead code

Reviewed By: markbt

Differential Revision: D51196520

fbshipit-source-id: 447b84788eac1ec7f9a0d4c3bcd179623d73178b
  • Loading branch information
Liubov Dmitrieva authored and facebook-github-bot committed Nov 10, 2023
1 parent 11c3d89 commit b55c78c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
1 change: 0 additions & 1 deletion eden/scm/sapling/ext/commitcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def extsetup(ui):
localrepo.localrepository._wlockfreeprefix.add(backuplock.progressfilename)
localrepo.localrepository._wlockfreeprefix.add(backupstate.BackupState.directory)
localrepo.localrepository._wlockfreeprefix.add(background._autobackupstatefile)
localrepo.localrepository._lockfreeprefix.add(syncstate.SyncState.v1prefix)
localrepo.localrepository._lockfreeprefix.add(sync._syncstatusfile)

def wrapsmartlog(loaded):
Expand Down
45 changes: 0 additions & 45 deletions eden/scm/sapling/ext/commitcloud/syncstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ class SyncState:
# best with fixed filenames.
v2filename = "cloudsyncstate"

# Version 1: a JSON file "commitcloudstate.<workspace>.<hash>" per
# workspace.
v1prefix = "commitcloudstate."

@classmethod
def _v1filename(cls, workspacename):
"""filename for workspace, only for compatibility"""
# make a unique valid filename
return (
cls.v1prefix
+ "".join(x for x in workspacename if x.isalnum())
+ ".%s" % (hashlib.sha256(encodeutf8(workspacename)).hexdigest()[0:5])
)

@classmethod
def erasestate(cls, repo, workspacename):
# update v2 states
Expand All @@ -51,10 +37,6 @@ def erasestate(cls, repo, workspacename):
if workspacename in states:
del states[workspacename]
cls.savev2states(repo.svfs, states)
# update v1 states
filename = cls._v1filename(workspacename)
# clean up the current state in force recover mode
repo.svfs.tryunlink(filename)

@classmethod
def movestate(cls, repo, workspacename, new_workspacename):
Expand All @@ -64,10 +46,6 @@ def movestate(cls, repo, workspacename, new_workspacename):
if workspacename in states:
states[new_workspacename] = states[workspacename]
cls.savev2states(repo.svfs, states)
# update v1 states
src = cls._v1filename(workspacename)
dst = cls._v1filename(new_workspacename)
repo.svfs.rename(src, dst)

@classmethod
def loadv2states(cls, svfs):
Expand All @@ -86,30 +64,12 @@ def savev2states(cls, svfs, states):

def __init__(self, repo, workspacename):
self.workspacename = workspacename
self.v1filename = self._v1filename(workspacename)
self.repo = repo
self.prevstate = None

# Try v2 state first.
states = self.loadv2states(repo.svfs)
data = states.get(workspacename)

# If v2 state is missing, try load from v1 state.
if data is None and repo.svfs.exists(self.v1filename):
# Migra v1 state to v2 so v2 state gets used going forward.
with repo.lock(), repo.transaction("cloudstate"):
# Reload since v2 states might have changed.
states = self.loadv2states(repo.svfs)
with repo.svfs.open(self.v1filename, "r") as f:
try:
data = json.load(f)
except Exception:
raise ccerror.InvalidWorkspaceDataError(
repo.ui, _("failed to parse %s") % self.v1filename
)
states[workspacename] = data
self.savev2states(repo.svfs, states)

if data is not None:
self.version = data["version"]
self.heads = [ensurestr(h) for h in data["heads"]]
Expand Down Expand Up @@ -176,11 +136,6 @@ def update(value, orig):
"omittedremotebookmarks": omittedremotebookmarks,
"lastupdatetime": time.time(),
}
tr.addfilegenerator(
self.v1filename,
[self.v1filename],
lambda f, data=data: f.write(encodeutf8(json.dumps(data))),
)
svfs = tr._vfsmap[""]
states = self.loadv2states(svfs)
states[self.workspacename] = data
Expand Down

0 comments on commit b55c78c

Please sign in to comment.