For this lab we were asked to refactor our code. In other words, clean it up and make it more maintainable in the future. We learned how to use git rebase , git commit --ammend , and git merge to effectively rewrite history. Much cleaner then tearing down statues…
Part 1 – Refactoring
in this first part we needed to make some improvements to the readability and maintainability of the code. After each fix, make a commit, for at lease 3 in total.
The first thing I noticed was that when I was adding the –json feature I declared a class member array called self.json that I had intended to use to store the json objects. What I had done instead was make a local array in each printJSON function and use that to display the output. I got ride of all the local arrays and instead put that original array to work. I believe this helps improve the readability of the functions.
Second commit was to re-order the class functions to put all the print functions at he bottom instead of in the middle. I felt this was necessary because it organizes the class much better. I also added some documentation and got rid of the few single letter variables I had to better assist a would be contributor.
Third refactoring commit was fixing the –ignore option that was added last week to work a little better. I hadn’t noticed that it didn’t block all matching urls. For example if google. was in the ignore file, I wanted it to ignore both google.com and google.ca. There was also a slight issue with the error handling of it. So after fixing the matching issue and adding some proper error handling I made the third commit.

Part 2 – If I could turn back time
Next step was to rebase it all into a single commit to make the history easier to follow. My first attempt was a failure

Turns out I had a dirty staging area back in master. So, after restoring master to a clean state I was able to run the rebase. I picked one commit to squash the other two into. After the rebase I then did a commit --amend which ammends the last commit made. Since the last commit made was the rebasing commit, we are able to clean up the commit message to be better understood in the future. I was then able to do a fast-forward merge into my master as one commit with a significant commit message.
