~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/server.py

  • Committer: Vincent Ladeuil
  • Date: 2009-07-02 13:07:14 UTC
  • mto: (4524.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4525.
  • Revision ID: v.ladeuil+lp@free.fr-20090702130714-hsyqfusi8vn3a11m
Use tree.has_changes() where appropriate (the test suite caught a
bug in has_changes() (not filtering out the root) in an impressive
number of tests)

* bzrlib/send.py:
(send): Use tree.has_changes() instead of tree.changes_from().

* bzrlib/reconfigure.py:
(Reconfigure._check): Use tree.has_changes() instead of
tree.changes_from().

* bzrlib/merge.py:
(Merger.ensure_revision_trees, Merger.compare_basis): Use
tree.has_changes() instead of tree.changes_from().

* bzrlib/builtins.py:
(cmd_remove_tree.run, cmd_push.run, cmd_merge.run): Use
tree.has_changes() instead of tree.changes_from().

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Server for smart-server protocol."""
18
18
 
21
21
import sys
22
22
import threading
23
23
 
24
 
from bzrlib.hooks import Hooks
 
24
from bzrlib.hooks import HookPoint, Hooks
25
25
from bzrlib import (
26
26
    errors,
27
27
    trace,
62
62
        from socket import error as socket_error
63
63
        self._socket_error = socket_error
64
64
        self._socket_timeout = socket_timeout
65
 
        addrs = socket.getaddrinfo(host, port, socket.AF_UNSPEC, 
 
65
        addrs = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
66
66
            socket.SOCK_STREAM, 0, socket.AI_PASSIVE)[0]
67
67
 
68
68
        (family, socktype, proto, canonname, sockaddr) = addrs
98
98
        # We need all three because:
99
99
        #  * other machines see the first
100
100
        #  * local commits on this machine should be able to be mapped to
101
 
        #    this server 
 
101
        #    this server
102
102
        #  * commits the server does itself need to be mapped across to this
103
103
        #    server.
104
104
        # The latter two urls are different aliases to the servers url,
105
 
        # so we group those in a list - as there might be more aliases 
 
105
        # so we group those in a list - as there might be more aliases
106
106
        # in the future.
107
107
        backing_urls = [self.backing_transport.base]
108
108
        try:
152
152
 
153
153
    def serve_conn(self, conn, thread_name_suffix):
154
154
        # For WIN32, where the timeout value from the listening socket
155
 
        # propogates to the newly accepted socket.
 
155
        # propagates to the newly accepted socket.
156
156
        conn.setblocking(True)
157
157
        conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
158
158
        handler = medium.SmartServerSocketStreamMedium(
178
178
        self._should_terminate = True
179
179
        # close the socket - gives error to connections from here on in,
180
180
        # rather than a connection reset error to connections made during
181
 
        # the period between setting _should_terminate = True and 
 
181
        # the period between setting _should_terminate = True and
182
182
        # the current request completing/aborting. It may also break out the
183
183
        # main loop if it was currently in accept() (on some platforms).
184
184
        try:
208
208
        notified.
209
209
        """
210
210
        Hooks.__init__(self)
211
 
        # Introduced in 0.16:
212
 
        # invoked whenever the server starts serving a directory.
213
 
        # The api signature is (backing urls, public url).
214
 
        self['server_started'] = []
215
 
        # Introduced in 0.16:
216
 
        # invoked whenever the server stops serving a directory.
217
 
        # The api signature is (backing urls, public url).
218
 
        self['server_stopped'] = []
 
211
        self.create_hook(HookPoint('server_started',
 
212
            "Called by the bzr server when it starts serving a directory. "
 
213
            "server_started is called with (backing urls, public url), "
 
214
            "where backing_url is a list of URLs giving the "
 
215
            "server-specific directory locations, and public_url is the "
 
216
            "public URL for the directory being served.", (0, 16), None))
 
217
        self.create_hook(HookPoint('server_stopped',
 
218
            "Called by the bzr server when it stops serving a directory. "
 
219
            "server_stopped is called with the same parameters as the "
 
220
            "server_started hook: (backing_urls, public_url).", (0, 16), None))
219
221
 
220
222
SmartTCPServer.hooks = SmartServerHooks()
221
223
 
222
224
 
223
225
class SmartTCPServer_for_testing(SmartTCPServer):
224
226
    """Server suitable for use by transport tests.
225
 
    
 
227
 
226
228
    This server is backed by the process's cwd.
227
229
    """
228
230
 
230
232
        SmartTCPServer.__init__(self, None)
231
233
        self.client_path_extra = None
232
234
        self.thread_name_suffix = thread_name_suffix
233
 
        
 
235
 
234
236
    def get_backing_transport(self, backing_transport_server):
235
237
        """Get a backing transport from a server we are decorating."""
236
238
        return transport.get_transport(backing_transport_server.get_url())
238
240
    def setUp(self, backing_transport_server=None,
239
241
              client_path_extra='/extra/'):
240
242
        """Set up server for testing.
241
 
        
 
243
 
242
244
        :param backing_transport_server: backing server to use.  If not
243
245
            specified, a LocalURLServer at the current working directory will
244
246
            be used.
305
307
        return transport.get_transport(url)
306
308
 
307
309
 
 
310
def serve_bzr(transport, host=None, port=None, inet=False):
 
311
    from bzrlib import lockdir, ui
 
312
    from bzrlib.transport import get_transport
 
313
    from bzrlib.transport.chroot import ChrootServer
 
314
    chroot_server = ChrootServer(transport)
 
315
    chroot_server.setUp()
 
316
    t = get_transport(chroot_server.get_url())
 
317
    if inet:
 
318
        smart_server = medium.SmartServerPipeStreamMedium(
 
319
            sys.stdin, sys.stdout, transport)
 
320
    else:
 
321
        if host is None:
 
322
            host = medium.BZR_DEFAULT_INTERFACE
 
323
        if port is None:
 
324
            port = medium.BZR_DEFAULT_PORT
 
325
        smart_server = SmartTCPServer(
 
326
            transport, host=host, port=port)
 
327
        trace.note('listening on port: %s' % smart_server.port)
 
328
    # For the duration of this server, no UI output is permitted. note
 
329
    # that this may cause problems with blackbox tests. This should be
 
330
    # changed with care though, as we dont want to use bandwidth sending
 
331
    # progress over stderr to smart server clients!
 
332
    old_factory = ui.ui_factory
 
333
    old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
 
334
    try:
 
335
        ui.ui_factory = ui.SilentUIFactory()
 
336
        lockdir._DEFAULT_TIMEOUT_SECONDS = 0
 
337
        smart_server.serve()
 
338
    finally:
 
339
        ui.ui_factory = old_factory
 
340
        lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
 
341