~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-15 21:35:53 UTC
  • mfrom: (907.1.57)
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050915213552-a6c83a5ef1e20897
(broken) Transport work is merged in. Tests do not pass yet.

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
23
21
 
24
22
# XXX: mbp: I'm not totally convinced that we should handle conflicts
25
23
# as part of changeset application, rather than only in the merge
44
42
        newdict[value] = key
45
43
    return newdict
46
44
 
 
45
 
47
46
       
48
47
class ChangeUnixPermissions(object):
49
48
    """This is two-way change, suitable for file modification, creation,
93
92
    def __ne__(self, other):
94
93
        return not (self == other)
95
94
 
96
 
 
97
95
def dir_create(filename, conflict_handler, reverse):
98
96
    """Creates the directory, or deletes it if reverse is true.  Intended to be
99
97
    used with ReplaceContents.
119
117
        try:
120
118
            os.rmdir(filename)
121
119
        except OSError, e:
122
 
            if e.errno != errno.ENOTEMPTY:
 
120
            if e.errno != 39:
123
121
                raise
124
122
            if conflict_handler.rmdir_non_empty(filename) == "skip":
125
123
                return
126
124
            os.rmdir(filename)
127
125
 
 
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
 
            rename(new_file, filename)
 
356
            os.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
 
                    rename(src_path, to_name)
 
834
                    os.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 bzrlib.osutils.lexists(new_path):
 
866
        if os.path.exists(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
 
                rename(old_path, new_path)
 
877
                os.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
    
1006
1009
    def missing_parent(self, pathname):
1007
1010
        parent = os.path.dirname(pathname)
1008
1011
        raise Exception("Parent directory missing for %s" % pathname)
1081
1084
    :rtype: Dictionary
1082
1085
    """
1083
1086
    if conflict_handler is None:
1084
 
        conflict_handler = ExceptionConflictHandler()
 
1087
        conflict_handler = ExceptionConflictHandler(dir)
1085
1088
    temp_dir = os.path.join(dir, "bzr-tree-change")
1086
1089
    try:
1087
1090
        os.mkdir(temp_dir)
1384
1387
 
1385
1388
        if cs_entry is None:
1386
1389
            return None
 
1390
        if id in self.tree_a and id in self.tree_b:
 
1391
            a_sha1 = self.tree_a.get_file_sha1(id)
 
1392
            b_sha1 = self.tree_b.get_file_sha1(id)
 
1393
            if None not in (a_sha1, b_sha1) and a_sha1 == b_sha1:
 
1394
                return cs_entry
1387
1395
 
1388
1396
        full_path_a = self.tree_a.readonly_path(id)
1389
1397
        full_path_b = self.tree_b.readonly_path(id)
1390
1398
        stat_a = self.lstat(full_path_a)
1391
1399
        stat_b = self.lstat(full_path_b)
1392
 
 
 
1400
        
1393
1401
        cs_entry.metadata_change = self.make_mode_change(stat_a, stat_b)
1394
 
 
1395
 
        if id in self.tree_a and id in self.tree_b:
1396
 
            a_sha1 = self.tree_a.get_file_sha1(id)
1397
 
            b_sha1 = self.tree_b.get_file_sha1(id)
1398
 
            if None not in (a_sha1, b_sha1) and a_sha1 == b_sha1:
1399
 
                return cs_entry
1400
 
 
1401
1402
        cs_entry.contents_change = self.make_contents_change(full_path_a,
1402
1403
                                                             stat_a, 
1403
1404
                                                             full_path_b,