67
67
self.base_tree = self.branch.revision_tree(self.changeset_info.base)
69
def guess_text_id(tree, file_id, rev_id, modified=True):
70
"""This returns the estimated text_id for a given file.
71
The idea is that in general the text_id should be the id last
72
revision which modified the file.
74
:param tree: This should be the base tree for a changeset, since that
75
is all the target has for guessing.
76
:param file_id: The file id to guess the text_id for.
77
:param rev_id: The target revision id
78
:param modified: Was the file modified between base and target?
80
from bzrlib.errors import BzrError
82
# If the file was modified in an intermediate stage
83
# (not in the final target), this won't be correct
84
# but it is our best guess.
85
# TODO: In the current code, text-ids are randomly generated
86
# using the filename as the base. In the future they will
87
# probably follow this format.
88
return file_id + '-' + rev_id
89
# The file was not actually modified in this changeset
90
# so the text_id should be equal to it's previous value
91
if not file_id in tree.inventory:
92
raise BzrError('Unable to generate text_id for file_id {%s}'
93
', file does not exist in tree.' % file_id)
94
# This is the last known text_id for this file
95
# so assume that it is being used.
96
text_id = tree.inventory[file_id].text_id
99
"""Take a unicode string, and make sure to escape it for
102
Note: It can be either a normal, or a unicode string
104
>>> encode(u'abcdefg')
106
>>> encode(u'a b\tc\\nd\\\\e')
107
'a b\\\\tc\\\\nd\\\\e'
108
>>> encode('a b\tc\\nd\\e')
109
'a b\\\\tc\\\\nd\\\\e'
110
>>> encode(u'\\u1234\\u0020')
112
>>> encode('abcdefg')
119
return s.encode('unicode_escape')
122
"""Undo the encode operation, returning a unicode string.
124
>>> decode('abcdefg')
126
>>> decode('a b\\\\tc\\\\nd\\\\e')
128
>>> decode('\\\\u1234\\\\u0020')
130
>>> for s in ('test', 'strings'):
131
... if decode(encode(s)) != s:
132
... print 'Failed: %r' % s # There should be no failures
135
return s.decode('unicode_escape')
69
137
def format_highres_date(t, offset=0):
70
138
"""Format a date, such that it includes higher precision in the