def _unpack_revision(self, elt): """XML Element -> Revision object""" format = elt.get('format') format_num = self.format_num if self.revision_format_num is not None: format_num = self.revision_format_num if format is not None: if format != format_num: raise BzrError("invalid format version %r on revision" % format) get_cached = _get_utf8_or_ascii rev = Revision(committer = elt.get('committer'), timestamp = float(elt.get('timestamp')), revision_id = get_cached(elt.get('revision_id')), inventory_sha1 = elt.get('inventory_sha1') ) parents = elt.find('parents') or [] for p in parents: rev.parent_ids.append(get_cached(p.get('revision_id'))) self._unpack_revision_properties(elt, rev) v = elt.get('timezone') if v is None: rev.timezone = 0 else: rev.timezone = int(v) rev.message = elt.findtext('message') # text of <message> return rev
def _unpack_revision(self, elt): """XML Element -> Revision object""" format = elt.get('format') format_num = self.format_num if self.revision_format_num is not None: format_num = self.revision_format_num if format is not None: if format != format_num: raise BzrError("invalid format version %r on revision" % format) get_cached = _get_utf8_or_ascii rev = Revision(committer=elt.get('committer'), timestamp=float(elt.get('timestamp')), revision_id=get_cached(elt.get('revision_id')), inventory_sha1=elt.get('inventory_sha1')) parents = elt.find('parents') or [] for p in parents: rev.parent_ids.append(get_cached(p.get('revision_id'))) self._unpack_revision_properties(elt, rev) v = elt.get('timezone') if v is None: rev.timezone = 0 else: rev.timezone = int(v) rev.message = elt.findtext('message') # text of <message> return rev
def test_roundtrips_non_ascii(self): rev = Revision("revid1") rev.message = u"\n\xe5me" rev.committer = u'Erik B\xe5gfors' rev.timestamp = 1242385452 rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7" rev.timezone = 3600 self.assertRoundTrips(chk_bencode_serializer, rev)
def test_roundtrips_xml_invalid_chars(self): rev = Revision("revid1") rev.message = "\t\ue000" rev.committer = u'Erik B\xe5gfors' rev.timestamp = 1242385452 rev.timezone = 3600 rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7" self.assertRoundTrips(chk_bencode_serializer, rev)
def test_roundtrips_non_ascii(self): rev = Revision("revid1") rev.message = u"\n\xe5me" rev.committer = u'Erik B\xe5gfors' rev.timestamp = 1242385452 rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7" rev.timezone = 3600 self.assertRoundTrips(chk_bencode_serializer, rev)
def test_roundtrips_xml_invalid_chars(self): rev = Revision("revid1") rev.message = "\t\ue000" rev.committer = u'Erik B\xe5gfors' rev.timestamp = 1242385452 rev.timezone = 3600 rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7" self.assertRoundTrips(chk_bencode_serializer, rev)
def annotate_file_tree(tree, file_id, to_file, verbose=False, full=False, show_ids=False, branch=None): """Annotate file_id in a tree. The tree should already be read_locked() when annotate_file_tree is called. :param tree: The tree to look for revision numbers and history from. :param file_id: The file_id to annotate. :param to_file: The file to output the annotation to. :param verbose: Show all details rather than truncating to ensure reasonable text width. :param full: XXXX Not sure what this does. :param show_ids: Show revision ids in the annotation output. :param branch: Branch to use for revision revno lookups """ if branch is None: branch = tree.branch if to_file is None: to_file = sys.stdout # Handle the show_ids case annotations = list(tree.annotate_iter(file_id)) if show_ids: return _show_id_annotations(annotations, to_file, full) if not getattr(tree, "get_revision_id", False): # Create a virtual revision to represent the current tree state. # Should get some more pending commit attributes, like pending tags, # bugfixes etc. current_rev = Revision(CURRENT_REVISION) current_rev.parent_ids = tree.get_parent_ids() try: current_rev.committer = branch.get_config_stack().get('email') except errors.NoWhoami: current_rev.committer = 'local user' current_rev.message = "?" current_rev.timestamp = round(time.time(), 3) current_rev.timezone = osutils.local_time_offset() else: current_rev = None annotation = list(_expand_annotations(annotations, branch, current_rev)) _print_annotations(annotation, verbose, to_file, full)
def annotate_file_tree(tree, file_id, to_file, verbose=False, full=False, show_ids=False, branch=None): """Annotate file_id in a tree. The tree should already be read_locked() when annotate_file_tree is called. :param tree: The tree to look for revision numbers and history from. :param file_id: The file_id to annotate. :param to_file: The file to output the annotation to. :param verbose: Show all details rather than truncating to ensure reasonable text width. :param full: XXXX Not sure what this does. :param show_ids: Show revision ids in the annotation output. :param branch: Branch to use for revision revno lookups """ if branch is None: branch = tree.branch if to_file is None: to_file = sys.stdout # Handle the show_ids case annotations = list(tree.annotate_iter(file_id)) if show_ids: return _show_id_annotations(annotations, to_file, full) if not getattr(tree, "get_revision_id", False): # Create a virtual revision to represent the current tree state. # Should get some more pending commit attributes, like pending tags, # bugfixes etc. current_rev = Revision(CURRENT_REVISION) current_rev.parent_ids = tree.get_parent_ids() try: current_rev.committer = branch.get_config_stack().get('email') except errors.NoWhoami: current_rev.committer = 'local user' current_rev.message = "?" current_rev.timestamp = round(time.time(), 3) current_rev.timezone = osutils.local_time_offset() else: current_rev = None annotation = list(_expand_annotations(annotations, branch, current_rev)) _print_annotations(annotation, verbose, to_file, full)
def _unpack_revision(self, elt): """XML Element -> Revision object""" # <changeset> is deprecated... if elt.tag not in ('revision', 'changeset'): raise BzrError("unexpected tag in revision file: %r" % elt) rev = Revision(committer = elt.get('committer'), timestamp = float(elt.get('timestamp')), revision_id = elt.get('revision_id'), inventory_id = elt.get('inventory_id'), inventory_sha1 = elt.get('inventory_sha1') ) precursor = elt.get('precursor') precursor_sha1 = elt.get('precursor_sha1') pelts = elt.find('parents') if pelts: for p in pelts: rev.parent_ids.append(p.get('revision_id')) rev.parent_sha1s.append(p.get('revision_sha1')) if precursor: # must be consistent prec_parent = rev.parent_ids[0] elif precursor: # revisions written prior to 0.0.5 have a single precursor # give as an attribute rev.parent_ids.append(precursor) rev.parent_sha1s.append(precursor_sha1) v = elt.get('timezone') rev.timezone = v and int(v) rev.message = elt.findtext('message') # text of <message> return rev
def _unpack_revision(self, elt): """XML Element -> Revision object""" # <changeset> is deprecated... if elt.tag not in ('revision', 'changeset'): raise BzrError("unexpected tag in revision file: %r" % elt) rev = Revision(committer=elt.get('committer'), timestamp=float(elt.get('timestamp')), revision_id=elt.get('revision_id'), inventory_id=elt.get('inventory_id'), inventory_sha1=elt.get('inventory_sha1')) precursor = elt.get('precursor') precursor_sha1 = elt.get('precursor_sha1') pelts = elt.find('parents') if pelts: for p in pelts: rev.parent_ids.append(p.get('revision_id')) rev.parent_sha1s.append(p.get('revision_sha1')) if precursor: # must be consistent prec_parent = rev.parent_ids[0] elif precursor: # revisions written prior to 0.0.5 have a single precursor # give as an attribute rev.parent_ids.append(precursor) rev.parent_sha1s.append(precursor_sha1) v = elt.get('timezone') rev.timezone = v and int(v) rev.message = elt.findtext('message') # text of <message> return rev