예제 #1
0
 def write_revision_to_string(self, rev):
     encode_utf8 = cache_utf8._utf8_encode
     # Use a list of tuples rather than a dict
     # This lets us control the ordering, so that we are able to create
     # smaller deltas
     ret = [
         (b"format", 10),
         (b"committer", encode_utf8(rev.committer)[0]),
     ]
     if rev.timezone is not None:
         ret.append((b"timezone", rev.timezone))
     # For bzr revisions, the most common property is just 'branch-nick'
     # which changes infrequently.
     revprops = {}
     for key, value in rev.properties.items():
         revprops[encode_utf8(key)[0]] = encode_utf8(value, 'surrogateescape')[0]
     ret.append((b'properties', revprops))
     ret.extend([
         (b"timestamp", b"%.3f" % rev.timestamp),
         (b"revision-id", rev.revision_id),
         (b"parent-ids", rev.parent_ids),
         (b"inventory-sha1", rev.inventory_sha1),
         (b"message", encode_utf8(rev.message)[0]),
     ])
     return bencode.bencode(ret)
예제 #2
0
 def do_with_branch(self, branch):
     all_reference_info = branch._get_all_reference_info()
     content = bencode.bencode([
         (key, value[0].encode('utf-8'),
          value[1].encode('utf-8') if value[1] else b'')
         for (key, value) in all_reference_info.items()
     ])
     return SuccessfulSmartServerResponse((b'ok', ), content)
예제 #3
0
 def _extract_hg_metadata(self, rev, message):
     (message, renames, branch, extra) = extract_hg_metadata(message)
     if branch is not None:
         rev.properties[u'hg:extra:branch'] = branch
     for name, value in extra.items():
         rev.properties[u'hg:extra:' + name] = base64.b64encode(value)
     if renames:
         rev.properties[u'hg:renames'] = base64.b64encode(
             bencode.bencode([(new, old)
                              for (old, new) in renames.items()]))
     return message
예제 #4
0
파일: v4.py 프로젝트: breezy-team/breezy
    def _add_record(self, bytes, metadata, repo_kind, revision_id, file_id):
        """Add a bundle record to the container.

        Most bundle records are recorded as header/body pairs, with the
        body being nameless.  Records with storage_kind 'header' have no
        body.
        """
        name = self.encode_name(repo_kind, revision_id, file_id)
        encoded_metadata = bencode.bencode(metadata)
        self._container.add_bytes_record([encoded_metadata],
                                         len(encoded_metadata), [(name, )])
        if metadata[b'storage_kind'] != b'header':
            self._container.add_bytes_record([bytes], len(bytes), [])
예제 #5
0
    def do_bzrdir_request(self):
        """Get the branches in a control directory.

        The body is a bencoded dictionary, with values similar to the return
        value of the open branch request.
        """
        branch_names = self._bzrdir.branch_names()
        ret = {}
        for name in branch_names:
            if name is None:
                name = b""
            branch_ref = self._bzrdir.get_branch_reference(name=name)
            if branch_ref is not None:
                branch_ref = urlutils.relative_url(self._bzrdir.user_url,
                                                   branch_ref)
                value = (b"ref", branch_ref.encode('utf-8'))
            else:
                b = self._bzrdir.open_branch(name=name, ignore_fallbacks=True)
                value = (b"branch", b._format.network_name())
            ret[name.encode('utf-8')] = value
        return SuccessfulSmartServerResponse((b"success", ),
                                             bencode.bencode(ret))
예제 #6
0
 def save(self):
     import fastbencode as bencode
     with open(self._filename + '.mpidx', 'wb') as f:
         f.write(
             bencode.bencode(
                 (self._parents, list(self._snapshots), self._diff_offset)))
예제 #7
0
 def make_records(self, attribs, contents):
     records = [((((b'attribs'), ), ), bencode.bencode(attribs))]
     records.extend([(((n, k), ), c) for n, k, c in contents])
     return records
예제 #8
0
 def import_unusual_file_modes(self, rev, unusual_file_modes):
     if unusual_file_modes:
         ret = [(path, unusual_file_modes[path])
                for path in sorted(unusual_file_modes.keys())]
         rev.properties[u'file-modes'] = bencode.bencode(ret)
예제 #9
0
 def _serialize_tag_dict(self, tag_dict):
     td = dict((k.encode('utf-8'), v) for k, v in tag_dict.items())
     return bencode.bencode(td)
예제 #10
0
파일: shelf.py 프로젝트: breezy-team/breezy
 def metadata_record(serializer, revision_id, message=None):
     metadata = {b'revision_id': revision_id}
     if message is not None:
         metadata[b'message'] = message.encode('utf-8')
     return serializer.bytes_record(bencode.bencode(metadata),
                                    ((b'metadata', ), ))