/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
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

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
 
 
19
17
import sys
20
18
 
21
19
from . import (
68
66
 
69
67
    if short:
70
68
        changes = new.iter_changes(old, want_unchanged, specific_files,
71
 
            require_versioned=False, want_unversioned=want_unversioned)
 
69
                                   require_versioned=False, want_unversioned=want_unversioned)
72
70
        _mod_delta.report_changes(changes, show_short_reporter)
73
71
    else:
74
72
        delta = new.changes_from(old, want_unchanged=want_unchanged,
75
 
                              specific_files=specific_files,
76
 
                              want_unversioned=want_unversioned)
 
73
                                 specific_files=specific_files,
 
74
                                 want_unversioned=want_unversioned)
77
75
        # filter out unknown files. We may want a tree method for
78
76
        # this
79
 
        delta.unversioned = [unversioned for unversioned in
80
 
            delta.unversioned if not new.is_ignored(unversioned[0])]
 
77
        delta.unversioned = [change for change in delta.unversioned
 
78
                             if not new.is_ignored(change.path[1])]
81
79
        show_long_callback(to_file, delta,
82
80
                           show_ids=show_ids,
83
81
                           show_unchanged=want_unchanged,
128
126
    if to_file is None:
129
127
        to_file = sys.stdout
130
128
 
131
 
    wt.lock_read()
132
 
    try:
 
129
    with wt.lock_read():
133
130
        new_is_working_tree = True
134
131
        if revision is None:
135
132
            if wt.last_revision() != wt.branch.last_revision():
149
146
                    raise errors.BzrCommandError(str(e))
150
147
            else:
151
148
                new = wt
152
 
        old.lock_read()
153
 
        new.lock_read()
154
 
        try:
 
149
        with old.lock_read(), new.lock_read():
155
150
            for hook in hooks['pre_status']:
156
 
                hook(StatusHookParams(old, new, to_file, versioned,
157
 
                    show_ids, short, verbose, specific_files=specific_files))
 
151
                hook(StatusHookParams(
 
152
                    old, new, to_file, versioned, show_ids, short, verbose,
 
153
                    specific_files=specific_files))
158
154
 
159
155
            specific_files, nonexistents \
160
156
                = _filter_nonexistent(specific_files, old, new)
161
157
            want_unversioned = not versioned
162
158
 
163
159
            # Reporter used for short outputs
164
 
            reporter = _mod_delta._ChangeReporter(output_file=to_file,
165
 
                unversioned_filter=new.is_ignored, classify=classify)
 
160
            reporter = _mod_delta._ChangeReporter(
 
161
                output_file=to_file, unversioned_filter=new.is_ignored,
 
162
                classify=classify)
166
163
            report_changes(to_file, old, new, specific_files,
167
164
                           reporter, show_long_callback,
168
165
                           short=short, want_unversioned=want_unversioned,
173
170
            if specific_files is not None:
174
171
                # Ignored files is sorted because specific_files is already sorted
175
172
                ignored_files = [specific for specific in
176
 
                    specific_files if new.is_ignored(specific)]
 
173
                                 specific_files if new.is_ignored(specific)]
177
174
                if len(ignored_files) > 0 and not short:
178
175
                    to_file.write("ignored:\n")
179
176
                    prefix = ' '
186
183
            # delta.
187
184
            conflicts = new.conflicts()
188
185
            if specific_files is not None:
189
 
                conflicts = conflicts.select_conflicts(new, specific_files,
190
 
                    ignore_misses=True, recurse=True)[1]
 
186
                conflicts = conflicts.select_conflicts(
 
187
                    new, specific_files, ignore_misses=True, recurse=True)[1]
191
188
            if len(conflicts) > 0 and not short:
192
189
                to_file.write("conflicts:\n")
193
190
            for conflict in conflicts:
195
192
                    prefix = 'C  '
196
193
                else:
197
194
                    prefix = ' '
198
 
                to_file.write("%s %s\n" % (prefix, unicode(conflict)))
 
195
                to_file.write("%s %s\n" % (prefix, conflict.describe()))
199
196
            # Show files that were requested but don't exist (and are
200
197
            # not versioned).  We don't involve delta in this; these
201
198
            # paths are really the province of just the status
217
214
            if nonexistents:
218
215
                raise errors.PathsDoNotExist(nonexistents)
219
216
            for hook in hooks['post_status']:
220
 
                hook(StatusHookParams(old, new, to_file, versioned,
221
 
                    show_ids, short, verbose, specific_files=specific_files))
222
 
        finally:
223
 
            old.unlock()
224
 
            new.unlock()
225
 
    finally:
226
 
        wt.unlock()
 
217
                hook(StatusHookParams(
 
218
                    old, new, to_file, versioned, show_ids, short, verbose,
 
219
                    specific_files=specific_files))
227
220
 
228
221
 
229
222
def _get_sorted_revisions(tip_revision, revision_ids, parent_map):
242
235
    # of any references pointing outside of this graph.
243
236
    parent_graph = {}
244
237
    for revision_id in revision_ids:
245
 
        if revision_id not in parent_map: # ghost
 
238
        if revision_id not in parent_map:  # ghost
246
239
            parent_graph[revision_id] = []
247
240
        else:
248
241
            # Only include parents which are in this sub-graph
249
242
            parent_graph[revision_id] = [p for p in parent_map[revision_id]
250
 
                                            if p in revision_ids]
 
243
                                         if p in revision_ids]
