SVN-based Code submission statistics tool implemented by shell scripts

Source: Internet
Author: User
Tags exit printf svn

This article mainly introduces the shell script implementation based on SVN Code submission Statistics tool, this article directly gives the implementation of script code, the need for friends can refer to the

Nothing recently, I wrote a code statistics gadget based on SVN in bash. You can specify a catalog of statistics, and the default recursive statistics subdirectory.

Currently, there is no capability to mask the specified directory. The code is rather rough. But get the sun out first.

?

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 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170-171 :./lines.sh [dir] # author:william # DESCRIPTION: Code submission based on SVN statistics tool # OPTIONS:---# created:06/05/2012 12:49:20 PM CST "" "" "" "" "" "" "" "" "" "" ""   set-o Nounset # Treat unset Variables as an error     # attention to the file type after the charge files_type= "*.cpp *.h *.lua"   # people who need to count, write to the person in need of statistics, separated by a space. Ah, not yet. Smart declare-r coder_list= "Coder1 coder2" declare-i coder1 declare-i coder2     declare-r usage= "USAGE: $ [dir]. Default dir is current DIR.N   # ERROR codes; Declare-r e_bad_path=1 declare-r e_invailed_argu=2 declare-r e_not_svn_dir=3     #TODO shielding some DIR hasn't written yet. TODO OT Her way get path not with/end GetPath () {#debug #echo dir_name: ${dir_name} #echo base_name: ${base_name} if [$dir _nam E = = "/"] | | [$base _name = = "/"]; Then work_path= "/" Else Work_path=${dir_name}/${base_name} Fi} &nbsp Statistic_codelines () {if [-Z ' $]; then echo ' ERROR statistic_codelines not argument ' return to fi local pwd_length=${#P WD} echo "--------------------------" echo "${pwd}" for coder in $CODER _list; Do local num=$ (echo "|" | grep ${coder} | wc-l) ((${coder} = = num)) If [$num-ne 0]; Then printf "%10s | %-7dn "${coder} $num fi done echo"--------------------------"}     # init check argument set Work_path Init_wo Rk_path () {if [$#-eq 1]; then if [$ = = '-h] ' then # is help Echo-e ' $USAGE ' elif [-D $]; then dir_name=$ (Dirna Me ${1}) base_name=$ (basename ${1}) GetPath; Else Echo-e ' an invailed argument ' echo-e use-h get help. ' Exit $E _invailed_argu fi fi}   # check Work_path chec K_work_path () {if [-Z $work _path] | | [!-d $work _path]; Then exit $E _badpath; fi}   # Enter Work_path Enter_work_path () {CD ${work_path} if [! $?]; then echo "Can not enter ${work_path}" fi }   # Check work_pat is a svn dir is_svn_dir () {(# Check ifCurrent dir is asvn dir svn info &>/dev/null exit $? ) return $? }   Action () {local dir_name=. Local base_name= local work_path= $dir _name   Init_work_path $ check_work_path E Nter_work_path #todo can ' t enter   #echo "now dir: $PWD, old dir $OLDPWD" Is_svn_dir #todo to next dir ret=$? If [$ret-ne 0] then echo-e ' current dir ' ${work_path} ' not svn dir. ' Exit $E _not_svn_dir fi   # get source file s local files=$ (LS ${files_type} 2>/dev/null)   If [-N "$files"]; Then local namelist=$ (Echo-n ${files} | xargs-n 1 svn blame | awk ' {print $} ') #svn blame $files #| grep $ | Wc-l statistic_codelines "$namelist" fi   local sub_dirs=$ (find-maxdepth 1-type d-name "[^.] * "2>/dev/null"   if [-N "$sub _dirs"]; Then for dir in $sub _dirs; Do action ' $dir ' done fi   CD. }   Total () {echo--------totoal----------"echo" NAME | Lines "echo"--------------------------"for coder in $CODER _list; do if [${!coder}-ne 0]; Then printf "%10s | %-7dn "${coder} ${!coder} fi done echo"--------------------------"}   # main echo"-----start counting, please be patient ...:) "Action $   Exit 0
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.