Skip to content

Importing the ruleutils REL9_3_STABLE Branch

Jason Petersen edited this page Sep 2, 2014 · 1 revision

pg_shard relies on static functions in PostgreSQL's ruleutils.c. In order to call these functions, we simply copy over the entire file. To make merging future changes easier, we preserve the actual history of this file in a separate branch and merge from it as necessary. The branch is named ruleutils-REL9_3_STABLE and contains only a single file, ruleutils.c.

To help troubleshoot issues related to a particular version of this file, the branch preserves PostgreSQL tags which contain changes to the file. I created this branch using these commands:

The Meat

Most of the work is done with this call:

git filter-branch -f --subdirectory-filter src/backend/utils/adt --prune-empty \
    --index-filter 'git rm --quiet --cached --ignore-unmatch $(git ls-files | grep -v ruleutils.c)' \
    --msg-filter '(git describe --always --tags --abbrev=0 $GIT_COMMIT && cat)' \
    --tag-name-filter "sed -e 's/^/ruleutils-/'"

To break down the options:

  • -f — force, to obliterate cruft from previous rewrites
  • --subdirectory-filter — only care about changes to this directory
  • --index-filter — run this command on each commit's index (removes all files but ruleutils.c)
  • --msg-filter — prepend the most recent tag name to each commit's message
  • --tag-name-filter — prepend ruleutils- to tags that already exist

Tag Preservation

Now we have a branch with just the history of that file. Tags exist as long as the file was changed during the commit pointed to by the tag (unlikely). So we stashed the tag name in the message. Now we'll rip it out and create new tags:

git log  --pretty=tformat:'%H %s' | awk '{print $1 " " rel}{rel = $2}' | tail -r | \
    uniq -f1 | grep -e 'REL9_3_\d' | awk '{print "ruleutils-" $2 " " $1}' | \
    xargs -n2 -p  git tag

Restore Messages

Now we just have to remove the tag names we stuck in the commit messages:

git filter-branch -f --msg-filter "sed '1d'" --tag-name-filter "cat"