89
def add_suffix(self, name, suffix, last_new_name=None):
89
def add_suffix(self, name, suffix, last_new_name=None, fix_inventory=True):
90
90
"""Rename a file to append a suffix. If the new name exists, the
91
91
suffix is added repeatedly until a non-existant name is found
99
99
new_name = last_new_name+suffix
101
101
rename(name, new_name)
103
relpath = self.this_tree.relpath(name)
104
except NotBranchError:
106
if relpath is not None:
107
file_id = self.this_tree.path2id(relpath)
108
if file_id is not None:
109
new_path = self.this_tree.relpath(new_name)
110
rename(new_name, name)
111
self.this_tree.branch.rename_one(relpath, new_path)
112
assert self.this_tree.id2path(file_id) == relpath
113
self.this_tree._inventory = self.this_tree.branch.inventory
114
assert self.this_tree.id2path(file_id) == new_path
102
if fix_inventory is True:
104
relpath = self.this_tree.relpath(name)
105
except NotBranchError:
107
if relpath is not None:
108
file_id = self.this_tree.path2id(relpath)
109
if file_id is not None:
110
new_path = self.this_tree.relpath(new_name)
111
rename(new_name, name)
112
self.this_tree.branch.rename_one(relpath, new_path)
113
assert self.this_tree.id2path(file_id) == relpath
114
self.this_tree._inventory = self.this_tree.branch.inventory
115
assert self.this_tree.id2path(file_id) == new_path
115
116
except OSError, e:
116
117
if e.errno != errno.EEXIST and e.errno != errno.ENOTEMPTY:
118
return self.add_suffix(name, suffix, last_new_name=new_name)
119
return self.add_suffix(name, suffix, last_new_name=new_name,
120
fix_inventory=fix_inventory)
121
123
def conflict(self, text):
132
134
:param base_path: Path to the file text for the BASE tree
133
135
:param other_path: Path to the file text for the OTHER tree
135
self.add_suffix(this_path, ".THIS")
137
self.add_suffix(this_path, ".THIS", fix_inventory=False)
136
138
self.dump(base_lines, this_path+".BASE")
137
139
self.dump(other_lines, this_path+".OTHER")
138
140
rename(new_file, this_path)