~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: Martin Pool
  • Date: 2005-10-06 10:53:12 UTC
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1418.
  • Revision ID: mbp@sourcefrog.net-20051006105312-06320dbb986e4bb3
- test that we cannot join weaves with different ancestry

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import patch
19
19
import stat
20
20
from bzrlib.trace import mutter
 
21
from bzrlib.osutils import rename
 
22
import bzrlib
21
23
 
22
24
# XXX: mbp: I'm not totally convinced that we should handle conflicts
23
25
# as part of changeset application, rather than only in the merge
42
44
        newdict[value] = key
43
45
    return newdict
44
46
 
45
 
 
46
47
       
47
48
class ChangeUnixPermissions(object):
48
49
    """This is two-way change, suitable for file modification, creation,
92
93
    def __ne__(self, other):
93
94
        return not (self == other)
94
95
 
 
96
 
95
97
def dir_create(filename, conflict_handler, reverse):
96
98
    """Creates the directory, or deletes it if reverse is true.  Intended to be
97
99
    used with ReplaceContents.
117
119
        try:
118
120
            os.rmdir(filename)
119
121
        except OSError, e:
120
 
            if e.errno != 39:
 
122
            if e.errno != errno.ENOTEMPTY:
121
123
                raise
122
124
            if conflict_handler.rmdir_non_empty(filename) == "skip":
123
125
                return
124
126
            os.rmdir(filename)
125
127
 
126
 
                
127
 
            
128
128
 
129
129
class SymlinkCreate(object):
130
130
    """Creates or deletes a symlink (for use with ReplaceContents)"""
353
353
        status = patch.diff3(new_file, filename, base, other)
354
354
        if status == 0:
355
355
            os.chmod(new_file, os.stat(filename).st_mode)
356
 
            os.rename(new_file, filename)
 
356
            rename(new_file, filename)
357
357
            return
358
358
        else:
359
359
            assert(status == 1)
831
831
            if src_path is not None:
832
832
                src_path = os.path.join(dir, src_path)
833
833
                try:
834
 
                    os.rename(src_path, to_name)
 
834
                    rename(src_path, to_name)
835
835
                    temp_name[entry.id] = to_name
836
836
                except OSError, e:
837
837
                    if e.errno != errno.ENOENT:
863
863
            continue
864
864
        new_path = os.path.join(dir, new_tree_path)
865
865
        old_path = changed_inventory.get(entry.id)
866
 
        if os.path.exists(new_path):
 
866
        if bzrlib.osutils.lexists(new_path):
867
867
            if conflict_handler.target_exists(entry, new_path, old_path) == \
868
868
                "skip":
869
869
                continue
874
874
            if old_path is None:
875
875
                continue
876
876
            try:
877
 
                os.rename(old_path, new_path)
 
877
                rename(old_path, new_path)
878
878
                changed_inventory[entry.id] = new_tree_path
879
879
            except OSError, e:
880
880
                raise Exception ("%s is missing" % new_path)
1003
1003
    descend from this class if they have a better way to handle some or
1004
1004
    all types of conflict.
1005
1005
    """
1006
 
    def __init__(self, dir):
1007
 
        self.dir = dir
1008
 
    
1009
1006
    def missing_parent(self, pathname):
1010
1007
        parent = os.path.dirname(pathname)
1011
1008
        raise Exception("Parent directory missing for %s" % pathname)
1084
1081
    :rtype: Dictionary
1085
1082
    """
1086
1083
    if conflict_handler is None:
1087
 
        conflict_handler = ExceptionConflictHandler(dir)
 
1084
        conflict_handler = ExceptionConflictHandler()
1088
1085
    temp_dir = os.path.join(dir, "bzr-tree-change")
1089
1086
    try:
1090
1087
        os.mkdir(temp_dir)
1387
1384
 
1388
1385
        if cs_entry is None:
1389
1386
            return None
 
1387
 
 
1388
        full_path_a = self.tree_a.readonly_path(id)
 
1389
        full_path_b = self.tree_b.readonly_path(id)
 
1390
        stat_a = self.lstat(full_path_a)
 
1391
        stat_b = self.lstat(full_path_b)
 
1392
 
 
1393
        cs_entry.metadata_change = self.make_mode_change(stat_a, stat_b)
 
1394
 
1390
1395
        if id in self.tree_a and id in self.tree_b:
1391
1396
            a_sha1 = self.tree_a.get_file_sha1(id)
1392
1397
            b_sha1 = self.tree_b.get_file_sha1(id)
1393
1398
            if None not in (a_sha1, b_sha1) and a_sha1 == b_sha1:
1394
1399
                return cs_entry
1395
1400
 
1396
 
        full_path_a = self.tree_a.readonly_path(id)
1397
 
        full_path_b = self.tree_b.readonly_path(id)
1398
 
        stat_a = self.lstat(full_path_a)
1399
 
        stat_b = self.lstat(full_path_b)
1400
 
        
1401
 
        cs_entry.metadata_change = self.make_mode_change(stat_a, stat_b)
1402
1401
        cs_entry.contents_change = self.make_contents_change(full_path_a,
1403
1402
                                                             stat_a, 
1404
1403
                                                             full_path_b,