Gentoo Archives: gentoo-dev

From: Steve Long <slong@××××××××××××××××××.uk>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: The Plethora of Patches
Date: Fri, 15 Aug 2008 09:12:54
Message-Id: g83h9b$9bf$1@ger.gmane.org
In Reply to: Re: [gentoo-dev] The Plethora of Patches by Andrew D Kirch
1 Andrew D Kirch wrote:
2
3 > Here's the script that I used to generate this.
4 Just some bash hints. In a nutshell: please don't use ls in scripts.
5 > I have not manually
6 > reviewed all of thousands of patches to determine the unique situation
7 > of each patch, however I would like a suggestion on how to demonstrate
8 > _real_ statistics short of auditing each and every patch in portage
9 > which I personally don't have time to do.
10 I think it's a great idea, and the other reply from robbat gives you a great
11 spec to start from in terms of classification.
12
13 > for I in `ls`; do
14 for f in *; do
15
16 Globs have a lot to recommend them: see http://wooledge.org:8000/glob
17 > PATCH=`ls -R ${I} | grep patch | wc -l`
18 > DIFF=`ls -R ${I} | grep diff | wc -l`
19 > COUNT=$(( ${PATCH} + ${DIFF} ))
20 while read -rd ''; do let count++
21 done < <(find "$dir" \( -name '*.diff' -o -name '*.patch' \) -print0)
22
23 ..in the general case, where you actually need a recursive descend. (We
24 don't here.)
25 > if ! [ ${COUNT} == 0 ]
26 > then
27 > echo $I $COUNT
28 > fi
29 ((count)) && { echo "$dir : $count" }
30
31 See http://bash-hackers.org/wiki/doku.php?id=syntax:words for an explanation
32 of why the quotes make a difference.
33
34 Putting it together you end up with this:
35
36 #!/bin/bash
37 # ./countPatchFiles > patchCount
38 # sed -nr '/^Category: (.*): (.*)/s//\1\2/p' patchCount |sort -n -k 2
39 PORTDIR=$(portageq envvar PORTDIR)
40 declare -i count tot=0 cTot
41 shopt -s nullglob
42 for d in "$PORTDIR"/*/; do
43 c=${d#"$PORTDIR/"}; c=${c%/}
44 [[ $c = *-* ]] || continue
45 cTot=0
46 echo "$c" >&2
47 for p in "$d"*/; do
48 files=("$p"files/*.patch "$p"files/*.diff)
49 count=${#files[@]}
50 ((count)) || continue
51 p=${p#"$d"}; echo "$c/${p%/} : $count"
52 ((tot+=count,cTot+=count))
53 done
54 echo "Category: $c : $cTot"
55 done
56 echo "Total: $tot"
57
58 -- HTH,
59 igli.
60 (The files are in that array, if their names should be needed.)