Friday, June 22, 2018

Finding changes between branches with git.

I'm often looking for a way to find the particular changes between two branches in git. I know I can use
git log --pickaxe.
But it can be tricky to get concise output from this.

I've added an alias to my
file to get me the info I want at a glance.

    findchanges = "!f() { revision=$1; shift ;                           ⏎
… for x in $(git diff $revision --name-status | cut -f 2) ; do           ⏎ 
…    git diff $revision -U0 -- $x | grep '^[+-] ' | sed 's#^#'$x': #' ;  ⏎
… done | grep \"$@\" ;                                                   ⏎
… } ; f"

(Note: This should all be one line - I've had to break it for readability)

This lets me do the following

> git findchanges my_branch -i todo
fileA.c: +    // TODO: We really should fix this
fileB.c: -    // TODO: Make sure we tweak the frobnitz later

Tuesday, May 6, 2014

Profiling IO in java on linux

This is more of a note to myself, but others may find it useful.

When you want to see what bottlenecks are being hit by some java process that you're running you can do the following:

  1. Repeatedly obtain the backtrace using jstack PID. If you're repeatedly seeing something blocking in a read/write related call then you're IO bound
  2. Check what files are open by the process using lsof PID. Its likely that one of these will look suspect
  3. Watch reads to those open files using strace -f -p PID -e trace=none -e write=FD1,FD2,... -e read=FD1,FD2,...

Friday, March 7, 2014

Cleaning up whitespace additions in git

I wrote a previous post on cleaning up end of line whitespace using git... But I've now run into a similar issue, the IDE used by several of the devlopers on my project
likes to change surrounding whitespace indentation of lines. This means if you change just one line, the indentation changes will swamp the real changes, making the diff unhappy to look at.

You can view a diff without showing whitespace changes in git using --ignore-space-change or --ignore--all-space. However unforunately the command

git rebase -f master --ignore-space-change

doesn't do what one might hope.

However all is not lost. You can get the same kind of behaviour by plumbing together git format-patch and git am.

git branch fixed 40caad7
git checkout fixed
git format-patch --stdout --ignore-all-space fixed..original | git am --ignore-whitespace

This takes the the changes from 40caad7 to original and applies them to the new fixed branch, but removes/fixes whitespace changes.

however this is not nice to use - so you can wrap it up into a little git alias like this: (newlines inserted for clarity - you'll need to remove them if you use it)

 cleanwhite = "!f() { 
⏎  orig=$(git rev-parse HEAD) ; 
⏎  mergebase=$(git merge-base HEAD $1) ; 
⏎  git reset --hard $1 ; 
⏎  git format-patch --stdout --ignore-all-space $mergebase..$orig | git am --ignore-whitespace ; 
⏎ } ; f"

Now cleaning up your current base is as simple as

$ git cleanwhite master

Which will clean up all commits whitespace from your current commit back to where you diverged from master.

Saturday, October 20, 2012

Finding changes in ugly XML with git and xmllint

This is probably not going to be useful to very many people, but it helped me track down a small bug, and I'm preserving it mostly incase I need something similar later.

So the key issue here is that we have some XML that is stored in git. Unfortunately this generated XML is not nicely formatted. Thus changes in git don't show nicely using git log or git diff.

My technique was this:

  1. Find the commits that changed the file of interest.

    git log --oneline afile.xml | awk '{print $1}'
  2. Get the file at that revision.

    git show $REVISION:afile.xml
  3. Get the file at the previous revision

    git show $REVISION~1:afile.xml
  4. Pass these through xmllint --format to clean them up

  5. diff the cleaned up versions

This sounds pretty complex, but it can be wrapped up into a concise piece of bash script.
Now its not going to work across merges etc, but the general technique can be handy.

I suspect a similar thing may have been obtainable by setting a custom diff tool in git but I couldn't see an easy way to get exactly what I wanted.

Wednesday, October 3, 2012

Partial template specialization for functions in C++

Partial template specialization for functions in C++

The short of it is you can't do it. But you can do something that looks just like it.

What is template specialization?

For functions template specialization looks like this:

So the first template tells us what to do in general and the specialization tells us what to do in particular cases.

What is partial template specialization?

Its just like template specialization, but you're not specifying all the template parameters. So for the example above we might like to add a specialization that prints "Lucky 7" when the first template argument is 7. If we could write it, it would look like this (but its not valid C++)

However this doesn't work - it's not valid C++.

What is the issue?

C++ does not allow function partial specialization.

How do we get around it?

C++ does allow partial template specialization for classes (and structs). So our solution is just to defer to a templated helper class with static functions:

Its verbose, but it works.

NOTE: in this case we're working with `int` parameters that would be better done with a normal function containing a couple of `if` statements - however all this works for type templates too.

Thursday, April 19, 2012

Faking watch on OS X

Sometimes watching something change over time in your terminal is kinda helpful. Linux has a great utility for this called "watch". OS X doesn't some with this. Of course you can build it yourself if you want .. but that can mean a chunk of pain too... luckily bash comes with what you need. "while" and some ANSII escape sequences are enough to get you going.

Here was my first try:

The first problem with this for me was that in iterm2 clear just keeps adding to your terminal scrollback in some weird way. Luckily replacing this with some ANSII control sequences fixes that up nicely.

Now it doesn't add to the scrollback but it does blink every 4 second. I fixed this by storing the current and previous results in temp files and only clearing if they've changed.

Saturday, March 24, 2012

Farewell Tim

It has been just over two weeks since my little brother Tim was killed. He was hit by a drunk driver while cycling - training for the Ride For Youth, a charity ride raising money for young people at risk of self harm or suicide.

The ride for youth requires serious dedication from those participating, riding 640km over 5 days. They are expected to train with the team at least 3 days a week for 6 months. In the week before his death Tim rode over 400km. My Dad has been doing the ride for several years, and this year was going to be his last and Tim's first. Tim was athletic all his life, but with this training he was fitter than he'd ever been.

Tim had an amazing group of friends. He touched so many lives. We've had messages of sympathy and support from all over the world. We estimate somewhere between 700 and 1000 people attended his funeral. Through his studies and work as Chemical Engineer he lived all over the world: Perth, Brisbane, Dubai, Wales, Switzerland and more. Everywhere he went he made great lifelong friends. To Tim everyone was a potential friend.

Tim was also intelligent. He had left his work to pursue a Masters degree in Chemical Engineering, and was considering upgrading that to a Ph.D. Amazingly Tim was using many of the tools I'd studied in my Ph.D. and post-doc. In the last year we'd had conversations about such esoteric topics as "Convergence and Stability of Finite Element Methods."

Finally, Tim was an amazing uncle to my daughter Kira, and my son Grant. Even after a training ride of 140km Tim would still have the energy to run around the table with Kira playing chasey. He'd leave the social events early to take Kira to the beach. Kira is going to miss him terribly, and I'm so sad that Grant will never get to know him. I was so looking forward to Tim teaching them both things like surfing and basket ball. (Both of which I'm useless at.)

If you want to support Tim's cause, don't send us flowers, donate here:

Some further information about Tim and the accident can be found here:

I don't know what else to say except

Goodbye Tim,
We're really going to miss you.