251
244
    sorter = tsort.MergeSorter(parent_graph, tip_revision)
252
245
    return sorter.iter_topo_order()
253
246
 
294
287
            rev = branch.repository.get_revision(merge)
295
288
        except errors.NoSuchRevision:
296
289
            # If we are missing a revision, just print out the revision id
297
 
            to_file.write(first_prefix + '(ghost) ' + merge + '\n')
 
290
            to_file.write(first_prefix + '(ghost) ' +
 
291
                          merge.decode('utf-8') + '\n')
298
292
            other_revisions.append(merge)
299
293
            continue
300
294
 
314
308
 
315
309
        # Display the revisions brought in by this merge.
316
310
        rev_id_iterator = _get_sorted_revisions(merge, merge_extra,
317
 
                            branch.repository.get_parent_map(merge_extra))
 
311
                                                branch.repository.get_parent_map(merge_extra))
318
312
        # Skip the first node
319
313
        num, first, depth, eom = next(rev_id_iterator)
320
314
        if first != merge:
321
315
            raise AssertionError('Somehow we misunderstood how'
322
 
                ' iter_topo_order works %s != %s' % (first, merge))
 
316
                                 ' iter_topo_order works %s != %s' % (first, merge))
323
317
        for num, sub_merge, depth, eom in rev_id_iterator:
324
318
            rev = revisions[sub_merge]
325
319
            if rev is None:
326
 
                to_file.write(sub_prefix + '(ghost) ' + sub_merge + '\n')
 
320
                to_file.write(sub_prefix + '(ghost) ' +
 
321
                              sub_merge.decode('utf-8') + '\n')
327
322
                continue
328
323
            show_log_message(revisions[sub_merge], sub_prefix)
329
324
 
347
342
    s = old_tree.filter_unversioned_files(orig_paths)
348
343
    s = new_tree.filter_unversioned_files(s)
349
344
    nonexistent = [path for path in s if not new_tree.has_filename(path)]
350
 
    remaining   = [path for path in orig_paths if not path in nonexistent]
 
345
    remaining = [path for path in orig_paths if path not in nonexistent]
351
346
    # Sorting the 'remaining' list doesn't have much effect in
352
347
    # practice, since the various status output sections will sort
353
348
    # their groups individually.  But for consistency of this
369
364
        notified.
370
365
        """
371
366
        _mod_hooks.Hooks.__init__(self, "breezy.status", "hooks")
372
 
        self.add_hook('post_status',
 
367
        self.add_hook(
 
368
            'post_status',
373
369
            "Called with argument StatusHookParams after Bazaar has "
374
370
            "displayed the status. StatusHookParams has the attributes "
375
371
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
377
373
            "line options specified by the user for the status command. "
378
374
            "to_file is the output stream for writing.",
379
375
            (2, 3))
380
 
        self.add_hook('pre_status',
 
376
        self.add_hook(
 
377
            'pre_status',
381
378
            "Called with argument StatusHookParams before Bazaar "
382
379
            "displays the status. StatusHookParams has the attributes "
383
380
            "(old_tree, new_tree, to_file, versioned, show_ids, short, "
400
397
    """
401
398
 
402
399
    def __init__(self, old_tree, new_tree, to_file, versioned, show_ids,
403
 
            short, verbose, specific_files=None):
 
400
                 short, verbose, specific_files=None):
404
401
        """Create a group of post_status hook parameters.
405
402
 
406
403
        :param old_tree: Start tree (basis tree) for comparison.
411
408
        :param short: Use short status indicators.
412
409
        :param verbose: Verbose flag.
413
410
        :param specific_files: If set, a list of filenames whose status should be
414
 
            shown.  It is an error to give a filename that is not in the working
415
 
            tree, or in the working inventory or in the basis inventory.
 
411
            shown.  It is an error to give a filename that is not in the
 
412
            working tree, or in the working inventory or in the basis inventory.
416
413
        """
417
414
        self.old_tree = old_tree
418
415
        self.new_tree = new_tree
427
424
        return self.__dict__ == other.__dict__
428
425
 
429
426
    def __repr__(self):
430
 
        return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (self.__class__.__name__,
431
 
            self.old_tree, self.new_tree, self.to_file, self.versioned,
432
 
            self.show_ids, self.short, self.verbose, self.specific_files)
 
427
        return "<%s(%s, %s, %s, %s, %s, %s, %s, %s)>" % (
 
428
            self.__class__.__name__, self.old_tree, self.new_tree,
 
429
            self.to_file, self.versioned, self.show_ids, self.short,
 
430
            self.verbose, self.specific_files)
433
431
 
434
432
 
435
433
def _show_shelve_summary(params):
465
463
 
466
464
 
467
465
hooks.install_named_hook('post_status', _show_shelve_summary,
468
 
    'brz status')
469
 
 
 
466
                         'brz status')