Tag: version control

  • The Muppets Meet Murderbot

    This morning, Devon tweeted a great git tip that shows how to create a git alias that produces more readable git logs. I decided I wanted to set this up.

    At work, we use a central Subversion repository, but a number of us use git-svn because we prefer git’s various local branch tools for development. I decided that it would be useful to extend this alias to also include the Subversion revision number if the commit has one. Unfortunately, this information (in the form of a Subversion URL) is stored in the commit body by git-svn, which may include other notes added by a developer. git-log exposes this text via the %b format specifier, but since we want to do some post-processing to extract just the revision number, we’ll need to set up a shell alias.

    Here’s the final version I’ve added to my ~/.aliases:

    alias glog='git log --graph --pretty=format:'"'"'%Cred%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%Cred%b%Creset'"'"' | perl -e '"'"'$log = do { local $/; <> }; $log =~ s/(>\e\[m\e\[31m)([^\n]*\n\| )*git-svn-id: svn\+ssh:\/\/[^\s\@]*\@(\d+) [0-9A-F-]+\n(\|| ) (\e\[m)/$1 r$3$5/gm; print "$log\n";'"'"' | less -RS'

    First you’ll note the weird quote escaping – we want the alias to be single-quoted (no expansion), but we want the arguments to the commands to also be single-quoted. That’s where the '"'"' trick comes in; see this explanation on StackOverflow. The format string is almost identical to Filipe’s solution, except for the addition of the body. The nasty Perl regular expression pulls out the revision number from that while also preserving the ANSI color escape sequences I inserted into the format string. Finally, we pass everything back to less for paging; -R makes sure it interprets the colors correctly, while -S disables line-wrapping.

    One unfortunate side effect of adding the post-processing is that you can’t pass the -p option to git log anymore, because Perl needs to read the whole log in for multiline matching (in case a developer had literal newlines in their commit body), and the diffs are large and could get caught in the regex filter.

    Hopefully you find this useful!

  • Fox Ferocity

    Pike playing with a toy almost as big as he is.

  • Groomed Pike

    Tiny freshly groomed Yorkie sits on a teal couch wearing a monstera bow tie

    I love this little gentleman.

  • The Kale Wanter

    A small black and brown Yorkie stands on a cream rug in front of a brown cupboard begging for the bunch of lacinato kale in hand in the foreground.
  • Puck Mouse

    An elegant weapon for a more civilized age.

    A blue and white USB puck mouse sitting on beige carpet

  • Seattle After Dark

    Seattle skyline at night with Space Needle in center, with Christmas lights on top

    We were wandering the neighborhood to see light displays and ended up at Kerry Park’s iconic view.