I don’t know about you, but I like diff -p [1].  Having used it for years, I can read these diffs like a text, while diffs without -p often need to have the original file opened side by side, just to get enough of the context.

Loving diff -p so much, I want to see it everywhere (evil laughter). Alas, in bzr only diff command can easily use -p, just run it as bzr diff --diff-options=-p or store it as an alias in the ~/.bazaar/bazaar.conf.

Actually, for an alias there is a better, although more verbose, alternative:

Unlike simple -p it will not think that a word ending with a semicolon (like a label or, say, public: and private:) is a “C function name”.

But the problem is — only bzr diff can be tuned this way. Bzr email plugin still sends diffs without function names. And bzr gdiff does not show them. And, of course, all other bzr commands — bzr commit, for example, or bzr shelve, bzr unshelve --preview, bzr log --show-diff and others — they are still as unfriendly as before.

I was solving it on a case by case basis — added a post_commit_diffoptions configuration option to the bzr-email plugin, then a command line option to bzr gdiff. But then it occurred to me that I can attack the problem at its core!

And here it is: get this piece of the python code [2], save it as the ~/.bazaar/plugins/diffoptions/__init__.py file. Then you can add, say,

to your bazaar.conf file and it will magically change everything. All bzr commands, bzr plugins — everything that generate diffs will use these options, and you can have nice C function names on all diff chunks, no matter what plugin or core bzr command generates them.


I wonder, whether bzr folks would like to get that as a core feature. They can do it properly, without hacks that I had to resort to.

1) If you haven’t heard about it before, -p option adds C function name to every diff chunk:

2) This is the complete text of the bzr diffoptions plugin. It works for me with bzr 2.2.4, but I didn’t try it with any other bzr version.

2 thoughts on “Bzr hacks and tricks: diff -p

  1. Exactly what I needed. Can’t believe this is not built-in.

  2. Does not work if changes are outside of a function !?
    It looked really ugly to me, removed your alias immediately, sorry.

Comments are closed.