mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
0d9f759213
Summary: Special command that fills optional metadata about infinitepush nodes. For now it's info about changed files + info about how many lines were added/removed. Since information is saved in json format it's easily extensible. It's a separate command so that we will be able to run it asynchronously: during infinitepush push separate `hg debugfillinfinitepushmetadata` process will be started. Push process won't wait for `debugfillinfinitepushmetadata` process. sqlindexapi will be implemented in the next diffs. Test Plan: arc unit Reviewers: #mercurial, quark Reviewed By: quark Subscribers: quark, mjpieters, medson, azich, #sourcecontrol Differential Revision: https://phabricator.intern.facebook.com/D5237547 Tasks: 19103180 Signature: t1:5237547:1497397211:569d1ffe3be37c8d14fb7e07e42cd085ad5686d4
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
# Copyright 2017 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.
|
|
|
|
import json
|
|
import os
|
|
import struct
|
|
import tempfile
|
|
|
|
from mercurial import (
|
|
error,
|
|
extensions,
|
|
)
|
|
from mercurial.node import hex
|
|
|
|
def isremotebooksenabled(ui):
|
|
return ('remotenames' in extensions._extensions and
|
|
ui.configbool('remotenames', 'bookmarks', True))
|
|
|
|
def encodebookmarks(bookmarks):
|
|
encoded = {}
|
|
for bookmark, node in bookmarks.iteritems():
|
|
encoded[bookmark] = node
|
|
dumped = json.dumps(encoded)
|
|
result = struct.pack('>i', len(dumped)) + dumped
|
|
return result
|
|
|
|
def downloadbundle(repo, unknownbinhead):
|
|
index = repo.bundlestore.index
|
|
store = repo.bundlestore.store
|
|
bundleid = index.getbundle(hex(unknownbinhead))
|
|
if bundleid is None:
|
|
raise error.Abort('%s head is not known' % hex(unknownbinhead))
|
|
bundleraw = store.read(bundleid)
|
|
return _makebundlefromraw(bundleraw)
|
|
|
|
def _makebundlefromraw(data):
|
|
fp = None
|
|
fd, bundlefile = tempfile.mkstemp()
|
|
try: # guards bundlefile
|
|
try: # guards fp
|
|
fp = os.fdopen(fd, 'wb')
|
|
fp.write(data)
|
|
finally:
|
|
fp.close()
|
|
except Exception:
|
|
try:
|
|
os.unlink(bundlefile)
|
|
except Exception:
|
|
# we would rather see the original exception
|
|
pass
|
|
raise
|
|
|
|
return bundlefile
|