[Pkg-bazaar-commits] ./bzr/unstable r815: - track pending-merges

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:21:07 UTC 2009


------------------------------------------------------------
revno: 815
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-04 18:06:51 +1000
message:
  - track pending-merges
  
  - unit tests for this
modified:
  bzrlib/branch.py
  bzrlib/commit.py
  bzrlib/selftest/whitebox.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2005-06-28 05:33:40 +0000
+++ b/bzrlib/branch.py	2005-07-04 08:06:51 +0000
@@ -302,7 +302,8 @@
             os.mkdir(self.controlfilename(d))
         for f in ('revision-history', 'merged-patches',
                   'pending-merged-patches', 'branch-name',
-                  'branch-lock'):
+                  'branch-lock',
+                  'pending-merges'):
             self.controlfile(f, 'w').write('')
         mutter('created control directory in ' + self.base)
 
@@ -1039,6 +1040,48 @@
                 f.close()
 
 
+    def pending_merges(self):
+        """Return a list of pending merges.
+
+        These are revisions that have been merged into the working
+        directory but not yet committed.
+        """
+        cfn = self.controlfilename('pending-merges')
+        if not os.path.exists(cfn):
+            return []
+        p = []
+        for l in self.controlfile('pending-merges', 'r').readlines():
+            p.append(l.rstrip('\n'))
+        return p
+
+
+    def add_pending_merge(self, revision_id):
+        from bzrlib.revision import validate_revision_id
+
+        validate_revision_id(revision_id)
+
+        p = self.pending_merges()
+        if revision_id in p:
+            return
+        p.append(revision_id)
+        self.set_pending_merges(p)
+
+
+    def set_pending_merges(self, rev_list):
+        from bzrlib.atomicfile import AtomicFile
+        self.lock_write()
+        try:
+            f = AtomicFile(self.controlfilename('pending-merges'))
+            try:
+                for l in rev_list:
+                    print >>f, l
+                f.commit()
+            finally:
+                f.close()
+        finally:
+            self.unlock()
+
+
 
 class ScratchBranch(Branch):
     """Special test class: a branch that cleans up after itself.

=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py	2005-06-28 05:33:40 +0000
+++ b/bzrlib/commit.py	2005-07-04 08:06:51 +0000
@@ -16,6 +16,8 @@
 
 
 
+# FIXME: "bzr commit doc/format" commits doc/format.txt!
+
 def commit(branch, message,
            timestamp=None,
            timezone=None,
@@ -81,6 +83,8 @@
         if verbose:
             note('looking for changes...')
 
+        pending_merges = branch.pending_merges()
+
         missing_ids, new_inv = _gather_commit(branch,
                                               work_tree,
                                               work_inv,

=== modified file 'bzrlib/selftest/whitebox.py'
--- a/bzrlib/selftest/whitebox.py	2005-07-04 07:34:10 +0000
+++ b/bzrlib/selftest/whitebox.py	2005-07-04 08:06:51 +0000
@@ -45,6 +45,27 @@
 
 
 
+class PendingMerges(InTempDir):
+    """Tracking pending-merged revisions."""
+    def runTest(self):
+        b = Branch('.', init=True)
+
+        self.assertEquals(b.pending_merges(), [])
+        
+        b.add_pending_merge('foo at azkhazan-123123-abcabc')
+        
+        self.assertEquals(b.pending_merges(), ['foo at azkhazan-123123-abcabc'])
+    
+        b.add_pending_merge('foo at azkhazan-123123-abcabc')
+        
+        self.assertEquals(b.pending_merges(), ['foo at azkhazan-123123-abcabc'])
+
+        b.add_pending_merge('wibble at fofof--20050401--1928390812')
+        self.assertEquals(b.pending_merges(),
+                          ['foo at azkhazan-123123-abcabc',
+                           'wibble at fofof--20050401--1928390812'])
+        
+
 class Revert(InTempDir):
     """Test selected-file revert"""
     def runTest(self):



More information about the Pkg-bazaar-commits mailing list