~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: Robert Collins
  • Date: 2005-10-09 23:42:12 UTC
  • Revision ID: robertc@robertcollins.net-20051009234212-7973344d900afb0b
merge in niemeyers prefixed-store patch

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)
360
360
            def get_lines(filename):
361
 
                my_file = file(base, "rb")
 
361
                my_file = file(filename, "rb")
362
362
                lines = my_file.readlines()
363
363
                my_file.close()
 
364
                return lines
364
365
            base_lines = get_lines(base)
365
366
            other_lines = get_lines(other)
366
367
            conflict_handler.merge_conflict(new_file, filename, base_lines, 
831
832
            if src_path is not None:
832
833
                src_path = os.path.join(dir, src_path)
833
834
                try:
834
 
                    os.rename(src_path, to_name)
 
835
                    rename(src_path, to_name)
835
836
                    temp_name[entry.id] = to_name
836
837
                except OSError, e:
837
838
                    if e.errno != errno.ENOENT:
863
864
            continue
864
865
        new_path = os.path.join(dir, new_tree_path)
865
866
        old_path = changed_inventory.get(entry.id)
866
 
        if os.path.exists(new_path):
 
867
        if bzrlib.osutils.lexists(new_path):
867
868
            if conflict_handler.target_exists(entry, new_path, old_path) == \
868
869
                "skip":
869
870
                continue
874
875
            if old_path is None:
875
876
                continue
876
877
            try:
877
 
                os.rename(old_path, new_path)
 
878
                rename(old_path, new_path)
878
879
                changed_inventory[entry.id] = new_tree_path
879
880
            except OSError, e:
880
881
                raise Exception ("%s is missing" % new_path)
1003
1004
    descend from this class if they have a better way to handle some or
1004
1005
    all types of conflict.
1005
1006
    """
1006
 
    def __init__(self, dir):
1007
 
        self.dir = dir
1008
 
    
1009
1007
    def missing_parent(self, pathname):
1010
1008
        parent = os.path.dirname(pathname)
1011
1009
        raise Exception("Parent directory missing for %s" % pathname)
1084
1082
    :rtype: Dictionary
1085
1083
    """
1086
1084
    if conflict_handler is None:
1087
 
        conflict_handler = ExceptionConflictHandler(dir)
 
1085
        conflict_handler = ExceptionConflictHandler()
1088
1086
    temp_dir = os.path.join(dir, "bzr-tree-change")
1089
1087
    try:
1090
1088
        os.mkdir(temp_dir)
1387
1385
 
1388
1386
        if cs_entry is None:
1389
1387
            return None
 
1388
 
 
1389
        full_path_a = self.tree_a.readonly_path(id)
 
1390
        full_path_b = self.tree_b.readonly_path(id)
 
1391
        stat_a = self.lstat(full_path_a)
 
1392
        stat_b = self.lstat(full_path_b)
 
1393
 
 
1394
        cs_entry.metadata_change = self.make_mode_change(stat_a, stat_b)
 
1395
 
1390
1396
        if id in self.tree_a and id in self.tree_b:
1391
1397
            a_sha1 = self.tree_a.get_file_sha1(id)
1392
1398
            b_sha1 = self.tree_b.get_file_sha1(id)
1393
1399
            if None not in (a_sha1, b_sha1) and a_sha1 == b_sha1:
1394
1400
                return cs_entry
1395
1401
 
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
1402
        cs_entry.contents_change = self.make_contents_change(full_path_a,
1403
1403
                                                             stat_a, 
1404
1404
                                                             full_path_b,