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 = [ ("format", 10), ("committer", encode_utf8(rev.committer)[0]), ] if rev.timezone is not None: ret.append(("timezone", rev.timezone)) # For bzr revisions, the most common property is just 'branch-nick' # which changes infrequently. revprops = {} for key, value in rev.properties.iteritems(): revprops[key] = encode_utf8(value)[0] ret.append(('properties', revprops)) ret.extend([ ("timestamp", "%.3f" % rev.timestamp), ("revision-id", rev.revision_id), ("parent-ids", rev.parent_ids), ("inventory-sha1", rev.inventory_sha1), ("message", encode_utf8(rev.message)[0]), ]) return bencode.bencode(ret)
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, [(name, )]) if metadata['storage_kind'] != 'header': self._container.add_bytes_record(bytes, [])
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. """ branches = self._bzrdir.get_branches() ret = {} for name, b in branches.iteritems(): if name is None: name = "" ret[name] = ("branch", b._format.network_name()) return SuccessfulSmartServerResponse( ("success", ), bencode.bencode(ret))
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. """ branches = self._bzrdir.get_branches() ret = {} for name, b in branches.iteritems(): if name is None: name = "" ret[name] = ("branch", b._format.network_name()) return SuccessfulSmartServerResponse(("success", ), bencode.bencode(ret))
def save(self, tree, branch): # We store in branch's config, which can be a problem if two gcommit # are done in two checkouts of one single branch (comments overwrite # each other). Ideally should be in working tree. But uncommit does # not always have a working tree, though it always has a branch. # 'tree' argument is for the future config = branch.get_config() # should it be named "gtk_" or some more neutral name ("gui_" ?) to # be compatible with qbzr in the future? config.set_user_option('gtk_global_commit_message', self.global_message) # bencode() does not know unicode objects but set_user_option() # requires one: config.set_user_option( 'gtk_file_commit_messages', bencode.bencode(self.file_messages).decode('UTF-8'))
def do_end(self): self.queue.put(StopIteration) if self.insert_thread is not None: self.insert_thread.join() if not self.insert_ok: exc_info = self.insert_exception raise exc_info[0], exc_info[1], exc_info[2] write_group_tokens, missing_keys = self.insert_result if write_group_tokens or missing_keys: # bzip needed? missing keys should typically be a small set. # Should this be a streaming body response ? missing_keys = sorted(missing_keys) bytes = bencode.bencode((write_group_tokens, missing_keys)) self.repository.unlock() return SuccessfulSmartServerResponse(('missing-basis', bytes)) else: self.repository.unlock() return SuccessfulSmartServerResponse(('ok', ))
def test_create_view_with_file_info(self): tree = self.make_branch_and_memory_tree('test') file_info = bencode.bencode([{'file_id':'root-id', 'path':'', 'message':'test-message\n'}]) tree.lock_write() try: tree.add([''], ['root-id']) tree.commit('test', rev_id='A', revprops={'file-info': file_info}) finally: tree.unlock() b = tree.branch rv = revisionview.RevisionView(b) self.addCleanup(rv.destroy) rev = b.repository.get_revision('A') rv.set_revision(rev) self.assertEqual(rev.committer, rv.committer.get_text()) self.assertTrue(rv.file_info_box.get_property('visible')) self.assertBufferText('\ntest-message\n', rv.file_info_buffer)
def __init__(self, data): super(bResponse, self).__init__( bencode.bencode(data), mimetype='text/plain' )
def _dict_to_torrent(self, data): dictionary = utf8_dict(self._torrent_dict(data)) dictionary['info']['pieces'] = binascii.unhexlify( dictionary['info']['pieces'] ) return bencode.bencode(dictionary)
def _info_hash(self): return sha1(bencode.bencode( bencode.bdecode(self.torrent_file).get('info') )).hexdigest()