/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/transport/log.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Transport decorator that logs transport operations to .bzr.log."""
 
17
"""Transport decorator that logs transport operations to .brz.log."""
18
18
 
 
19
from __future__ import absolute_import
19
20
 
20
21
# see also the transportstats plugin, which gives you some summary information
21
22
# in a machine-readable dump
22
23
 
23
 
import StringIO
24
 
import cStringIO
25
24
import time
26
25
import types
27
26
 
28
 
from bzrlib.trace import mutter
29
 
from bzrlib.transport import decorator
 
27
from ..trace import mutter
 
28
from ..transport import decorator
30
29
 
31
30
 
32
31
class TransportLogDecorator(decorator.TransportDecorator):
33
 
    """Decorator for Transports that logs interesting operations to .bzr.log.
 
32
    """Decorator for Transports that logs interesting operations to .brz.log.
34
33
 
35
34
    In general we want to log things that usually take a network round trip
36
35
    and may be slow.
47
46
            def _hook(relpath, *args, **kw):
48
47
                return self._log_and_call(hookname, relpath, *args, **kw)
49
48
            return _hook
 
49
        # GZ 2017-05-21: Not all methods take relpath as first argument, for
 
50
        # instance copy_to takes list of relpaths. Also, unclear on url vs
 
51
        # filesystem path split. Needs tidying up.
50
52
        for methodname in (
51
53
            'append_bytes',
52
54
            'append_file',
81
83
        else:
82
84
            kwargs_str = ''
83
85
        mutter("%s %s %s %s"
84
 
               % (methodname, self._decorated.abspath(relpath),
 
86
               % (methodname, relpath,
85
87
                  self._shorten(self._strip_tuple_parens(args)),
86
88
                  kwargs_str))
87
89
        return self._call_and_log_result(methodname, (relpath,) + args, kwargs)
90
92
        before = time.time()
91
93
        try:
92
94
            result = getattr(self._decorated, methodname)(*args, **kwargs)
93
 
        except Exception, e:
 
95
        except Exception as e:
94
96
            mutter("  --> %s" % e)
95
97
            mutter("      %.03fs" % (time.time() - before))
96
98
            raise
108
110
            return_result = iter(result)
109
111
        else:
110
112
            return_result = result
111
 
        if isinstance(result, (cStringIO.OutputType, StringIO.StringIO)):
112
 
            val = repr(result.getvalue())
 
113
        # Is this an io object with a getvalue() method?
 
114
        getvalue = getattr(result, 'getvalue', None)
 
115
        if getvalue is not None:
 
116
            val = repr(getvalue())
113
117
            result_len = len(val)
114
118
            shown_result = "%s(%s) (%d bytes)" % (result.__class__.__name__,
115
119
                self._shorten(val), result_len)
116
120
        elif methodname == 'readv':
117
121
            num_hunks = len(result)
118
 
            total_bytes = sum((len(d) for o,d in result))
 
122
            total_bytes = sum((len(d) for o, d in result))
119
123
            shown_result = "readv response, %d hunks, %d total bytes" % (
120
124
                num_hunks, total_bytes)
121
125
            result_len = total_bytes
150
154
 
151
155
def get_test_permutations():
152
156
    """Return the permutations to be used in testing."""
153
 
    from bzrlib.tests import test_server
 
157
    from ..tests import test_server
154
158
    return [(TransportLogDecorator, test_server.LogDecoratorServer)]