/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/status.py

  • Committer: Jelmer Vernooij
  • Author(s): Richard Wilbur
  • Date: 2017-05-30 23:37:11 UTC
  • mto: This revision was merged to the branch mainline in revision 6645.
  • Revision ID: jelmer@jelmer.uk-20170530233711-r0m0qp8hpkqzpopw
Fix order in which files are processed.

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
from __future__ import absolute_import
 
18
 
17
19
import sys
18
20
 
19
 
from bzrlib import (
 
21
from . import (
20
22
    delta as _mod_delta,
 
23
    hooks as _mod_hooks,
21
24
    log,
22
25
    osutils,
23
26
    tsort,
24
27
    revision as _mod_revision,
25
28
    )
26
 
import bzrlib.errors as errors
27
 
from bzrlib.trace import mutter, warning
 
29
from . import errors as errors
 
30
from .trace import mutter, warning
28
31
 
29
32
# TODO: when showing single-line logs, truncate to the width of the terminal
30
33
# if known, but only if really going to the terminal (not into a file)
33
36
def report_changes(to_file, old, new, specific_files, 
34
37
                   show_short_reporter, show_long_callback, 
35
38
                   short=False, want_unchanged=False, 
36
 
                   want_unversioned=False, show_ids=False):
 
39
                   want_unversioned=False, show_ids=False, classify=True):
37
40
    """Display summary of changes.
38
41
 
39
42
    This compares two trees with regards to a list of files, and delegates 
58
61
        files.
59
62
    :param show_ids: If set, includes each file's id.
60
63
    :param want_unversioned: If False, only shows versioned files.
 
64
    :param classify: Add special symbols to indicate file kind.
61
65
    """
62
66
 
63
67
    if short:
75
79
            delta.unversioned if not new.is_ignored(unversioned[0])]
76
80
        show_long_callback(to_file, delta, 
77
81
                           show_ids=show_ids,
78
 
                           show_unchanged=want_unchanged)
 
82
                           show_unchanged=want_unchanged,
 
83
                           classify=classify)
79
84
 
80
85
 
81
86
def show_tree_status(wt, show_unchanged=None,
87
92
                     short=False,
88
93
                     verbose=False,
89
94
                     versioned=False,
 
95
                     classify=True,
90
96
                     show_long_callback=_mod_delta.report_delta):
91
97
    """Display summary of changes.
92
98
 
116
122
    :param verbose: If True, show all merged revisions, not just
117
123
        the merge tips
118
124
    :param versioned: If True, only shows versioned files.
 
125
    :param classify: Add special symbols to indicate file kind.
119
126
    :param show_long_callback: A callback: message = show_long_callback(to_file, delta, 
120
127
        show_ids, show_unchanged, indent, filter), only used with the long output
121
128
    """
122
129
    if show_unchanged is not None:
123
130
        warn("show_tree_status with show_unchanged has been deprecated "
124
 
             "since bzrlib 0.9", DeprecationWarning, stacklevel=2)
 
131
             "since breezy 0.9", DeprecationWarning, stacklevel=2)
125
132
 
126
133
    if to_file is None:
127
134
        to_file = sys.stdout
131
138
        new_is_working_tree = True
132
139
        if revision is None:
133
140
            if wt.last_revision() != wt.branch.last_revision():
134
 
                warning("working tree is out of date, run 'bzr update'")
 
141
                warning("working tree is out of date, run 'brz update'")
135
142
            new = wt
136
143
            old = new.basis_tree()
137
144
        elif len(revision) > 0:
138
145
            try:
139
146
                old = revision[0].as_tree(wt.branch)
140
 
            except errors.NoSuchRevision, e:
 
147
            except errors.NoSuchRevision as e:
141
148
                raise errors.BzrCommandError(str(e))
142
149
            if (len(revision) > 1) and (revision[1].spec is not None):
143
150
                try:
144
151
                    new = revision[1].as_tree(wt.branch)
