Skip to content

Instantly share code, notes, and snippets.

@drinkcat
Last active December 22, 2015 13:58
Show Gist options
  • Select an option

  • Save drinkcat/6482317 to your computer and use it in GitHub Desktop.

Select an option

Save drinkcat/6482317 to your computer and use it in GitHub Desktop.
awk version of branch matching
ADHD_HEAD="`awk '
BEGIN {
crosver = "'"$CROS_VER"'"
crosvers[0] = crosver
while (sub(/\.[^.]*$/, "", crosver))
crosvers[length(crosvers)] = crosver
bestmatch = length(crosvers)-1
}
sub(/refs\/heads\//, "", $2) {
if ($2 ~ "^release-R[0-9]*-" crosvers[length(crosvers)-1] "([^0-9].*)*$") {
print $2
exit
}
for (i = 0; i <= bestmatch; i++) {
if ($2 ~ "^stabilize-" crosvers[i] "([^0-9].*)*$") {
out = ((i < bestmatch) ? "" : out) $2 "\n"
bestmatch = i
}
}
}
END { printf "%s", out; }
' adhd.refs | sort -V | tail -n 1`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment