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

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
    range,
90
90
    zip,
91
91
    )
92
 
from .tree import find_previous_path
 
92
from .tree import InterTree
93
93
 
94
94
 
95
95
def find_touching_revisions(repository, last_revision, last_tree, last_path):
109
109
    revno = len(history)
110
110
    for revision_id in history:
111
111
        this_tree = repository.revision_tree(revision_id)
112
 
        this_path = find_previous_path(last_tree, this_tree, last_path)
 
112
        this_intertree = InterTree.get(this_tree, last_tree)
 
113
        this_path = this_intertree.find_source_path(last_path)
113
114
 
114
115
        # now we know how it was last time, and how it is in this revision.
115
116
        # are those two states effectively the same or not?
136
137
 
137
138
def show_log(branch,
138
139
             lf,
139
 
             specific_fileid=None,
140
140
             verbose=False,
141
141
             direction='reverse',
142
142
             start_revision=None,
154
154
 
155
155
    :param lf: The LogFormatter object showing the output.
156
156
 
157
 
    :param specific_fileid: If not None, list only the commits affecting the
158
 
        specified file, rather than all commits.
159
 
 
160
157
    :param verbose: If True show added/changed/deleted/renamed files.
161
158
 
162
159
    :param direction: 'reverse' (default) is latest to earliest; 'forward' is
177
174
    :param match: Dictionary of search lists to use when matching revision
178
175
      properties.
179
176
    """
180
 
    # Convert old-style parameters to new-style parameters
181
 
    if specific_fileid is not None:
182
 
        file_ids = [specific_fileid]
183
 
    else:
184
 
        file_ids = None
185
177
    if verbose:
186
 
        if file_ids:
187
 
            delta_type = 'partial'
188
 
        else:
189
 
            delta_type = 'full'
 
178
        delta_type = 'full'
190
179
    else:
191
180
        delta_type = None
192
181
    if show_diff:
193
 
        if file_ids:
194
 
            diff_type = 'partial'
195
 
        else:
196
 
            diff_type = 'full'
 
182
        diff_type = 'full'
197
183
    else:
198
184
        diff_type = None
199
185
 
200
186
    if isinstance(start_revision, int):
201
187
        try:
202
188
            start_revision = revisionspec.RevisionInfo(branch, start_revision)
203
 
        except errors.NoSuchRevision:
 
189
        except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
204
190
            raise errors.InvalidRevisionNumber(start_revision)
205
191
 
206
192
    if isinstance(end_revision, int):
207
193
        try:
208
194
            end_revision = revisionspec.RevisionInfo(branch, end_revision)
209
 
        except errors.NoSuchRevision:
 
195
        except (errors.NoSuchRevision, errors.RevnoOutOfBounds):
210
196
            raise errors.InvalidRevisionNumber(end_revision)
211
197
 
212
198
    if end_revision is not None and end_revision.revno == 0:
213
199
        raise errors.InvalidRevisionNumber(end_revision.revno)
214
200
 
215
201
    # Build the request and execute it
216
 
    rqst = make_log_request_dict(direction=direction, specific_fileids=file_ids,
217
 
                                 start_revision=start_revision, end_revision=end_revision,
218
 
                                 limit=limit, message_search=search,
219
 
                                 delta_type=delta_type, diff_type=diff_type)
 
202
    rqst = make_log_request_dict(
 
203
        direction=direction,
 
204
        start_revision=start_revision, end_revision=end_revision,
 
205
        limit=limit, message_search=search,
 
206
        delta_type=delta_type, diff_type=diff_type)
220
207
    Logger(branch, rqst).show(lf)
221
208
 
222
209
 
747
734
    repo = branch.repository
748
735
    graph = repo.get_graph()
749
736
    if start_rev_id is None and end_rev_id is None:
750
 
        try:
751
 
            br_revno, br_rev_id = branch.last_revision_info()
752
 
        except errors.GhostRevisionsHaveNoRevno:
 
737
        if branch._format.stores_revno() or \
 
738
                config.GlobalStack().get('calculate_revnos'):
 
739
            try:
 
740
                br_revno, br_rev_id = branch.last_revision_info()
 
741
            except errors.GhostRevisionsHaveNoRevno:
 
742
                br_rev_id = branch.last_revision()
 
743
                cur_revno = None
 
744
            else:
 
745
                cur_revno = br_revno
 
746
        else:
753
747
            br_rev_id = branch.last_revision()
754
748
            cur_revno = None
755
 
        else:
756
 
            cur_revno = br_revno
 
749
 
757
750
        graph_iter = graph.iter_lefthand_ancestry(br_rev_id,
758
751
                                                  (_mod_revision.NULL_REVISION,))
759
752
        while True:
1024
1017
      fileids set once their add or remove entry is detected respectively
1025
1018
    """
1026
1019
    if stop_on == 'add':
1027
 
        for item in delta.added:
1028
 
            if item[1] in fileids:
1029
 
                fileids.remove(item[1])
 
1020
        for item in delta.added + delta.copied:
 
1021
            if item.file_id in fileids:
 
1022
                fileids.remove(item.file_id)
1030
1023
    elif stop_on == 'delete':
1031
1024
        for item in delta.removed:
1032
 
            if item[1] in fileids:
1033
 
                fileids.remove(item[1])
 
1025
            if item.file_id in fileids:
 
1026
                fileids.remove(item.file_id)
1034
1027
 
1035
1028
 
1036
1029
def _make_revision_objects(branch, generate_delta, search, log_rev_iterator):
1105
1098
            raise TypeError(start_revision)
1106
1099
        end_rev_id = end_revision.rev_id
1107
1100
        end_revno = end_revision.revno
1108
 
    if end_revno is None:
1109
 
        try:
1110
 
            end_revno = branch.revno()
1111
 
        except errors.GhostRevisionsHaveNoRevno:
1112
 
            end_revno = None
1113
1101
 
1114
1102
    if branch.last_revision() != _mod_revision.NULL_REVISION:
1115
1103
        if (start_rev_id == _mod_revision.NULL_REVISION
1807
1795
 
1808
1796
        if revision.delta is not None and revision.delta.has_changed():
1809
1797
            for c in revision.delta.added + revision.delta.removed + revision.delta.modified:
1810
 
                path, = c[:1]
 
1798
                if c.path[0] is None:
 
1799
                    path = c.path[1]
 
1800
                else:
 
1801
                    path = c.path[0]
1811
1802
                to_file.write('\t* %s:\n' % (path,))
1812
 
            for c in revision.delta.renamed:
1813
 
                oldpath, newpath = c[:2]
 
1803
            for c in revision.delta.renamed + revision.delta.copied:
1814
1804
                # For renamed files, show both the old and the new path
1815
 
                to_file.write('\t* %s:\n\t* %s:\n' % (oldpath, newpath))
 
1805
                to_file.write('\t* %s:\n\t* %s:\n' % (c.path[0], c.path[1]))
1816
1806
            to_file.write('\n')
1817
1807
 
1818
1808
        if not revision.rev.message:
1949
1939
        to_file.write('Added Revisions:\n')
1950
1940
        show_log(branch,
1951
1941
                 lf,
1952
 
                 None,
1953
1942
                 verbose=False,
1954
1943
                 direction='forward',
1955
1944
                 start_revision=base_idx + 1,
2034
2023
    if new_history != []:
2035
2024
        output.write('Added Revisions:\n')
2036
2025
        start_revno = new_revno - len(new_history) + 1
2037
 
        show_log(branch, lf, None, verbose=False, direction='forward',
 
2026
        show_log(branch, lf, verbose=False, direction='forward',
2038
2027
                 start_revision=start_revno)
2039
2028
 
2040
2029
 
2052
2041
        lf.log_revision(lr)
2053
2042
 
2054
2043
 
2055
 
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
 
2044
def _get_info_for_log_files(revisionspec_list, file_list, exit_stack):
2056
2045
    """Find file-ids and kinds given a list of files and a revision range.
2057
2046
 
2058
2047
    We search for files at the end of the range. If not found there,
2062
2051
    :param file_list: the list of paths given on the command line;
2063
2052
      the first of these can be a branch location or a file path,
2064
2053
      the remainder must be file paths
2065
 
    :param add_cleanup: When the branch returned is read locked,
2066
 
      an unlock call will be queued to the cleanup.
 
2054
    :param exit_stack: When the branch returned is read locked,
 
2055
      an unlock call will be queued to the exit stack.
2067
2056
    :return: (branch, info_list, start_rev_info, end_rev_info) where
2068
2057
      info_list is a list of (relative_path, file_id, kind) tuples where
2069
2058
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2072
2061
    from breezy.builtins import _get_revision_range
2073
2062
    tree, b, path = controldir.ControlDir.open_containing_tree_or_branch(
2074
2063
        file_list[0])
2075
 
    add_cleanup(b.lock_read().unlock)
 
2064
    exit_stack.enter_context(b.lock_read())
2076
2065
    # XXX: It's damn messy converting a list of paths to relative paths when
2077
2066
    # those paths might be deleted ones, they might be on a case-insensitive
2078
2067
    # filesystem and/or they might be in silly locations (like another branch).