FindingOldBranches » History » Version 4

Chris Cannam, 2012-02-02 11:44 AM

1 1 Chris Cannam
h1. Finding Old Branches
2 1 Chris Cannam
3 4 Chris Cannam
List bug or feature branches that have not been modified in the past 90 days and that have been merged into other branches since they were last modified:
4 1 Chris Cannam
5 1 Chris Cannam
<pre>
6 1 Chris Cannam
$ hg -q branches | \
7 2 Chris Cannam
    egrep '(bug_|feature_)' | \
8 1 Chris Cannam
    while read b; do \
9 4 Chris Cannam
      oldmerges=`hg log --template '{rev}\n' -r "children(last(branch('"$b"')) and not date('-90'))"`; \
10 3 Chris Cannam
      [ -n "$oldmerges" ] && echo $b ; \
11 1 Chris Cannam
    done
12 1 Chris Cannam
</pre>
13 4 Chris Cannam
14 4 Chris Cannam
List branches as above, then close each branch with a commit dated 24 hours after the branch was last modified:
15 4 Chris Cannam
16 4 Chris Cannam
<pre>
17 4 Chris Cannam
$ hg -q branches | \
18 4 Chris Cannam
    egrep '(bug_|feature_)' | \
19 4 Chris Cannam
    while read b; do \
20 4 Chris Cannam
      oldmerges=`hg log --template '{rev}\n' -r "children(last(branch('"$b"')) and not date('-90'))"`; \
21 4 Chris Cannam
      [ -n "$oldmerges" ] && echo $b ; \
22 4 Chris Cannam
    done | \
23 4 Chris Cannam
    while read b; do \
24 4 Chris Cannam
      d=`hg log --template '{date|hgdate}' -r "last(branch('"$b"'))"`; \
25 4 Chris Cannam
      closeat="$((${d%% *} + 86400)) ${d##* }"; \
26 4 Chris Cannam
      hg update "$b" && hg commit -m "Closing obsolete branch $b" -d "$closeat" --close-branch; \
27 4 Chris Cannam
    done
28 4 Chris Cannam
</pre>
29 4 Chris Cannam
30 4 Chris Cannam
Needless to say, do this in a spare clone and check the result carefully before pushing!