Archive for the ‘wishful thinking’ Category

Mercurial Hook to ensure issue references in Trac/Redmine

Saturday, June 4th, 2011

As much as I love the version control integration of the bug trackers I use (Redmine and Trac) I find myself forgetting to include the issue reference more often than I’d like to admit.

Add to this the merry dance you have to go through to ammend commit messages in Mercurial and things get even worse. (Oh how I’d love for hg to implement something similar to git’s $ git commit –amend )

Hence, a Pre-transaction-commit hook for hg that will ask me if I’m sure I want to commit without an issue number. If want to commit anyway, it’s just two extra keystrokes, and saves a whole lot of rollback/apply nonsense.

#!/usr/bin/env python
import os
import re
import subprocess
import sys
 
cmd = subprocess.Popen(['hg', 'log', '-vr', os.environ['HG_NODE']],
                       stdout=subprocess.PIPE).communicate()[0]
msg = cmd.split('description:')[1]
issue_regexes = [
    # Trac
    r'#\d+',
    # Redmine
    r'fixes #\d+',
    r'refs #\d+',
    ]
if not filter(lambda x: re.search(x, msg), issue_regexes):
    print "No issue ref or fix... message is:"
    print msg
    sys.stdout.write("Continue? [y/n] ")
    resp = raw_input().lower()
    if resp == 'n':
        sys.exit(9)

Then add the following to your project’s .hg/hgrc:

[hooks]
pretxncommit = path/to/your/pretxncommit.py

Saving you endless embarrassment:

davidmiller@pascal:~/src/buggy_repo$ hg commit -m "A context-less void"
No issue ref or fix... message is:
 
A context-less void
 
 
 
Continue? [y/n] n
transaction abort!
rollback completed
abort: pretxncommit hook exited with status 9

Love regards etc

Mass buffer revert in emacs

Saturday, May 21st, 2011

One of the problems with doing branchy development in Emacs is that when you have lots of files open and then switch branches, the bufer contents stay on the previous branch. Thankfully Emacs will warn you that the file’s contents have changed before you edit/save the file, but calling M-x revert-buffer on lots of open files gets old very fast.

This being Emacs though, the natural solution to any irritation is to program your way out of it. M-x regexp-revert let’s you enter a regexp, and then reverts any buffer with a file location matching that regexp to the file’s current state on disk.

(defun regexp-revert (regexp)
  "Revert all buffers whose path matches regexp"
  (interactive "sPath Regexp: ")
  (dolist (buffer (buffer-list))
    (if (string-match-p regexp (or (buffer-file-name buffer) ""))
        (progn
          (set-buffer buffer)
          (revert-buffer nil t)
          (message "Reverting %s" (buffer-file-name buffer))))))

Love regards etc

Security and freedoms

Sunday, October 31st, 2010

We must plan for freedom, and not only for security, if for no other reason than that only freedom can make security secure.

Karl Popper – The Open Society and its Enemies

Popper: Rulers

Sunday, June 13th, 2010

It appears to me madness to base all our political efforts upon the faint hope that we shall be successful in obtaining excellent, or even competent rulers.

The Open Society & It’s Enemies – Popper