-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathhesort
executable file
·25 lines (25 loc) · 1.1 KB
/
hesort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# ~/bin/hesort histeditfile
# reorder histedit commit plan by commit message,
# -- favoring oldest commit message
# -- collapsing commits for the same message
#
# Pipeline explanation:
# [cat] input is HG histedit series
# [egrep] strip comments explaining how to use histedit
# [perl] prefix the commit message and commit number to the plan
# [sort] this sorts similar commits next to eachother
# -- newer ones should generally be after older ones
# (technically if you have 99 and 100 it will mess up --
# this hasn't been a problem)
# [perl] 1. remove the prefixes inserted by the previous perl
# (technically this could mess up if the commit message has
# an underscore (`_`), stuff, `cherrypick` -- this hasn't been a problem)
# 2. if the previous correction was the same as the current,
# replace pick with roll
cat $1 |\
egrep -v '^#'|\
perl -pne 's/(\S+) (\S+) (\S+) (.*)/$4_$3 $1 $2 $3 $4/' |\
sort |\
perl -pne 's/(.*)_(?:.*? )pick/pick/; $q=$1; s/pick/roll/ if $q eq $p; $p = $q;' > $1.0;
mv $1.0 $1