Add vco and source-code-stats scripts
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 5 Oct 2014 21:06:27 +0000 (17:06 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 5 Oct 2014 21:06:27 +0000 (17:06 -0400)
scripts/Makefile.am
scripts/source-code-stats [new file with mode: 0755]
scripts/vco [new file with mode: 0755]
scripts/vco-sub [new file with mode: 0755]

index 6feb3fb..d113c7d 100644 (file)
@@ -19,13 +19,15 @@ dist_bin_SCRIPTS = \
     setdate \
     strip-debug-symbols \
     tildes-clean \
-    vb vd vl vs vs-sub \
+    vb vd vl vs vs-sub vco vco-sub \
     hg-format-patch hg-update-subrepos \
     git-hg-sub-import git-hg-sub-update \
+    source-code-stats \
     flac2ogg flac2mp3 \
     hv-scan \
     tape-backup tape-backup-mult tape-list tape-restore
 
+
 # we want these in the dist tarball
 # (for scripts that we don't want to install but want to distribute)
 EXTRA_DIST = \
diff --git a/scripts/source-code-stats b/scripts/source-code-stats
new file mode 100755 (executable)
index 0000000..6f8ea86
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Comptage des lignes de code.
+
+# find $1 -print0 | xargs -0 touch
+# That terminates each filename with \000 (character 0) and instructs xargs to expect the filenames terminated by \000
+#
+#   -print0
+#          True; print the full file name on the standard output,  followed
+#          by  a  null  character  (instead  of  the newline character that
+#          -print uses).  This allows file names that contain  newlines  or
+#          other  types  of white space to be correctly interpreted by pro‐
+#          grams that process the find output.  This option corresponds  to
+#          the -0 option of xargs.
+
+echo -n "Lignes de code: "
+find . \
+    \( \
+    -name '*.c' -o \
+    -name '*.C' -o \
+    -name '*.h' -o \
+    -name '*.H' -o \
+    -name '*.cxgate' \
+    \) \
+    -print0 | xargs -0 cat | wc -l
+
+echo -n "Fichiers:       "
+find . \
+    \( \
+    -name '*.c' -o \
+    -name '*.C' -o \
+    -name '*.h' -o \
+    -name '*.H' -o \
+    -name '*.cxgate' \
+    \) \
+    -print | wc -l
diff --git a/scripts/vco b/scripts/vco
new file mode 100755 (executable)
index 0000000..31418a7
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+VCS_SUPPORTED="GIT, Subversion or Mercurial"
+
+print_usage()
+{
+    echo "$(basename $0) -- checkout for version control (${VCS_SUPPORTED})."
+    echo "Usage: $(basename $0) [OPTIONS...]"
+}
+
+if [ "x${1}" = "x--help" ]; then
+    print_usage
+    exit 1
+fi
+
+if git diff 1> /dev/null 2>&1; then
+    git checkout "$@"
+elif svn diff 1> /dev/null 2>&1; then
+    svn co "$@"
+elif hg status 1> /dev/null 2>&1; then
+    hg update "$@"
+else
+    echo "Not a ${VCS_SUPPORTED} repository"
+    exit 1
+fi
diff --git a/scripts/vco-sub b/scripts/vco-sub
new file mode 100755 (executable)
index 0000000..374faa7
--- /dev/null
@@ -0,0 +1,116 @@
+#!/bin/bash
+set -o errexit
+
+PROG_NAME=$(basename $0)
+
+# Version control checkout command for all subrepositories.
+# For use with git-remote-hg:
+#   http://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/
+
+# Uncomment to have verbose debug output
+debug=1
+
+print_usage()
+{
+    echo "$(basename $0) -- Version control subrepository checkout"
+    echo "Usage: $(basename $0) [OPTIONS...]"
+    echo "Options:"
+    echo "  -h   display this help and exit"
+    echo "  -m   display only subrepositories with local modifications"
+}
+
+display_subrepo_name()
+{
+    COLOR_BLUE='\033[1;34m'
+    COLOR_NORMAL='\033[0m'
+
+    echo -en "${COLOR_BLUE}"
+    echo "${dest}"
+    echo -en "${COLOR_NORMAL}"
+}
+
+if [ "x${1}" = "x--help" ]; then
+    print_usage
+    exit 1
+fi
+
+if [ ${#} -eq 0 ]; then
+    echo "${PROG_NAME}: Missing branch name."
+    echo "Try \`${PROG_NAME} --help' for more information."
+    exit 1
+elif [ ${#} -gt 1 ]; then
+    echo "${PROG_NAME}: Too many arguments."
+    echo "Try \`${PROG_NAME} --help' for more information."
+    exit 1
+fi
+
+branch=${1}
+
+if [ ! -f .hgsub ]; then
+    echo "No Mercurial subrepositories found"
+    exit 1
+fi
+
+checkout_branch()
+{
+    if [ ${#} -eq 0 ]; then
+        echo "${PROG_NAME}: Missing branch name."
+        exit 1
+    fi
+
+    local branch=${1}
+
+    if vb | egrep -q "^\s+${branch}$" ; then
+                # Branch found
+        vco ${branch} 1> /dev/null 2>&1
+        if [ -n "${debug}" ]; then
+            echo "Changing branch"
+            echo # Blank line
+        fi
+    elif vb | egrep -q "^\**\s+${branch}$" ; then
+        if [ -n "${debug}" ]; then
+            echo "Already on branch"
+            echo # Blank line
+        fi
+    else
+        if [ -n "${debug}" ]; then
+            echo "Branch not found"
+            echo # Blank line
+        fi
+    fi
+}
+
+# Switch branch on main assembly
+if [ -n "${debug}" ]; then
+    dest="Top assembly"
+    display_subrepo_name
+fi
+checkout_branch ${branch}
+
+# Read lines from .hgsub
+while read sub; do
+    # Remove CR (DOS)
+    sub="${sub//$'\r'/}"
+
+    if [ "${sub}" != "" ]; then
+        # Get subrepository local alias or label
+        dest="${sub// =*}"
+
+        # Get project ID (example: S0289)
+        id=$(echo ${sub} | sed "s/.*\(S[0-9][0-9][0-9][0-9]\).*/\1/")
+
+        if [ -n "${debug}" ]; then
+            display_subrepo_name
+        fi
+
+        if [ -d "${dest}" ]; then
+            pushd "${dest}" 1> /dev/null
+            checkout_branch ${branch}
+            popd 1> /dev/null
+        else
+            display_subrepo_name
+            echo "Error: missing local subrepository"
+            echo # Blank line
+        fi
+    fi
+done < .hgsub