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:
Cecile Berillon 2015-12-02 17:45:01 -08:00
parent 9d05ef5950
commit 92d7a9147e
2 changed files with 59 additions and 20 deletions

View File

@ -60,17 +60,28 @@ def _pushb2movedata(pushop, bundler):
add parts containing the movedata when pushing new commits -- client-side add parts containing the movedata when pushing new commits -- client-side
""" """
repo = pushop.repo 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') @bundle2.parthandler('push:movedata')
@ -125,6 +136,7 @@ def _handlemovedatarequest(op, inpart):
except Exception as e: except Exception as e:
dberror.logfailure(op.repo, e, "_handlemovedatarequest-pull") dberror.logfailure(op.repo, e, "_handlemovedatarequest-pull")
def _processctxlist(repo, remoteheads, localheads): def _processctxlist(repo, remoteheads, localheads):
""" """
Processes the ctx list between remoteheads and localheads Processes the ctx list between remoteheads and localheads

View File

@ -63,6 +63,12 @@ def _sqlcmds(name, remote):
'FROM Moves ' + \ 'FROM Moves ' + \
'WHERE hash IN (%s) and repo = %s;' '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': elif name == 'retrievehashes':
if not remote: if not remote:
return 'SELECT DISTINCT hash ' + \ return 'SELECT DISTINCT hash ' + \
@ -245,6 +251,22 @@ def retrievedatapkg(repo, ctxlist, move=False, askserver=True, addmissing=True):
return ret 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): def retrieverawdata(repo, ctxlist):
""" """
retrieves {ctxhash: [src, dst, mv]} for ctxhash in ctxlist for moves or retrieves {ctxhash: [src, dst, mv]} for ctxhash in ctxlist for moves or
@ -261,17 +283,22 @@ def retrieverawdata(repo, ctxlist):
all_rows = cursor.fetchall() all_rows = cursor.fetchall()
_close(conn, cursor) _close(conn, cursor)
ret = {} return _builddict(all_rows)
# 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 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): def removectx(repo, ctx):