Merge lp:~jelmer/brz/cat-no-file-id into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/cat-no-file-id
Merge into: lp:brz
Diff against target: 69 lines (+21/-21)
1 file modified
breezy/builtins.py (+21/-21)
To merge this branch: bzr merge lp:~jelmer/brz/cat-no-file-id
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+358951@code.launchpad.net

Commit message

Avoid using file ids in cat; use find_previous_path instead.

Description of the change

Avoid using file ids in cat; use find_previous_path instead.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks reasonable, see inline comment about comment comment.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/builtins.py'
2--- breezy/builtins.py 2018-11-16 18:35:30 +0000
3+++ breezy/builtins.py 2018-11-18 12:07:59 +0000
4@@ -54,6 +54,7 @@
5 symbol_versioning,
6 timestamp,
7 transport,
8+ tree as _mod_tree,
9 ui,
10 urlutils,
11 views,
12@@ -3432,38 +3433,37 @@
13 rev_tree = _get_one_revision_tree('cat', revision, branch=b)
14 self.add_cleanup(rev_tree.lock_read().unlock)
15
16- old_file_id = rev_tree.path2id(relpath)
17-
18- # TODO: Split out this code to something that generically finds the
19- # best id for a path across one or more trees; it's like
20- # find_ids_across_trees but restricted to find just one. -- mbp
21- # 20110705.
22 if name_from_revision:
23 # Try in revision if requested
24- if old_file_id is None:
25+ if not rev_tree.is_versioned(relpath):
26 raise errors.BzrCommandError(gettext(
27 "{0!r} is not present in revision {1}").format(
28 filename, rev_tree.get_revision_id()))
29- else:
30- actual_file_id = old_file_id
31+ rev_tree_path = relpath
32 else:
33- cur_file_id = tree.path2id(relpath)
34- if cur_file_id is not None and rev_tree.has_id(cur_file_id):
35- actual_file_id = cur_file_id
36- elif old_file_id is not None:
37- actual_file_id = old_file_id
38- else:
39- raise errors.BzrCommandError(gettext(
40- "{0!r} is not present in revision {1}").format(
41- filename, rev_tree.get_revision_id()))
42- relpath = rev_tree.id2path(actual_file_id)
43+ try:
44+ rev_tree_path = _mod_tree.find_previous_path(
45+ tree, rev_tree, relpath)
46+ except errors.NoSuchFile:
47+ rev_tree_path = None
48+
49+ if rev_tree_path is None:
50+ # Path didn't exist in working tree
51+ if not rev_tree.is_versioned(relpath):
52+ raise errors.BzrCommandError(gettext(
53+ "{0!r} is not present in revision {1}").format(
54+ filename, rev_tree.get_revision_id()))
55+ else:
56+ # Fall back to the same path in the basis tree, if present.
57+ rev_tree_path = relpath
58+
59 if filtered:
60 from .filter_tree import ContentFilterTree
61 filter_tree = ContentFilterTree(
62 rev_tree, rev_tree._content_filter_stack)
63- fileobj = filter_tree.get_file(relpath)
64+ fileobj = filter_tree.get_file(rev_tree_path)
65 else:
66- fileobj = rev_tree.get_file(relpath)
67+ fileobj = rev_tree.get_file(rev_tree_path)
68 shutil.copyfileobj(fileobj, self.outf)
69 self.cleanup_now()
70

Subscribers

People subscribed via source and target branches