~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-05 22:58:59 UTC
  • mfrom: (2120.7.7 autoconflicts)
  • Revision ID: pqm@pqm.ubuntu.com-20070305225859-31c72fc6c3778b82
resolve auto-resolves text conflicts by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
import stat
48
48
from time import time
49
49
import warnings
 
50
import re
50
51
 
51
52
import bzrlib
52
53
from bzrlib import (
1940
1941
                             file_id=self.path2id(conflicted)))
1941
1942
        return conflicts
1942
1943
 
 
1944
    @needs_tree_write_lock
 
1945
    def auto_resolve(self):
 
1946
        """Automatically resolve text conflicts according to contents.
 
1947
 
 
1948
        Only text conflicts are auto_resolvable. Files with no conflict markers
 
1949
        are considered 'resolved', because bzr always puts conflict markers
 
1950
        into files that have text conflicts.  The corresponding .THIS .BASE and
 
1951
        .OTHER files are deleted, as per 'resolve'.
 
1952
        :return: a tuple of ConflictLists: (un_resolved, resolved).
 
1953
        """
 
1954
        un_resolved = _mod_conflicts.ConflictList()
 
1955
        resolved = _mod_conflicts.ConflictList()
 
1956
        conflict_re = re.compile('^(<{7}|={7}|>{7})')
 
1957
        for conflict in self.conflicts():
 
1958
            if (conflict.typestring != 'text conflict' or
 
1959
                self.kind(conflict.file_id) != 'file'):
 
1960
                un_resolved.append(conflict)
 
1961
                continue
 
1962
            my_file = open(self.id2abspath(conflict.file_id), 'rb')
 
1963
            try:
 
1964
                for line in my_file:
 
1965
                    if conflict_re.search(line):
 
1966
                        un_resolved.append(conflict)
 
1967
                        break
 
1968
                else:
 
1969
                    resolved.append(conflict)
 
1970
            finally:
 
1971
                my_file.close()
 
1972
        resolved.remove_files(self)
 
1973
        self.set_conflicts(un_resolved)
 
1974
        return un_resolved, resolved
 
1975
 
1943
1976
 
1944
1977
class WorkingTree2(WorkingTree):
1945
1978
    """This is the Format 2 working tree.