145
152
                    new_is_working_tree = False
146
 
                except errors.NoSuchRevision, e:
 
153
                except errors.NoSuchRevision as e:
147
154
                    raise errors.BzrCommandError(str(e))
148
155
            else:
149
156
                new = wt
150
157
        old.lock_read()
151
158
        new.lock_read()
152
159
        try:
 
160
            for hook in hooks['pre_status']:
 
161
                hook(StatusHookParams(old, new, to_file, versioned,
 
162
                    show_ids, short, verbose, specific_files=specific_files))
 
163
 
153
164
            specific_files, nonexistents \
154
165
                = _filter_nonexistent(specific_files, old, new)
155
166
            want_unversioned = not versioned
156
167
 
157
168
            # Reporter used for short outputs
158
169
            reporter = _mod_delta._ChangeReporter(output_file=to_file,
159
 
                unversioned_filter=new.is_ignored)
 
170
                unversioned_filter=new.is_ignored, classify=classify)
160
171
            report_changes(to_file, old, new, specific_files, 
161
172
                           reporter, show_long_callback, 
162
173
                           short=short, want_unchanged=show_unchanged, 
163
 
                           want_unversioned=want_unversioned, show_ids=show_ids)
 
174
                           want_unversioned=want_unversioned, show_ids=show_ids,
 
175
                           classify=classify)
164
176
 
165
177
            # show the ignored files among specific files (i.e. show the files
166
178
            # identified from input that we choose to ignore). 
189
201
                    prefix = 'C  '
190
202
                else:
191
203
                    prefix = ' '
192
 
                to_file.write("%s %s\n" % (prefix, conflict))
 
204
                to_file.write("%s %s\n" % (prefix, unicode(conflict)))
193
205
            # Show files that were requested but don't exist (and are
194
206
            # not versioned).  We don't involve delta in this; these
195
207
            # paths are really the province of just the status
210
222
                show_pending_merges(new, to_file, short, verbose=verbose)
211
223
            if nonexistents:
212
224
                raise errors.PathsDoNotExist(nonexistents)
 
225
            for hook in hooks['post_status']:
 
226
                hook(StatusHookParams(old, new, to_file, versioned,
 
227
                    show_ids, short, verbose, specific_files=specific_files))
213
228
        finally:
214
229
            old.unlock()
215
230
            new.unlock()
319
334
        rev_id_iterator = _get_sorted_revisions(merge, merge_extra,
320
335
                            branch.repository.get_parent_map(merge_extra))
321
336
        # Skip the first node
322
 
        num, first, depth, eom = rev_id_iterator.next()
 
337
        num, first, depth, eom = next(rev_id_iterator)
323
338
        if first != merge:
324
339
            raise AssertionError('Somehow we misunderstood how'
325
340
                ' iter_topo_order works %s != %s' % (first, merge))
341
356
 
342
357
    If either of the two lists is empty, return it as an empty list.
343
358
 
344
 
    This can be used by operations such as bzr status that can accept
 
359
    This can be used by operations such as brz status that can accept
345
360
    unknown or ignored files.
346
361
    """
347
362
    mutter("check paths: %r", orig_paths)
356
371
    # their groups individually.  But for consistency of this
357
372
    # function's API, it's better to sort both than just 'nonexistent'.
358
373
    return sorted(remaining), sorted(nonexistent)
 
374
 
 
375
 
 
376
class StatusHooks(_mod_hooks.Hooks):
 
377
    """A dictionary mapping hook name to a list of callables for status hooks.
 
378
 
 
379
    e.g. ['post_status'] Is the list of items to be called when the
 
380
    status command has finished printing the status.
 
381
    """
 
382
 
 
383
    def __init__(self):
 
384
        """Create the default hooks.
 
385
 
 
386
        These are all empty initially, because by default nothing should get
 
387
        notified.
 
