mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
copytrace: push old move data
Summary: the option copytrace.pushmvdb allows to use the push command (with nothing to push) to send the whole database to the server and fill it Test Plan: I tested it manually with an XDB. I am not sure how to automate that see what's present in the XDB Reviewers: #sourcecontrol, rmcelroy Differential Revision: https://phabricator.fb.com/D2713157 Tasks: 8660367
This commit is contained in:
parent
9d05ef5950
commit
92d7a9147e
@ -60,17 +60,28 @@ def _pushb2movedata(pushop, bundler):
|
||||
add parts containing the movedata when pushing new commits -- client-side
|
||||
"""
|
||||
repo = pushop.repo
|
||||
ctxlist = _processctxlist(repo, pushop.remoteheads, pushop.revs)
|
||||
if ctxlist:
|
||||
try:
|
||||
dic = dbutil.retrieverawdata(repo, ctxlist)
|
||||
except Exception as e:
|
||||
dberror.logfailure(repo, e, "_pushb2movedata")
|
||||
return
|
||||
data = _encodedict(dic)
|
||||
repo.ui.status('moves for %d changesets pushed\n' % len(dic.keys()))
|
||||
|
||||
part = bundler.newpart('push:movedata', data=data, mandatory=False)
|
||||
try:
|
||||
# Send the whole database
|
||||
if repo.ui.configbool('copytrace', 'pushmvdb'):
|
||||
dic = dbutil.retrieveallrawdata(repo)
|
||||
# Send the moves related to the pushed commits
|
||||
else:
|
||||
ctxlist = _processctxlist(repo, pushop.remoteheads, pushop.revs)
|
||||
# Moves to send
|
||||
if ctxlist:
|
||||
dic = dbutil.retrieverawdata(repo, ctxlist)
|
||||
# No moves to send
|
||||
else:
|
||||
return
|
||||
except Exception as e:
|
||||
dberror.logfailure(repo, e, "_pushb2movedata")
|
||||
return
|
||||
|
||||
data = _encodedict(dic)
|
||||
repo.ui.status('moves for %d changesets pushed\n' % len(dic.keys()))
|
||||
|
||||
part = bundler.newpart('push:movedata', data=data, mandatory=False)
|
||||
|
||||
|
||||
@bundle2.parthandler('push:movedata')
|
||||
@ -125,6 +136,7 @@ def _handlemovedatarequest(op, inpart):
|
||||
except Exception as e:
|
||||
dberror.logfailure(op.repo, e, "_handlemovedatarequest-pull")
|
||||
|
||||
|
||||
def _processctxlist(repo, remoteheads, localheads):
|
||||
"""
|
||||
Processes the ctx list between remoteheads and localheads
|
||||
|
@ -63,6 +63,12 @@ def _sqlcmds(name, remote):
|
||||
'FROM Moves ' + \
|
||||
'WHERE hash IN (%s) and repo = %s;'
|
||||
|
||||
elif name == 'retrieveallraw':
|
||||
if not remote:
|
||||
return 'SELECT DISTINCT hash, source, destination, mv ' + \
|
||||
'FROM Moves ' + \
|
||||
'WHERE repo = ?'
|
||||
|
||||
elif name == 'retrievehashes':
|
||||
if not remote:
|
||||
return 'SELECT DISTINCT hash ' + \
|
||||
@ -245,6 +251,22 @@ def retrievedatapkg(repo, ctxlist, move=False, askserver=True, addmissing=True):
|
||||
return ret
|
||||
|
||||
|
||||
def _builddict(rows):
|
||||
"""
|
||||
building {ctxhash: [src, dst, mv]} from the database rows
|
||||
"""
|
||||
ret = {}
|
||||
for ctxhash, src, dst, mv in rows:
|
||||
# No move or No copy
|
||||
if not src and not dst:
|
||||
src = 'None'
|
||||
dst = 'None'
|
||||
ret.setdefault(ctxhash.encode('utf8'), []).append((src.encode('utf8'),
|
||||
dst.encode('utf8'), mv.encode('utf8')))
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def retrieverawdata(repo, ctxlist):
|
||||
"""
|
||||
retrieves {ctxhash: [src, dst, mv]} for ctxhash in ctxlist for moves or
|
||||
@ -261,17 +283,22 @@ def retrieverawdata(repo, ctxlist):
|
||||
all_rows = cursor.fetchall()
|
||||
_close(conn, cursor)
|
||||
|
||||
ret = {}
|
||||
# Building the mvdict and cpdict for each ctxhash:
|
||||
for ctxhash, src, dst, mv in all_rows:
|
||||
# No move or No copy
|
||||
if not src and not dst:
|
||||
src = 'None'
|
||||
dst = 'None'
|
||||
ret.setdefault(ctxhash.encode('utf8'), []).append((src.encode('utf8'),
|
||||
dst.encode('utf8'), mv.encode('utf8')))
|
||||
return _builddict(all_rows)
|
||||
|
||||
return ret
|
||||
|
||||
def retrieveallrawdata(repo):
|
||||
"""
|
||||
retrieves all {ctxhash: [src, dst, mv]} in the local database
|
||||
"""
|
||||
dbname, conn, cursor = _connect(repo)
|
||||
|
||||
# Returns hash, src, dst, mv
|
||||
cursor.execute(_sqlcmds('retrieveallraw', repo.copytraceremote),
|
||||
[repo.root])
|
||||
all_rows = cursor.fetchall()
|
||||
_close(conn, cursor)
|
||||
|
||||
return _builddict(all_rows)
|
||||
|
||||
|
||||
def removectx(repo, ctx):
|
||||
|
Loading…
Reference in New Issue
Block a user