[patch][bugfix] Merge deletes foo.new
John Arbash Meinel
john at arbash-meinel.com
Fri Jan 20 17:18:37 GMT 2006
Aaron Bentley wrote:
> Erik Bågfors wrote:
>
>>>NP, thanks for looking into it so quickly! You guys rock.
>
>
> Aw, thanks. Here's the patch.
>
> Aaron
To make it look nicer, you might like to use:
output_file, new_file = mkstemp(dir=os.path.dirname(filename),
prefix=os.path.basename(filename))
That way the final name will be somewhat related to the original name,
rather than just a random file in that directory.
Just a thought.
Also, with changeset.py, is this a special directory created for each
file? It looks like it, I just wanted to make sure that we wouldn't have
filesystem conflicts if there is a merge in both foo/baz.py, and foo2/baz.py
+1 from me, but with a suggestion.
John
=:->
------------------------------------------------------------------------
=== modified file 'bzrlib/changeset.py'
--- bzrlib/changeset.py
+++ bzrlib/changeset.py
@@ -401,9 +401,9 @@
def apply(self, filename, conflict_handler):
import bzrlib.patch
- temp_dir = mkdtemp(prefix="bzr-")
+ temp_dir = mkdtemp(prefix="bzr-", dir=os.path.dirname(filename))
try:
- new_file = filename+".new"
+ new_file = os.path.join(temp_dir, filename)
base_file = self.dump_file(temp_dir, "base", self.base)
other_file = self.dump_file(temp_dir, "other", self.other)
base = base_file
=== modified file 'bzrlib/merge_core.py'
--- bzrlib/merge_core.py
+++ bzrlib/merge_core.py
@@ -1,4 +1,6 @@
+from os import fdopen
import os.path
+from tempfile import mkstemp
import changeset
from changeset import Inventory, apply_changeset, invert_dict
@@ -37,7 +39,8 @@
return not (self == other)
def apply(self, filename, conflict_handler):
- new_file = filename+".new"
+ output_file, new_file = mkstemp(dir=os.path.dirname(filename))
+ output_file = fdopen(output_file, 'wb')
base = self.base
other = self.other
def get_lines(tree):
@@ -50,7 +53,6 @@
m3 = Merge3(base_lines, file(filename, "rb").readlines(),
other_lines)
new_conflicts = False
- output_file = file(new_file, "wb")
start_marker = "!START OF MERGE CONFLICT!" + "I HOPE THIS IS
UNIQUE"
if self.show_base is True:
base_marker = '|' * 7
=== modified file 'bzrlib/tests/test_merge_core.py'
--- bzrlib/tests/test_merge_core.py
+++ bzrlib/tests/test_merge_core.py
@@ -14,7 +14,7 @@
from bzrlib.merge_core import (ApplyMerge3, make_merge_changeset,
BackupBeforeChange, ExecFlagMerge,
WeaveMerge)
from bzrlib.changeset import Inventory, apply_changeset, invert_dict, \
- get_contents, ReplaceContents, ChangeExecFlag
+ get_contents, ReplaceContents, ChangeExecFlag, Diff3Merge
from bzrlib.clone import copy_branch
from bzrlib.merge import merge
from bzrlib.workingtree import WorkingTree
@@ -531,6 +531,18 @@
self.assert_(os.lstat(builder.this.full_path("3")).st_mode
&0100 == 0000)
builder.cleanup();
+ def test_new_suffix(self):
+ for merge_type in ApplyMerge3, Diff3Merge:
+ builder = MergeBuilder()
+ builder.add_file("1", "0", "name1", "text1", 0755)
+ builder.change_contents("1", other="text3")
+ builder.add_file("2", "0", "name1.new", "text2", 0777)
+ cset = builder.merge_changeset(ApplyMerge3)
+ os.lstat(builder.this.full_path("2"))
+ builder.apply_changeset(cset)
+ os.lstat(builder.this.full_path("2"))
+ builder.cleanup()
+
class FunctionalMergeTest(TestCaseInTempDir):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060120/25300cc7/attachment.pgp
More information about the bazaar
mailing list