111
112
DEPRECATED_PARAMETER,
117
119
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
118
120
CONFLICT_HEADER_1 = "BZR conflict list format 1"
120
# the regex removes any weird characters; we don't escape them
121
# but rather just pull them out
122
_gen_file_id_re = re.compile(r'[^\w.]')
123
_gen_id_suffix = None
127
def _next_id_suffix():
128
"""Create a new file id suffix that is reasonably unique.
130
On the first call we combine the current time with 64 bits of randomness
131
to give a highly probably globally unique number. Then each call in the same
132
process adds 1 to a serial number we append to that unique value.
134
# XXX TODO: change bzrlib.add.smart_add to call workingtree.add() rather
135
# than having to move the id randomness out of the inner loop like this.
136
# XXX TODO: for the global randomness this uses we should add the thread-id
137
# before the serial #.
138
global _gen_id_suffix, _gen_id_serial
139
if _gen_id_suffix is None:
140
_gen_id_suffix = "-%s-%s-" % (compact_date(time()), rand_chars(16))
142
return _gen_id_suffix + str(_gen_id_serial)
123
@deprecated_function(zero_thirteen)
145
124
def gen_file_id(name):
146
125
"""Return new file id for the basename 'name'.
148
The uniqueness is supplied from _next_id_suffix.
127
Use bzrlib.generate_ids.gen_file_id() instead
150
# The real randomness is in the _next_id_suffix, the
151
# rest of the identifier is just to be nice.
153
# 1) Remove non-ascii word characters to keep the ids portable
154
# 2) squash to lowercase, so the file id doesn't have to
155
# be escaped (case insensitive filesystems would bork for ids
156
# that only differred in case without escaping).
157
# 3) truncate the filename to 20 chars. Long filenames also bork on some
159
# 4) Removing starting '.' characters to prevent the file ids from
160
# being considered hidden.
161
ascii_word_only = _gen_file_id_re.sub('', name.lower())
162
short_no_dots = ascii_word_only.lstrip('.')[:20]
163
return short_no_dots + _next_id_suffix()
129
return generate_ids.gen_file_id(name)
132
@deprecated_function(zero_thirteen)
166
133
def gen_root_id():
167
"""Return a new tree-root file id."""
168
return gen_file_id('tree_root')
134
"""Return a new tree-root file id.
136
This has been deprecated in favor of bzrlib.generate_ids.gen_root_id()
138
return generate_ids.gen_root_id()
171
141
class TreeEntry(object):
850
820
def mkdir(self, path, file_id=None):
851
821
"""See MutableTree.mkdir()."""
852
822
if file_id is None:
853
file_id = gen_file_id(os.path.basename(path))
823
file_id = generate_ids.gen_file_id(os.path.basename(path))
854
824
os.mkdir(self.abspath(path))
855
825
self.add(path, file_id, 'directory')