From: Mike Frysinger Date: Mon, 19 Sep 2011 22:34:42 +0000 (-0400) Subject: git helpers X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=6c162084bc50a80aa7561bc77b642ad441a9304a;p=home.git git helpers --- diff --git a/.bin/git-rewrite-authors b/.bin/git-rewrite-authors new file mode 100755 index 0000000..ce93381 --- /dev/null +++ b/.bin/git-rewrite-authors @@ -0,0 +1,23 @@ +#!/bin/bash + +tmp=$(mktemp) +cat << \EOF > ${tmp} +decode() { + awk -vid="$1" -vtype="$2" '$1 == id { + print "export GIT_"type"_NAME='\''" $3 " " $4 "'\'';" + print "export GIT_"type"_EMAIL='\''" $5 "'\'';" + }' ${author_file} +} +EOF + +for x in cvs-authors authors ; do + export author_file=${PWD}/.git/$x + [ -e ${author_file} ] && break +done +git filter-branch \ + --env-filter ". ${tmp};"' \ + eval `decode "${GIT_AUTHOR_NAME}" AUTHOR`; \ + eval `decode "${GIT_COMMITTER_NAME}" COMMITTER`; \ +' "$@" + +rm -f $tmp diff --git a/.bin/git-svn b/.bin/git-svn new file mode 100755 index 0000000..7843b16 --- /dev/null +++ b/.bin/git-svn @@ -0,0 +1,77 @@ +#!/bin/sh + +gdir=".git" +if [ ! -d ${gdir} ] ; then + echo "Run this is in the root of the git tree" + exit 1 +fi + +revmap() { + find ${gdir}/svn/$1/ '(' -name '.rev_map.*' -a '!' -name '*.bak' ')' -print +} + +decode() { + xxd -c24 < $1 +} +encode() { + xxd -c24 -r +} + +get_branch() { + branch=${1:-trunk} + if [ ! -d ${gdir}/svn/${branch} ] ; then + echo "Branch ${branch} not in ${gdir}/svn/" + exit 1 + fi + + map=$(revmap ${branch}) + + cur_rev=$(printf '%i' 0x$(decode $map | tail -n1 | awk '{print $3}')) +} + +show() { + get_branch "$@" + echo "${branch}: at rev ${cur_rev}" + exit 0 +} + +reset() { + get_branch "$@" + new_rev=$2 + if [ -z "$new_rev" ] || [ "$new_rev" -gt "$cur_rev" ] ; then + echo "${branch}: invalid rev '$new_rev' (at $cur_rev)" + exit 1 + fi + + printf "really reset $branch to $new_rev ? [y/N] " + read ans + case ${ans} in + [yY]) ;; + *) exit 1;; + esac + + hex0=$(printf '%04x' $(( new_rev % 0x10000 )) ) + hex1=$(printf '%04x' $(( new_rev / 0x10000 )) ) + cp $map $map.bak + decode $map.bak \ + | sed -n "1,/^[^:]*: $hex1 $hex0/p" \ + | encode \ + > $map + + show ${branch} + echo "don't forget to reset manually ref/remotes/${branch}" +} + +usage() { + echo "Unknown op '$op'" + exit 1 +} + +branch= +op=$1 +shift +case $op in + -s) show "$@";; + -r) reset "$@";; + *) usage;; +esac