truncate only hashes, other ids need to remain intact
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 2 Jul 2010 10:44:22 +0000 (12:44 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 2 Jul 2010 10:44:22 +0000 (12:44 +0200)
scripts/post-receive-email-with-diffs

index 52cbced..66a7bd2 100755 (executable)
@@ -175,6 +175,14 @@ generate_email()
     generate_email_footer
 }
 
+# generate a pattern for testing if a string is a hash
+hpat="";__=1; while [ $__ -le 40 ] ; do hpat=${hpat}'[0-9a-f]';__=$(($__+1)); done
+function is_hash () {
+    local hash
+    hash=$1; shift
+    case $hash in $hpat) return 0;; *) return 1;; esac
+}
+
 generate_email_header()
 {
     # --- Email (all stdout will be the email)
@@ -186,7 +194,7 @@ generate_email_header()
        details="$refname_type, $short_refname,"
     fi
     local shortrev
-    shortrev=$(echo $describe | cut -b1-8)
+    is_hash $describe && shortrev="$(cut -b1-8 <<< $describe).." || shortrev=$describe
     # Generate header
     cat <<-EOF
        To: $recipients