Allow depth limiting git clones

Depending on how you are using devstack you probably don't need the
entire history of a project so we should allow people to specify a clone
depth to speed up the devstack process.

Change-Id: I804a5abcc80f6a81e915c0bb4dceae72486441a7
Blueprint: git-depth
diff --git a/functions-common b/functions-common
index e6f425f..bf25c25 100644
--- a/functions-common
+++ b/functions-common
@@ -19,6 +19,7 @@
 #
 # The following variables are assumed to be defined by certain functions:
 #
+# - ``GIT_DEPTH``
 # - ``ENABLED_SERVICES``
 # - ``ERROR_ON_CLONE``
 # - ``FILES``
@@ -562,16 +563,22 @@
 # Set global ``RECLONE=yes`` to simulate a clone when dest-dir exists
 # Set global ``ERROR_ON_CLONE=True`` to abort execution with an error if the git repo
 # does not exist (default is False, meaning the repo will be cloned).
-# Uses globals ``ERROR_ON_CLONE``, ``OFFLINE``, ``RECLONE``
+# Set global ``GIT_DEPTH=<number>`` to limit the history depth of the git clone
+# Uses globals ``ERROR_ON_CLONE``, ``OFFLINE``, ``RECLONE``, ``GIT_DEPTH``
 # git_clone remote dest-dir branch
 function git_clone {
     local git_remote=$1
     local git_dest=$2
     local git_ref=$3
     local orig_dir=$(pwd)
+    local git_clone_flags=""
 
     RECLONE=$(trueorfalse False $RECLONE)
 
+    if [[ "$GIT_DEPTH" ]]; then
+        git_clone_flags="$git_clone_flags --depth $GIT_DEPTH"
+    fi
+
     if [[ "$OFFLINE" = "True" ]]; then
         echo "Running in offline mode, clones already exist"
         # print out the results so we know what change was used in the logs
@@ -586,7 +593,7 @@
         if [[ ! -d $git_dest ]]; then
             [[ "$ERROR_ON_CLONE" = "True" ]] && \
                 die $LINENO "Cloning not allowed in this configuration"
-            git_timed clone $git_remote $git_dest
+            git_timed clone $git_clone_flags $git_remote $git_dest
         fi
         cd $git_dest
         git_timed fetch $git_remote $git_ref && git checkout FETCH_HEAD
@@ -595,7 +602,7 @@
         if [[ ! -d $git_dest ]]; then
             [[ "$ERROR_ON_CLONE" = "True" ]] && \
                 die $LINENO "Cloning not allowed in this configuration"
-            git_timed clone $git_remote $git_dest
+            git_timed clone $git_clone_flags $git_remote $git_dest
             cd $git_dest
             # This checkout syntax works for both branches and tags
             git checkout $git_ref