Tuesday, September 18, 2012

Tracking down unused variables with Pyflakes and git bisect

I was working on a Python project when I noticed a variable that was defined but never used. Does this indicate that some important code was accidentally deleted? Or was there just a minor oversight during refactoring?

To answer this question, I wanted to see the Git commit which removed the last use of this variable. This sounds like a job for git bisect. And because Pyflakes can detect unused variables, the whole process is completely automatic.

I made a guess that the mystery_variable became unused sometime within the past two weeks. Then I told Git to consider a commit "good" if Pyflakes's list of complaints does not mention mystery_variable.

$ git bisect start master master@{'2 weeks ago'}
Already on 'master'
Bisecting: 150 revisions left to test after this (roughly 7 steps)
[066327622129dbe863f6e2fc4746ff9e869bd049] Synthesize gravity

$ git bisect run bash -c '! pyflakes foo.py | grep mystery_variable'
running bash -c ! pyflakes foo.py | grep mystery_variable
Bisecting: 75 revisions left to test after this (roughly 6 steps)
[d3a5665eff478cccfb86d994a8fc289446325fbf] Model object components
running bash -c ! pyflakes foo.py | grep mystery_variable
Bisecting: 37 revisions left to test after this (roughly 5 steps)
[6ddcfbf27a1a4548acf972a6b817e485743f6bd9] Time-compress simulator clock
...

running bash -c ! pyflakes foo.py | grep mystery_variable
9c2b2f006207ae9f274f9182efeb3e009d18ed04 is the first bad commit
commit 9c2b2f006207ae9f274f9182efeb3e009d18ed04
Author: Ben Bitdiddle <bitdiddle@example.com>
Date:   Fri Sep 14 01:38:31 2012 -0400

    Reticulate splines

Now I can examine this commit and see what happened.

