Rev 3237: Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

Robert Collins robertc at robertcollins.net
Tue Feb 26 01:59:06 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

------------------------------------------------------------
revno: 3237
revision-id:robertc at robertcollins.net-20080226015859-0ny930hk79seevw0
parent: robertc at robertcollins.net-20080225100231-4e202i2ebxak2ya6
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.reference
timestamp: Tue 2008-02-26 12:58:59 +1100
message:
  Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
  bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-02-25 10:02:31 +0000
+++ b/bzrlib/builtins.py	2008-02-26 01:58:59 +0000
@@ -702,20 +702,29 @@
                 'for the commit history. Only the work not present in that '
                 'other branch is included in this shallow branch.',
             type=unicode),
+        Option('shallow',
+            help='Create a shallow branch with an automatic reference url. '
+                'The chosen url is the parent branches public location. See '
+                '--reference for more information.'),
         ]
     takes_args = ['location?']
     encoding_type = 'replace'
 
     def run(self, location=None, remember=False, overwrite=False,
         create_prefix=False, verbose=False, use_existing_dir=False,
-        directory=None, reference=None):
+        directory=None, reference=None, shallow=False):
         # FIXME: Way too big!  Put this into a function called from the
         # command.
         if directory is None:
             directory = '.'
+        br_from = Branch.open_containing(directory)[0]
+        # shallow branch where to refer to logic:
         if reference is not None:
             reference = urlutils.normalize_url(reference)
-        br_from = Branch.open_containing(directory)[0]
+        if shallow:
+            parent = Branch.open(br_from.get_parent())
+            reference = parent.get_public_branch()
+        # where to push logic:
         stored_loc = br_from.get_push_location()
         if location is None:
             if stored_loc is None:

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2008-02-25 10:02:31 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2008-02-26 01:58:59 +0000
@@ -29,6 +29,7 @@
 from bzrlib.osutils import abspath
 from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
 from bzrlib.tests.blackbox import ExternalBase
+from bzrlib.tests.http_server import HttpServer
 from bzrlib.transport import register_transport, unregister_transport
 from bzrlib.transport.memory import MemoryServer, MemoryTransport
 from bzrlib.uncommit import uncommit
@@ -248,8 +249,7 @@
                 'push ../dir',
                 working_dir='tree')
 
-    def test_push_new_branch_reference(self):
-        """Pushing a new branch with --reference creates a stacked branch."""
+    def create_trunk_and_feature_branch(self):
         # We have a mainline
         trunk_tree = self.make_branch_and_tree('target',
             format='development')
@@ -258,9 +258,15 @@
         branch_tree = self.make_branch_and_tree('branch',
             format='development')
         branch_tree.pull(trunk_tree.branch)
+        branch_tree.branch.set_parent(trunk_tree.branch.base)
         # with some work on it
-        branch_revid = branch_tree.commit('moar work plz')
-        # which we publish with a reference to the mainline.
+        branch_tree.commit('moar work plz')
+        return trunk_tree, branch_tree
+
+    def test_push_new_branch_reference(self):
+        """Pushing a new branch with --reference creates a stacked branch."""
+        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
+        # we publish branch_tree with a reference to the mainline.
         out, err = self.run_bzr(['push', '--reference', trunk_tree.branch.base,
             self.get_url('published')], working_dir='branch')
         self.assertEqual('', out)
@@ -271,6 +277,30 @@
         self.assertEqual(trunk_tree.branch.base,
             published_branch.get_stacked_on())
         # and the branch's work was pushed
+        branch_revid = branch_tree.last_revision()
+        self.assertTrue(published_branch.repository.has_revision(branch_revid))
+
+    def test_push_new_branch_shallow_uses_parent_public(self):
+        """Pushing a new branch with --reference creates a stacked branch."""
+        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
+        # the trunk is published on a web server
+        self.transport_readonly_server = HttpServer
+        trunk_public = self.make_branch('public_trunk', format='development')
+        trunk_public.pull(trunk_tree.branch)
+        trunk_public_url = self.get_readonly_url('public_trunk')
+        trunk_tree.branch.set_public_branch(trunk_public_url)
+        # now we do a shallow push, which should determine the public location
+        # for us.
+        out, err = self.run_bzr(['push', '--shallow',
+            self.get_url('published')], working_dir='branch')
+        self.assertEqual('', out)
+        self.assertEqual('Created new shallow branch referring to %s.\n' %
+            trunk_public_url, err)
+        published_branch = Branch.open('published')
+        # The published branch refers to the mainline
+        self.assertEqual(trunk_public_url, published_branch.get_stacked_on())
+        # and the branch's work was pushed
+        branch_revid = branch_tree.last_revision()
         self.assertTrue(published_branch.repository.has_revision(branch_revid))
 
 

=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2008-01-03 08:44:12 +0000
+++ b/bzrlib/tests/http_server.py	2008-02-26 01:58:59 +0000
@@ -58,6 +58,7 @@
 
     def setup(self):
         SimpleHTTPServer.SimpleHTTPRequestHandler.setup(self)
+        self._cwd = self.server._home_dir
         tcs = self.server.test_case_server
         if tcs.protocol_version is not None:
             # If the test server forced a protocol version, use it
@@ -284,8 +285,26 @@
         return self._translate_path(path)
 
     def _translate_path(self, path):
-        return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(
-            self, path)
+        """Translate a /-separated PATH to the local filename syntax.
+
+        Components that mean special things to the local file system
+        (e.g. drive or directory names) are ignored.  (XXX They should
+        probably be diagnosed.)
+
+        Override from python standard library to stop it calling os.getcwd()
+        """
+        # abandon query parameters
+        path = urlparse.urlparse(path)[2]
+        path = posixpath.normpath(urllib.unquote(path))
+        words = path.split('/')
+        words = filter(None, words)
+        path = self._cwd
+        for word in words:
+            drive, word = os.path.splitdrive(word)
+            head, word = os.path.split(word)
+            if word in (os.curdir, os.pardir): continue
+            path = os.path.join(path, word)
+        return path
 
     if sys.platform == 'win32':
         # On win32 you cannot access non-ascii filenames without
@@ -307,7 +326,7 @@
             path = path.decode('utf-8')
             words = path.split('/')
             words = filter(None, words)
-            path = os.getcwdu()
+            path = self._cwd
             for word in words:
                 drive, word = os.path.splitdrive(word)
                 head, word = os.path.split(word)
@@ -324,6 +343,7 @@
         # server), allowing dynamic behaviors to be defined from
         # the tests cases.
         self.test_case_server = test_case_server
+        self._home_dir = test_case_server._home_dir
 
     def tearDown(self):
          """Called to clean-up the server.
@@ -355,6 +375,7 @@
          # Let the server properly close the socket
          self.server_close()
 
+
 class TestingHTTPServer(SocketServer.TCPServer, TestingHTTPServerMixin):
 
     def __init__(self, server_address, request_handler_class,



More information about the bazaar-commits mailing list