Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brancher: do not get tree if there's no revs #3211

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dvc/repo/brancher.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def brancher( # noqa: E302
revs.extend(scm.list_tags())

try:
for sha, names in group_by(scm.resolve_rev, revs).items():
self.tree = scm.get_tree(sha)
yield ", ".join(names)
if revs:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be caught by:

    if not any([revs, all_branches, all_tags, all_commits]):
        yield ""
        return

🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh, but I saw that you were doing all_*=True 🙂

Copy link

@ghost ghost Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, @skshetry , why didn't you solve it by using if not scm: return ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, brancher doesn't have anything to do when NoSCM is used.

So, it would be:

    scm = self.scm

    if not any([revs, all_branches, all_tags, all_commits]) or not scm:
        yield ""
        return

I guess that, since the end result is the same, it doesn't matter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scm is always there. If it's a non-git repo, it will be NoSCM.
Honestly, I didn't really feel confident around brancher() (this is an uncovered corner). I really just added here because of the finally statement here that resets the self.tree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which doesn't make your point wrong, I'm just saying.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efiop , I don't get why revs=["something"] is intentionally breaking it but no all_commits=True.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrOutis because it expects to receive revs that are valid in the scm that we are operating in and there are no valid revs in NoSCM. And all_commits=True asks scm for list of all commits, which are [] for NoSCM. I agree that brancher could be improved to handle those cases more smoothly, but this fix does get the job done in this case.

Copy link
Member Author

@skshetry skshetry Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as my understanding goes, the NoSCM case and working tree should not even be the concern of the brancher().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like someone has been here and changed things, and forgot to update the docstrings.

for sha, names in group_by(scm.resolve_rev, revs).items():
self.tree = scm.get_tree(sha)
yield ", ".join(names)
finally:
self.tree = saved_tree