43 comments:

  1. Another option that is often useful is to run "git log -Smystery_variable" (just in case you were not aware of it).

    ReplyDelete
  2. Nice article, thanks for the information. It's very complete information. I will bookmark for next reference
    jaring futsal | jaring golf | jaring pengaman proyek |
    jaring pengaman bangunan | jaring pengaman gedung
    http://www.jual-jaring.blogspot.com/
    http://www.agen-jaring.blogspot.com/
    http://www.pancasamudera-safetynet.blogspot.com/
    http://www.toko-jaring.blogspot.com/
    http://www.pusat-jaring.blogspot.com/
    http://jualjaringpengaman.blogspot.com/
    https://pancasamudera.wordpress.com/
    https://pasangjaringfutsal.wordpress.com/
    https://jualtambangmurah.wordpress.com/
    https://tokojaring.wordpress.com/
    https://jualjaringfutsal.wordpress.com/
    https://jaringfutsal.wordpress.com/


    ReplyDelete
  3. Our strong network of movers and packers in India assist us to reach you anywhere in India and relocate you from your existing place to the desired destination.
    Packers and Movers Faridabad
    Packers and Movers Delhi
    Packers and Movers Ghaziabad
    Packers and Movers Noida

    ReplyDelete
  4. Exoprt Packers and Movers in India are known to provide moving & packing services at the rates that actually fit in make you local shifting solutions experts for amazing only.
    Packers and Movers in Bangalore
    Packers and Movers in Hyderabad
    Packers and Movers in Chennai
    Packers and Movers in Mumbai
    Packers and Movers in Pune

    ReplyDelete
  5. How did you can avail the experts services of listed Adword India's No 1 companies?
    Thanks for information visit: http://www.adword.co.in/

    ReplyDelete
  6. This is useful content. really apreciate it!Great post....such a brilliant and mindful post Please Visit Our Webpage:
    http://thebusinessplace.in/
    http://thebusinessplace.in/packers-and-movers-adivare-pune
    For contacting us u may not need to call and spend money. Keeping in mind the customers convenience alternate chat enquiry option is added to website. At the right corner you can leave enquiry anytime for further information about the shifting services we provide. Movers And Packers Pune service operator will provide you with the information required via chat or will call you as per your suitability. Even u can Call us to 24x7 available services on 7023102310.

    ReplyDelete
  7. This is useful content. really apreciate it! Please Visit Our Webpage:
    http://thebusinessplace.in/
    http://thebusinessplace.in/packers-and-movers-adivare-pune
    For contacting us u may not need to call and spend money. Keeping in mind the customers convenience alternate chat enquiry option is added to website. At the right corner you can leave enquiry anytime for further information about the shifting services we provide. Movers And Packers Pune service operator will provide you with the information required via chat or will call you as per your suitability. Even u can Call us to 24x7 available services.

    ReplyDelete
  8. Thanks for sharing such a great article and it’s helpful for everyone. Great Post..
    http://packersmoversbangalore.in/

    ReplyDelete
  9. Thanks for sharing such a great article and it’s helpful for everyone. Great Post..
    http://packersmoversbangalore.in/

    ReplyDelete
  10. I must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1...Please visit our wonderful and valuable website-
    http://packersmoverschennai.in/
    http://packersmoverschennai.in/packers-and-movers-indian-institute-of-technology-chennai
    http://packersmoverschennai.in/packers-and-movers-mambalam-r-s-chennai
    http://packersmoverschennai.in/packers-and-movers-indian-institute-of-technology-chennai

    ReplyDelete
  11. I must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1...Please visit our wonderful and valuable website-
    http://packersmoverschennai.in/
    http://packersmoverschennai.in/packers-and-movers-indian-institute-of-technology-chennai
    http://packersmoverschennai.in/packers-and-movers-mambalam-r-s-chennai
    http://packersmoverschennai.in/packers-and-movers-indian-institute-of-technology-chennai

    ReplyDelete
  12. Top Packers And Movers Kolkata labors are trustworthy and answerable to us. Don’t worry about the fraud or any kind of theft in the relocating process. During the whole journey, in the pathway our local vendors check to ensure the safety of the customer’s good till it gets deliver to its owner.
    http://kolkatapackersmovers.in/
    http://kolkatapackersmovers.in/packers-and-movers-bartala-kolkata

    ReplyDelete
  13. A good informative post that you have shared and appreciate your work for sharing the information.....!!
    Packers and Movers Kolkata, Local Shifting Relocation and Top Movers Packers Kolkata. Packers and Movers Kolkata Household @ www.KolkataPackersMovers.in
    http://kolkatapackersmovers.in/
    http://kolkatapackersmovers.in/packers-and-movers-behala-kolkata

    ReplyDelete
  14. Generally I don’t read article on blogs, but I would like to say that this write-up very compelled me to take
    a look at and do so! Your writing style has been amazed me.
    Thank you, very great post.
    .Please visit our wonderful and valuable website-http://packersmovershyderabadcity.in/
    http://blog.packersmovershyderabadcity.in/

    ReplyDelete
  15. Generally I don’t read article on blogs, but I would like to say that this write-up very compelled me to take
    a look at and do so! Your writing style has been amazed me.
    Thank you, very great post.
    .Please visit our wonderful and valuable website-http://packersmovershyderabadcity.in/
    http://blog.packersmovershyderabadcity.in/

    ReplyDelete
  16. http://zetaclear2014.weebly.com/
    http://venapro2014.weebly.com/
    http://breast-actives.hpage.com/
    http://breastactives-us.weebly.com/
    http://tinnituscontrol2014.weebly.com/
    http://idollash2014.weebly.com/
    http://breastactivesb.weebly.com/
    http://xtremeno2014.weebly.com/
    http://eazol2014.weebly.com/
    http://xtremeno-us.weebly.com/
    http://idollash-us.weebly.com/
    http://buy-breast-actives.weebly.com/
    http://hghenergizer2014.weebly.com/
    http://tinnituscontrol-us.weebly.com/
    http://breastactivesresultsr.webs.com/
    http://zetaclear-us.weebly.com/
    http://hghenergizer-us.weebly.com/
    http://wartrol-us.weebly.com/
    http://breastactivesbuycheap.page.tl/
    http://venapro-us.weebly.com/

    ReplyDelete
  17. Get a wide range of packing and moving companies at helloenquiry.in. We endeavour to furnish the best packers and movers companies in Patna at ease of Internet. Packers and Movers Patna

    ReplyDelete
  18. Packers Movers Mumbai are one of the leading packers and movers. Movers And Packers Mumbai are offering our services not only in Mumbai but also other major cities of India.Movers engaged in packing, loading and unloading, transportation/moving, car transportation, warehousing, Packing And Moving services in India.
    http://packersmoversmumbaicity.in/

    ReplyDelete
  19. I really enjoyed reading your blog, you have lots of great content.Please visit here:
    http://bhubaneswarpackersmovers.in/
    We are expert in Handling, Movers And Packers Bhubaneswar and Packing & Shifting of Household Goods, Office goods, Commercial Equipment and Car, Logistics and Transportation.

    ReplyDelete
  20. i must say you had done a tremendous job,I appreciate all your efforts.Thanks alot for your writings......Waiting for a new 1..
    Packers And Movers Bhopal
    http://packersmoversbhopal.in/packers-and-movers-indore

    ReplyDelete
  21. Hello my friend! I want to say that this post is awesome, great written and include almost all
    important infos.I really love this post I will visit again to read your post in a very short time and I hope you will make more posts like this.

    T H A N K S
    F O R
    S H A R I N G

    WinAVI Video Converter 11.5 Keygen
    Trend Micro Antivirus
    Movie Converter 7 Keygen
    Neuratron Audio Score Ultimate Keygen

    ReplyDelete
  22. This is one of the fastest and most effective results among the existing diet pills.For More Information Visit: http://www.dietreviewmonster.com/phen375

    ReplyDelete