Skip to content

Instantly share code, notes, and snippets.

@o11c
Created May 5, 2017 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o11c/cc3520bda444f2b26717952f02e51bf4 to your computer and use it in GitHub Desktop.
Save o11c/cc3520bda444f2b26717952f02e51bf4 to your computer and use it in GitHub Desktop.
#!/bin/sh
# For repositories cloned using `git-remote-bzr` (the official one),
# convert a git commit hash to the bzr hash *and* revno.
set -e
die()
{
printf '%s\n' "$1" >&2
exit 1
}
case "$#" in
0) what=HEAD;;
1) what="$1";;
*) die 'Error: too many arguments';;
esac
case "$what" in
-*) die "Usage: $0 [git-revision]";;
esac
cd "$(git rev-parse --git-dir)"
what="$(git rev-parse "$what")"
mark="$(cat bzr/origin/marks-git | grep ' '"$what"'$' | sed 's/^://;s/ .*$//')"
bzr_id="$(cat bzr/origin/marks-int | jq --raw-output --argjson mark "$mark" '
.marks
| to_entries
| map(select(.value == $mark))
| .[0].key
')"
echo "$bzr_id"
bzr revno bzr/origin/clone/master/.bzr -r "$bzr_id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment