comparison mercurial/scmutil.py @ 41937:232d4b9d391a

uncommit: move _movedirstate() to scmutil for reuse The function should be applicable generically when moving from one commit to another. I'll try to add more callers when I find time. I'm not convinced it's handling all the cases correctly, but we should have a generic function for this kind of operation, so I think it belongs somewhere in core (not in the uncommit extension). Differential Revision: https://phab.mercurial-scm.org/D6119
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 11 Mar 2019 09:42:29 -0700
parents 64de5f44eec3
children ad4a3e2eedb3
comparison
equal deleted inserted replaced
41936:a791623458ef 41937:232d4b9d391a
26 wdirid, 26 wdirid,
27 wdirrev, 27 wdirrev,
28 ) 28 )
29 29
30 from . import ( 30 from . import (
31 copies as copiesmod,
31 encoding, 32 encoding,
32 error, 33 error,
33 match as matchmod, 34 match as matchmod,
34 obsolete, 35 obsolete,
35 obsutil, 36 obsutil,
1251 if repo.dirstate[dst] in '?r' and not dryrun: 1252 if repo.dirstate[dst] in '?r' and not dryrun:
1252 wctx.add([dst]) 1253 wctx.add([dst])
1253 elif not dryrun: 1254 elif not dryrun:
1254 wctx.copy(origsrc, dst) 1255 wctx.copy(origsrc, dst)
1255 1256
1257 def movedirstate(repo, newctx, match=None):
1258 """Move the dirstate to newctx and adjust it as necessary."""
1259 oldctx = repo['.']
1260 ds = repo.dirstate
1261 ds.setparents(newctx.node(), nullid)
1262 copies = dict(ds.copies())
1263 s = newctx.status(oldctx, match=match)
1264 for f in s.modified:
1265 if ds[f] == 'r':
1266 # modified + removed -> removed
1267 continue
1268 ds.normallookup(f)
1269
1270 for f in s.added:
1271 if ds[f] == 'r':
1272 # added + removed -> unknown
1273 ds.drop(f)
1274 elif ds[f] != 'a':
1275 ds.add(f)
1276
1277 for f in s.removed:
1278 if ds[f] == 'a':
1279 # removed + added -> normal
1280 ds.normallookup(f)
1281 elif ds[f] != 'r':
1282 ds.remove(f)
1283
1284 # Merge old parent and old working dir copies
1285 oldcopies = copiesmod.pathcopies(newctx, oldctx, match)
1286 oldcopies.update(copies)
1287 copies = dict((dst, oldcopies.get(src, src))
1288 for dst, src in oldcopies.iteritems())
1289 # Adjust the dirstate copies
1290 for dst, src in copies.iteritems():
1291 if (src not in newctx or dst in newctx or ds[dst] != 'a'):
1292 src = None
1293 ds.copy(src, dst)
1294
1256 def writerequires(opener, requirements): 1295 def writerequires(opener, requirements):
1257 with opener('requires', 'w', atomictemp=True) as fp: 1296 with opener('requires', 'w', atomictemp=True) as fp:
1258 for r in sorted(requirements): 1297 for r in sorted(requirements):
1259 fp.write("%s\n" % r) 1298 fp.write("%s\n" % r)
1260 1299