22
22
from bzrlib.trace import note, warning
23
from bzrlib.osutils import rename, sha_string
25
def _update_store_entry(obj, obj_id, branch, store_name, store):
26
"""This is just a meta-function, which handles both revision entries
27
and inventory entries.
29
from bzrlib.trace import mutter
30
import tempfile, os, errno
31
obj_tmp = tempfile.TemporaryFile()
32
obj.write_xml(obj_tmp)
35
tmpfd, tmp_path = tempfile.mkstemp(prefix=obj_id, suffix='.gz',
36
dir=branch.controlfilename(store_name))
39
orig_obj_path = branch.controlfilename([store_name, obj_id+'.gz'])
40
# Remove the old entry out of the way
41
rename(orig_obj_path, tmp_path)
43
# TODO: We may need to handle the case where the old
44
# entry was not compressed (and thus did not end with .gz)
46
store.add(obj_tmp, obj_id) # Add the new one
47
os.remove(tmp_path) # Remove the old name
48
mutter(' Updated %s entry {%s}' % (store_name, obj_id))
50
# On any exception, restore the old entry
51
rename(tmp_path, orig_obj_path)
54
if os.path.exists(tmp_path):
55
# Unfortunately, the next command might throw
56
# an exception, which will mask a previous exception.
60
def _update_revision_entry(rev, branch):
61
"""After updating the values in a revision, make sure to
62
write out the data, but try to do it in an atomic manner.
64
:param rev: The Revision object to store
65
:param branch: The Branch object where this Revision is to be stored.
67
_update_store_entry(rev, rev.revision_id, branch,
68
'revision-store', branch.revision_store)
70
def _update_inventory_entry(inv, inv_id, branch):
71
"""When an inventory has been modified (such as by adding a unique tree root)
72
this atomically re-generates the file.
74
:param inv: The Inventory
75
:param inv_id: The inventory id for this inventory
76
:param branch: The Branch where this entry will be stored.
78
raise NotImplementedError("can't update existing inventory entry")
23
from bzrlib.osutils import rename, sha_string, fingerprint_file
24
from bzrlib.trace import mutter
25
from bzrlib.errors import BzrCheckError, NoSuchRevision
26
from bzrlib.inventory import ROOT_ID
27
from bzrlib.branch import gen_root_id