-
-
Save johnbianchi/ce97cc769107e2808ce169d680079f5c to your computer and use it in GitHub Desktop.
svn log, one line per commit
This file contains hidden or 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
#!/usr/bin/awk -f | |
# | |
# Convert the "svn log" output into a one liner format, which is easier to grep | |
# or use in scripts. Pipe "svn log" into this script | |
# | |
# forked from: https://gist.github.com/trevershick/91df1e0df8731a7d706b | |
# | |
# optional vars passed to this script: | |
# -v table="type" a pre-defined output table: csv, tab, jira/conf, align, default | |
# -v description="text" prepend a description field (usually used for repo/path/etc.) | |
# -v header=any_text print a header row | |
# these are set by the table var, not fully working as expected if you pass these in | |
# -v separator="<char>" changes the default separator char | |
# -v format="<printf_format_string>" changes the internal C style printf string | |
# | |
# examples: | |
# | |
#$ svn log -l 2 | ./svn-short-log.awk | |
#r753|user001|2017-02-20 11:32:23|JIRA-1576 Updated cleanup scripts with gradle cache locations | |
#r751|no user|2017-02-06 21:59:22|JIRA-1469: post-commit hook test | |
# | |
#$ svn log -l 2 | ./svn-short-log.awk -v table=csv | |
#r753,user001,2017-02-20 11:32:23,JIRA-1576 Updated cleanup scripts with gradle cache locations | |
#r751,no user,2017-02-06 21:59:22,JIRA-1469: post-commit hook test | |
# | |
#$ svn log -l 2 | ./svn-short-log.awk -v table=align -v description="${PWD}" -v header=true | |
#description |revision|author |date |comment | |
#/TEST/Testing |r753 |user001 |2017-02-20 11:32:23|JIRA-1576 Updated cleanup scripts with gradle cache locations | |
#/TEST/Testing |r751 |no user |2017-02-06 21:59:22|JIRA-1469: post-commit hook test | |
# | |
#--- | |
BEGIN { | |
# as i had spaces in the username field, we are refactored to use the | as the field separator | |
FS="|" | |
# table defaults | |
if( table == "csv" ){ | |
separator = ","; | |
}else if( table == "tab" || table == "lst" ){ | |
separator = "\t"; | |
}else if( separator == "" ){ | |
separator = "|"; | |
} | |
# default format | |
if(format==""){ | |
format="%s" separator "%s" separator "%s" separator "%s\n" | |
if(length(description)>0){ | |
format="%s" separator format; | |
} | |
} | |
# did they give us a header format? | |
if(header_format==""){ | |
# default header matches each line | |
header_format = format; | |
}else{ | |
# if they gave us a header_format, they must want a header | |
header=true | |
} | |
# custom formats | |
if( table == "conf" || table == "jira" ) { | |
format=separator "%s" separator "%s" separator "%s" separator "%s" separator "\n" | |
if(length(description)>0){ | |
format=separator "%s" format; | |
} | |
# jira/conf needs extra separators to bold header: | |
header_format = gensub("\\" separator, separator separator, "g", format); | |
}else if( table == "align" ) { | |
format="%-8.8s" separator "%-24.24s" separator "%-19.19s" separator "%s\n" | |
if(length(description)>0){ | |
format="%-14.14s" separator format; | |
} | |
header_format = format; | |
} | |
#print format; | |
# print a header, if header arg is given | |
if(length(header) > 0){ | |
#print header_format; | |
if(length(description)>0){ | |
printf header_format, "description", "revision", "author", "date", "comment"; | |
}else{ | |
printf header_format, "revision", "author", "date", "comment"; | |
} | |
} | |
} | |
# trim whitespace and sanatize | |
function sanitize(str) { | |
# remove blanks from beginning | |
gsub(/^[ \t]+/,"", str) | |
# remove blanks from end | |
gsub(/[ \t]+$/,"", str) | |
# remove multiple white-space | |
gsub(/[ \t][ \t]+/," ", str) | |
# remove ending periods | |
gsub(/\.[ \t]*$/,"", str) | |
# replace special chars: single and double quotes and commas | |
gsub(/[,\'\"]/,"_", str) # fix the code editor's highlighting by adding an extra double quote " here | |
return str | |
} | |
# When we get a line that starts with a revision number, put the data in variables | |
/^r[0-9]+/ { | |
# orig=$0 | |
revision=sanitize($1) | |
author=sanitize($2) | |
# get first and second date fields (space separated) | |
split($3, d, " ") | |
date=d[1] " " d[2] | |
# lines=$4 | |
} | |
# Anything that isnt a revision line, a separator line or an empty line | |
# will be part of the commit message. Concatenate these into the comment variable | |
! (/^r[0-9]+/ || /^-+$/ || /^$/) { | |
comment = comment sanitize($0) | |
} | |
# With every separator line, output what we stored before and reset the comment variable | |
# To skip the first line we also check if weve already stored a revision | |
/^-+$/ && revision && comment { | |
# print "Original:",orig; | |
if(length(description)>0){ | |
printf format, description, revision, author, date, comment; | |
}else{ | |
printf format, revision, author, date, comment; | |
} | |
comment = "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment