[gnome-continuous] resolve: Add a "git describe" cache



commit 9160d19b234f32a7d80c0b5047566fe0596fa898
Author: Colin Walters <walters verbum org>
Date:   Sun Jan 5 14:48:44 2014 -0500

    resolve: Add a "git describe" cache
    
    In some cases performing a "git describe" may be slow; git has to walk
    all of the commits/tags etc.  Cache this.

 src/js/tasks/task-resolve.js |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/src/js/tasks/task-resolve.js b/src/js/tasks/task-resolve.js
index 18acd4d..1c5ef51 100644
--- a/src/js/tasks/task-resolve.js
+++ b/src/js/tasks/task-resolve.js
@@ -56,6 +56,18 @@ const TaskResolve = new Lang.Class({
         return true;
     },
 
+    _baseCommitFromDescribe: function(describe) {
+       if (describe.length == 40)
+           return describe;
+       let g = describe.lastIndexOf('g');
+       if (g == -1)
+           throw new Error("Failed to determine commit from " + describe);
+       let commit = describe.substring(g+1);
+       if (commit.length != 40) 
+           throw new Error("Failed to determine commit from " + describe);
+       return commit;
+    },
+
     execute: function(cancellable) {
         let manifestPath = this.workdir.get_child('manifest.json');
         this._snapshot = Snapshot.fromFile(manifestPath, cancellable, { prepareResolve: true });
@@ -76,16 +88,41 @@ const TaskResolve = new Lang.Class({
            gitMirrorArgs.push.apply(gitMirrorArgs, componentsToFetch);
        }
        ProcUtil.runSync(gitMirrorArgs, cancellable, { logInitiation: true });
+
+       let resolveCachePath = this.cachedir.get_child('component-git-describe.json');
+       let resolveCache = {};
+       let modifiedCache = true;
+       if (resolveCachePath.query_exists(null)) {
+           resolveCache = JsonUtil.loadJson(resolveCachePath, cancellable);
+           modifiedCache = false;
+       }
        
        let componentNames = this._snapshot.getAllComponentNames();
        for (let i = 0; i < componentNames.length; i++) {
            let component = this._snapshot.getComponent(componentNames[i]);
-           let tagOrBranch = component['tag'] || component['branch'];
+           let tagOrBranch = component['tag'] || component['branch'] || 'master';
             let mirrordir = Vcs.ensureVcsMirror(this.mirrordir, component, cancellable);
-            let revision = Vcs.describeVersion(mirrordir, tagOrBranch);
+           let currentCommit = Vcs.revParse(mirrordir, tagOrBranch, cancellable);
+           let revision = null;
+           let cachedEntry = resolveCache[component['name']];
+           if (cachedEntry) {
+               let previousCommit = cachedEntry['revision'];
+               if (currentCommit == previousCommit)
+                   revision = cachedEntry['describe'];
+           }
+           if (revision == null) {
+               print("Describe cache miss for " + component['name']);
+               revision = Vcs.describeVersion(mirrordir, tagOrBranch);
+               modifiedCache = true;
+               resolveCache[component['name']] = {'revision': currentCommit,
+                                                  'describe': revision};
+           }
             component['revision'] = revision;
        }
 
+       if (modifiedCache)
+            JsonUtil.writeJsonFileAtomic(resolveCachePath, resolveCache, cancellable);
+
         let modified = this._writeSnapshotToBuild(cancellable);
         if (modified) {
             print("New source snapshot");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]