388
        """
 
389
        _mod_hooks.Hooks.__init__(self, "breezy.status", "hooks")
 
390
        self.add_hook('post_status',
 
391
            "Called with argument StatusHookParams after Bazaar has "
 
392
            "displayed the status. StatusHookParams has the attributes "
 
393
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
 
394
            "verbose). The last four arguments correspond to the command "
 
395
            "line options specified by the user for the status command. "
 
396
            "to_file is the output stream for writing.",
 
397
            (2, 3))
 
398
        self.add_hook('pre_status',
 
399
            "Called with argument StatusHookParams before Bazaar "
 
400
            "displays the status. StatusHookParams has the attributes "
 
401
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
 
402
            "verbose). The last four arguments correspond to the command "
 
403
            "line options specified by the user for the status command. "
 
404
            "to_file is the output stream for writing.",
 
405
            (2, 3))
 
406
 
 
407
 
 
408
class StatusHookParams(object):
 
409
    """Object holding parameters passed to post_status hooks.
 
410
 
 
411
    :ivar old_tree: Start tree (basis tree) for comparison.
 
412
    :ivar new_tree: Working tree.
 
413
    :ivar to_file: If set, write to this file.
 
414
    :ivar versioned: Show only versioned files.
 
415
    :ivar show_ids: Show internal object ids.
 
416
    :ivar short: Use short status indicators.
 
417
    :ivar verbose: Verbose flag.
 
418
    """
 
419
 
 
420
    def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
 
421
            short, verbose, specific_files=None):
 
422
        """Create a group of post_status hook parameters.
 
423
 
 
424
        :param old_tree: Start tree (basis tree) for comparison.
 
425
        :param new_tree: Working tree.
 
426
        :param to_file: If set, write to this file.
 
427
        :param versioned: Show only versioned files.
 
428
        :param show_ids: Show internal object ids.
 
429
        :param short: Use short status indicators.
 
430
        :param verbose: Verbose flag.
 
431
        :param specific_files: If set, a list of filenames whose status should be
 
432
            shown.  It is an error to give a filename that is not in the working
 
433
            tree, or in the working inventory or in the basis inventory.
 
434
        """
 
435
        self.old_tree = old_tree
 
436
        self.new_tree = new_tree
 
437
        self.to_file = to_file
 
438
        self.versioned = versioned
 
439
        self.show_ids = show_ids
 
440
        self.short = short
 
441
        self.verbose = verbose
 
442
        self.specific_files = specific_files
 
443
 
 
444
    def __eq__(self, other):
 
445
        return self.__dict__ == other.__dict__
 
446
 
 
447
    def __repr__(self):
 
448
        return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
 
449
            self.old_tree, self.new_tree, self.to_file, self.versioned,
 
450
            self.show_ids, self.short, self.verbose, self.specific_files)
 
451
 
 
452
 
 
453
def _show_shelve_summary(params):
 
454
    """post_status hook to display a summary of shelves.
 
455
 
 
456
    :param params: StatusHookParams.
 
457
    """
 
458
    # Don't show shelves if status of specific files is being shown, only if
 
459
    # no file arguments have been passed
 
460
    if params.specific_files:
 
461
        return
 
462
    get_shelf_manager = getattr(params.new_tree, 'get_shelf_manager', None)
 
463
    if get_shelf_manager is None:
 
464
        return
 
465
    manager = get_shelf_manager()
 
466
    shelves = manager.active_shelves()
 
467
    if shelves:
 
468
        singular = '%d shelf exists. '
 
469
        plural = '%d shelves exist. '
 
470
        if len(shelves) == 1:
 
471
            fmt = singular
 
472
        else:
 
473
            fmt = plural
 
474
        params.to_file.write(fmt % len(shelves))
 
475
        params.to_file.write('See "brz shelve --list" for details.\n')
 
476
 
 
477
 
 
478
hooks = StatusHooks()
 
479
 
 
480
 
 
481
hooks.install_named_hook('post_status', _show_shelve_summary,
 
482
    'brz status')
 
483