~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-07-04 08:06:51 UTC
  • Revision ID: mbp@sourcefrog.net-20050704080651-6ecec49164359e48
- track pending-merges

- unit tests for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
302
302
            os.mkdir(self.controlfilename(d))
303
303
        for f in ('revision-history', 'merged-patches',
304
304
                  'pending-merged-patches', 'branch-name',
305
 
                  'branch-lock'):
 
305
                  'branch-lock',
 
306
                  'pending-merges'):
306
307
            self.controlfile(f, 'w').write('')
307
308
        mutter('created control directory in ' + self.base)
308
309
 
1039
1040
                f.close()
1040
1041
 
1041
1042
 
 
1043
    def pending_merges(self):
 
1044
        """Return a list of pending merges.
 
1045
 
 
1046
        These are revisions that have been merged into the working
 
1047
        directory but not yet committed.
 
1048
        """
 
1049
        cfn = self.controlfilename('pending-merges')
 
1050
        if not os.path.exists(cfn):
 
1051
            return []
 
1052
        p = []
 
1053
        for l in self.controlfile('pending-merges', 'r').readlines():
 
1054
            p.append(l.rstrip('\n'))
 
1055
        return p
 
1056
 
 
1057
 
 
1058
    def add_pending_merge(self, revision_id):
 
1059
        from bzrlib.revision import validate_revision_id
 
1060
 
 
1061
        validate_revision_id(revision_id)
 
1062
 
 
1063
        p = self.pending_merges()
 
1064
        if revision_id in p:
 
1065
            return
 
1066
        p.append(revision_id)
 
1067
        self.set_pending_merges(p)
 
1068
 
 
1069
 
 
1070
    def set_pending_merges(self, rev_list):
 
1071
        from bzrlib.atomicfile import AtomicFile
 
1072
        self.lock_write()
 
1073
        try:
 
1074
            f = AtomicFile(self.controlfilename('pending-merges'))
 
1075
            try:
 
1076
                for l in rev_list:
 
1077
                    print >>f, l
 
1078
                f.commit()
 
1079
            finally:
 
1080
                f.close()
 
1081
        finally:
 
1082
            self.unlock()
 
1083
 
 
1084
 
1042
1085
 
1043
1086
class ScratchBranch(Branch):
1044
1087
    """Special test class: a branch that cleans up after itself.