53
53
If null (default), a time/random revision id is generated.
56
import os, time, tempfile
58
from inventory import Inventory
59
from osutils import isdir, isfile, sha_string, quotefn, \
60
local_time_offset, username, kind_marker, is_inside_any
58
from osutils import local_time_offset, username
62
60
from branch import gen_file_id
63
61
from errors import BzrError
78
76
work_tree = branch.working_tree()
79
77
work_inv = work_tree.inventory
81
78
basis = branch.basis_tree()
82
79
basis_inv = basis.inventory
86
82
note('looking for changes...')
88
for path, entry in work_inv.iter_entries():
89
## TODO: Check that the file kind has not changed from the previous
90
## revision of this file (if any).
94
p = branch.abspath(path)
95
file_id = entry.file_id
96
mutter('commit prep file %s, id %r ' % (p, file_id))
98
if specific_files and not is_inside_any(specific_files, path):
99
if basis_inv.has_id(file_id):
100
# carry over with previous state
101
inv.add(basis_inv[file_id].copy())
103
# omit this from committed inventory
107
if not work_tree.has_id(file_id):
109
print('deleted %s%s' % (path, kind_marker(entry.kind)))
110
mutter(" file is missing, removing from inventory")
111
missing_ids.append(file_id)
116
if basis_inv.has_id(file_id):
117
old_kind = basis_inv[file_id].kind
118
if old_kind != entry.kind:
119
raise BzrError("entry %r changed kind from %r to %r"
120
% (file_id, old_kind, entry.kind))
122
if entry.kind == 'directory':
124
raise BzrError("%s is entered as directory but not a directory"
126
elif entry.kind == 'file':
128
raise BzrError("%s is entered as file but is not a file" % quotefn(p))
130
new_sha1 = work_tree.get_file_sha1(file_id)
132
old_ie = basis_inv.has_id(file_id) and basis_inv[file_id]
134
and old_ie.text_sha1 == new_sha1):
135
## assert content == basis.get_file(file_id).read()
136
entry.text_id = old_ie.text_id
137
entry.text_sha1 = new_sha1
138
entry.text_size = old_ie.text_size
139
mutter(' unchanged from previous text_id {%s}' %
142
content = file(p, 'rb').read()
144
# calculate the sha again, just in case the file contents
145
# changed since we updated the cache
146
entry.text_sha1 = sha_string(content)
147
entry.text_size = len(content)
149
entry.text_id = gen_file_id(entry.name)
150
branch.text_store.add(content, entry.text_id)
151
mutter(' stored with text_id {%s}' % entry.text_id)
154
print('added %s' % path)
155
elif (old_ie.name == entry.name
156
and old_ie.parent_id == entry.parent_id):
157
print('modified %s' % path)
159
print('renamed %s' % path)
84
missing_ids, new_inv = _gather_commit(branch,
162
91
for file_id in missing_ids:
163
92
# Any files that have been deleted are now removed from the
172
def _gather_commit(branch, work_tree, work_inv, basis_inv, specific_files,
174
"""Build inventory preparatory to commit.
176
This adds any changed files into the text store, and sets their
177
test-id, sha and size in the returned inventory appropriately.
180
Modified to hold a list of files that have been deleted from
181
the working directory; these should be removed from the
184
from bzrlib.inventory import Inventory
185
from osutils import isdir, isfile, sha_string, quotefn, \
186
local_time_offset, username, kind_marker, is_inside_any
188
from branch import gen_file_id
189
from errors import BzrError
190
from revision import Revision
191
from bzrlib.trace import mutter, note
196
for path, entry in work_inv.iter_entries():
197
## TODO: Check that the file kind has not changed from the previous
198
## revision of this file (if any).
200
## TODO: Don't need to copy this unless we're going to change it
203
p = branch.abspath(path)
204
file_id = entry.file_id
205
mutter('commit prep file %s, id %r ' % (p, file_id))
207
if specific_files and not is_inside_any(specific_files, path):
208
if basis_inv.has_id(file_id):
209
# carry over with previous state
210
inv.add(basis_inv[file_id].copy())
212
# omit this from committed inventory
216
if not work_tree.has_id(file_id):
218
print('deleted %s%s' % (path, kind_marker(entry.kind)))
219
mutter(" file is missing, removing from inventory")
220
missing_ids.append(file_id)
225
if basis_inv.has_id(file_id):
226
old_kind = basis_inv[file_id].kind
227
if old_kind != entry.kind:
228
raise BzrError("entry %r changed kind from %r to %r"
229
% (file_id, old_kind, entry.kind))
231
if entry.kind == 'directory':
233
raise BzrError("%s is entered as directory but not a directory"
235
elif entry.kind == 'file':
237
raise BzrError("%s is entered as file but is not a file" % quotefn(p))
239
new_sha1 = work_tree.get_file_sha1(file_id)
241
old_ie = basis_inv.has_id(file_id) and basis_inv[file_id]
243
and old_ie.text_sha1 == new_sha1):
244
## assert content == basis.get_file(file_id).read()
245
entry.text_id = old_ie.text_id
246
entry.text_sha1 = new_sha1
247
entry.text_size = old_ie.text_size
248
mutter(' unchanged from previous text_id {%s}' %
251
content = file(p, 'rb').read()
253
# calculate the sha again, just in case the file contents
254
# changed since we updated the cache
255
entry.text_sha1 = sha_string(content)
256
entry.text_size = len(content)
258
entry.text_id = gen_file_id(entry.name)
259
branch.text_store.add(content, entry.text_id)
260
mutter(' stored with text_id {%s}' % entry.text_id)
262
## TODO: Also show these for directories!
264
print('added %s' % path)
265
elif (old_ie.name == entry.name
266
and old_ie.parent_id == entry.parent_id):
267
print('modified %s' % path)
269
print('renamed %s' % path)
271
return missing_ids, inv