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

AttributeError: 'MBInfo' object has no attribute 'diff' #5

Open
white-gecko opened this issue Aug 19, 2021 · 3 comments
Open

AttributeError: 'MBInfo' object has no attribute 'diff' #5

white-gecko opened this issue Aug 19, 2021 · 3 comments

Comments

@white-gecko
Copy link
Contributor

git-diff-search fails with:

=== Gathering commit tree
=== Finding branching/merging commits
=== Rough search following only branch/merge commits
Setze Branch 'tmp' neu
c389cb7 (      547)  
Traceback (most recent call last):
  File "git-diff-search.py", line 205, in <module>
    status.follow_commits(status.commits[status.first[:7]],jump='knots',**kw)
  File "git-diff-search.py", line 163, in follow_commits
    cur = metric(node)
  File "git-diff-search.py", line 115, in fastdiff
    if c.diff is not None:
AttributeError: 'MBInfo' object has no attribute 'diff'
@white-gecko
Copy link
Contributor Author

@burnpanck I also ping you, as the python implementation is coming from you.

@burnpanck
Copy link
Contributor

Huh, that was a long time ago, took me some time to even recognise what this was! I was even using Enthought's traits back then... These days, I would probably use either plain python dataclasses or potentially attrs.

In any case, I have no intention to spend much time on this at this point. I vaguely remember that the script simplifies the git commit tree to a graph where branch and merge commits are considered nodes, and sequences of regular commits are edges. It then first selects the "best" edge, and bisects that edge to find the best commit. The failure seems to come from the edge selection part.

Apparently, each commit is represented using a Commit object, while the graph is encoded in MBInfo objects. It seems that at some point, the latter is accidentally fed into the metric function, while it should have been the associated former instead. Doing a detailed type analysis might bring clarity (maybe with the help of type annotations and a good static type checker, e.g. in your editor or mypy). Alternatively, you could try to fix it using

if isinstance(c, MBInfo):
    c = c.commit

although one should never fix something one doesn't understand, and I don't fully understand the exact issue here.

@white-gecko
Copy link
Contributor Author

Thank you very much for the reply. I've now solved my issue with a simple loop, as for my use case it is not important to analyze the complete graph. Further, I only had to compare a single file and not a complete tree.

Here my line for the reference.

for i in $( git log --oneline path/in/the/repo/file.py | awk '{print $1}' ); do git show --raw $i | grep path/in/the/repo/file.py | awk '{print $4}' | xargs git show --raw | diff -w path/to/the/file/i/want/to/compare/file.py - | grep "^<" | wc -l ; echo $i ; done

(The grep "^<" can be replaced with grep "^>" of cause.)
There should be room for improvements, maybe it can be simplified or provide better output in some way (additions and deletions in one run, showing the commit message and date, …)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants