From 3a0c4d93c7c4f8e6c9a42c9b94a165b56888c52d Mon Sep 17 00:00:00 2001
From: Wong Hoi Sing Edison <hswong3i@gmail.com>
Date: Wed, 19 Sep 2012 22:56:57 +0800
Subject: [PATCH 1/2] Issue #1511112 by fgm, blueyed and hswong3i: git_deploy
 slows down module install/enable massively.

---
 git_deploy.module |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/git_deploy.module b/git_deploy.module
index e35ff7c..ad646cb 100644
--- a/git_deploy.module
+++ b/git_deploy.module
@@ -30,6 +30,15 @@ function git_deploy_system_info_alter(&$info, $file, $type = NULL) {
       // Theoretically /.git could exist.
       if ($directory && file_exists($git_dir)) {
         $git = "git --git-dir $git_dir";
+        // Get cached values and return ASAP.
+        exec("$git rev-parse --verify HEAD 2>&1", $head_hash);
+        $head_hash = $head_hash[0];
+        if ($cache = cache_get("git_deploy:$directory:$head_hash")) {
+          $info['datestamp'] = $cache->data['datestamp'];
+          $info['project'] = $cache->data['project'];
+          $info['version'] = $cache->data['version'];
+          return;
+        }
         // Find first the project name based on fetch URL.
         // Eat error messages. >& is valid on Windows, too. Also, $output does
         // not need initialization because it's taken by reference.
@@ -81,6 +90,11 @@ function git_deploy_system_info_alter(&$info, $file, $type = NULL) {
         if ($datestamp && is_numeric($datestamp[0])) {
           $info['datestamp'] = $datestamp[0];
         }
+        // Save values into cache.
+        foreach (array('datestamp', 'project', 'version') as $key) {
+          $cache[$key] = isset($info[$key]) ? $info[$key] : NULL;
+        }
+        cache_set("git_deploy:$directory:$head_hash", $cache);
       }
     }
   }
-- 
1.7.9.5


From 68ba370135998ddd68ddbee1eaff45f2ed4aaf3f Mon Sep 17 00:00:00 2001
From: Wong Hoi Sing Edison <hswong3i@gmail.com>
Date: Wed, 19 Sep 2012 23:03:15 +0800
Subject: [PATCH 2/2] Issue #1511112 by fgm, blueyed and hswong3i: git_deploy
 slows down module install/enable massively (Part 2).

---
 git_deploy.module |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/git_deploy.module b/git_deploy.module
index ad646cb..36b2b83 100644
--- a/git_deploy.module
+++ b/git_deploy.module
@@ -34,9 +34,9 @@ function git_deploy_system_info_alter(&$info, $file, $type = NULL) {
         exec("$git rev-parse --verify HEAD 2>&1", $head_hash);
         $head_hash = $head_hash[0];
         if ($cache = cache_get("git_deploy:$directory:$head_hash")) {
-          $info['datestamp'] = $cache->data['datestamp'];
-          $info['project'] = $cache->data['project'];
-          $info['version'] = $cache->data['version'];
+          foreach (array('datestamp', 'project', 'version') as $key) {
+            $info[$key] = isset($cache->data[$key]) ? $cache->data[$key] : NULL;
+          }
           return;
         }
         // Find first the project name based on fetch URL.
-- 
1.7.9.5

