2
# -*- encoding: utf-8 -*-
3
# Copyright (C) 2007 Guillermo Gonzalez
5
# The code taken from bzrlib is under: Copyright (C) 2005, 2006, 2007 Canonical Ltd
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25
This code is a modified copy from bzrlib.annotate
26
(see there for copyrights and licensing)
33
from bzrlib.annotate import _expand_annotations
35
# to support bzr < 1.8
36
from bzrlib.annotate import _annotate_file
39
from bzrlib.annotate import _annotations
40
from bzrlib.xml_serializer import _escape_cdata
41
from bzrlib import user_encoding
42
from bzrlib import osutils
44
empty_annotation = 'revno="" author="" date=""'
46
def annotate_file_xml(branch, rev_id, file_id, to_file=None,
47
show_ids=False, wt_root_path=None, file_path=None, full=False):
51
encoding = getattr(to_file, 'encoding', None) or \
52
osutils.get_terminal_encoding()
55
to_file.write('<?xml version="1.0"?>')
56
to_file.write(('<annotation workingtree-root="%s" %s>' % \
57
(wt_root_path.encode(encoding),
58
'file="%s"' % file_path)).encode(encoding, 'replace'))
60
annotations = _annotations(branch.repository, file_id, rev_id)
62
annotation = list(_annotate_file(branch, rev_id, file_id))
64
annotation = list(_expand_annotations(annotations, branch))
66
for (revno_str, author, date_str, line_rev_id,
67
text, origin) in _annotation_iter(annotation, annotations):
70
prevanno = _show_entry(to_file, prevanno, revno_str, author,
71
date_str, line_rev_id, text, origin)
72
to_file.write('</annotation>')
75
def _annotation_iter(annotation, annotations):
76
for ((revno_str, author, date_str, line_rev_id, text), \
77
(origin, text_dup)) in zip(annotation, annotations):
78
yield (revno_str, author, date_str, line_rev_id, text, origin)
81
def _show_entry(to_file, prevanno, revno_str, author,
82
date_str, line_rev_id, text, fid):
83
anno = 'revno="%s" author="%s" date="%s"' % \
84
(_escape_cdata(revno_str), _escape_cdata(author), date_str)
85
if anno.lstrip() == empty_annotation:
88
to_file.write('<entry %s fid="%s">%s</entry>' % \
89
(anno, fid, _escape_cdata(text)))
91
to_file.write('<entry %s>' % anno)
92
to_file.write('%s</entry>' % _escape_cdata(text))