Created
February 18, 2012 00:15
-
-
Save mrigor/1856440 to your computer and use it in GitHub Desktop.
"git svnin" and "git svnout" commands for git-svn on OS X (requires gnu sed and awk)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# run git log in bunches of 25 until we find a svn id. | |
LIMIT=25 | |
SVN_REVISION="" | |
LAST_REVISION="HEAD" | |
PAGER=`git config core.pager` | |
if [ -z "$PAGER" ] ; then | |
PAGER="less" | |
fi | |
function _svnin(){ | |
while [ -z "$SVN_REVISION" -a -n "$LAST_REVISION" ] ; do | |
LOG=`git log -$LIMIT $LAST_REVISION 2> /dev/null | awk --re-interval ' | |
BEGIN { | |
FS = "\n" | |
svn_id_found = 0 | |
} | |
/commit [a-f0-9]{40}/ { | |
print $1 | |
} | |
/^[[:space:]]+git-svn-id:/ { | |
if (svn_id_found == 0){ | |
svn_id_found = 1 | |
print $1 | |
} | |
} | |
'` | |
if [ -n "$LOG" ] ; then | |
LAST_REVISION=`echo $LOG | gsed -r 's|.*commit ([a-f0-9]{40}).*|\1^|'` | |
SVN_REVISION=`echo $LOG | gsed -r 's|.*git-svn-id: .*@([0-9]+).*|\1|'` | |
LOG=`echo $LOG | gsed -r 's|\n| |g'` | |
if [ "$SVN_REVISION" == "$LOG" ] ; then | |
SVN_REVISION="" | |
fi | |
else | |
LAST_REVISION="" | |
fi | |
done | |
if [ -n "$SVN_REVISION" ] ; then | |
# run git svn log in bunches of 25 and stop when we stop finding new | |
# entries with revisions > the svn id we found above. | |
LIMIT=25 | |
FIRST=$((SVN_REVISION + 1)) | |
LAST=$FIRST | |
LAST_REVISION=$FIRST | |
while [ -n "$LAST_REVISION" ] ; do | |
MAX_REV=$(($LAST_REVISION + $LIMIT)) | |
LOG=`git svn log --limit=$(($LIMIT + 1)) --revision=$MAX_REV:$LAST_REVISION` | |
NEXT_REV=`echo $LOG | gsed -r 's|-+\sr([0-9]+).*|\1|'` | |
if [[ "$NEXT_REV" =~ ^[0-9]$ && "$NEXT_REV" != "$LAST_REVISION" ]] ; then | |
LAST_REVISION=$NEXT_REV | |
LAST=$NEXT_REV | |
else | |
LAST_REVISION="" | |
fi | |
done | |
git svn log $* --revision=$LAST:$FIRST | cat - | |
fi | |
} | |
_svnin | $PAGER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# run git log in bunches of 25 and stop when we find commits that exist with | |
# a svn id (the commit exists in svn). | |
LIMIT=25 | |
LAST_REVISION="HEAD" | |
PAGER=`git config core.pager` | |
if [ -z "$PAGER" ] ; then | |
PAGER="less" | |
fi | |
function _svnout(){ | |
while [ -n "$LAST_REVISION" ] ; do | |
LOG=`git log -$LIMIT --color $LAST_REVISION | awk --re-interval ' | |
BEGIN { | |
FS = "\n" | |
entry = "" | |
recording = 0 | |
} | |
END { | |
if (entry != ""){ | |
print entry | |
} | |
} | |
/commit [a-f0-9]{40}/ { | |
if (entry != ""){ | |
print entry | |
} | |
entry = "" | |
recording = 1 | |
} | |
/^[[:space:]]+git-svn-id:/ { | |
entry = "" | |
recording = 0 | |
} | |
/.*/ { | |
if (recording == 1){ | |
entry = entry "\\\n" $1 | |
} | |
} | |
'` | |
if [ -n "$LOG" ] ; then | |
echo -e $LOG | |
LAST_REVISION=`echo $LOG | sed -r 's|.*commit ([a-f0-9]{40}).*|\1^|'` | |
else | |
LAST_REVISION="" | |
fi | |
done | |
} | |
_svnout | $PAGER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment