[gnome-ostree] vcs: Clean up snapshot/vcs API layer



commit 786b0363e95abe40b75cf242ea732b5083a6af42
Author: Colin Walters <walters verbum org>
Date:   Thu Mar 7 09:17:36 2013 -0500

    vcs: Clean up snapshot/vcs API layer
    
    This is preparatory work for future tarball importing.

 src/js/builtins/git_mirror.js |    6 +++---
 src/js/snapshot.js            |   10 ----------
 src/js/tasks/task-resolve.js  |    8 ++------
 src/js/vcs.js                 |   19 +++++++++++++++----
 4 files changed, 20 insertions(+), 23 deletions(-)
---
diff --git a/src/js/builtins/git_mirror.js b/src/js/builtins/git_mirror.js
index d31a984..68ea408 100644
--- a/src/js/builtins/git_mirror.js
+++ b/src/js/builtins/git_mirror.js
@@ -72,13 +72,13 @@ const GitMirror = new Lang.Class({
        }
 
        componentNames.forEach(Lang.bind(this, function (name) {
-           let [keytype, uri, branchOrTag] = this._snapshot.getVcsInfo(name);
+           let component = this._snapshot.getComponent(name);
 
             if (!args.fetch) {
-                Vcs.ensureVcsMirror(this.mirrordir, keytype, uri, branchOrTag, cancellable);
+                Vcs.ensureVcsMirror(this.mirrordir, component, cancellable);
            } else {
                print("Running git fetch for " + name);
-               Vcs.fetch(this.mirrordir, keytype, uri, branchOrTag, cancellable,
+               Vcs.fetch(this.mirrordir, component, cancellable,
                          { keepGoing:args.keep_going,
                            timeoutSec: args.timeout_sec });
            }
diff --git a/src/js/snapshot.js b/src/js/snapshot.js
index fbe760c..30ba08b 100644
--- a/src/js/snapshot.js
+++ b/src/js/snapshot.js
@@ -179,15 +179,5 @@ const Snapshot = new Lang.Class({
 
     getExpanded: function(name) {
        return this._expandComponent(this.getComponent(name));
-    },
-
-    getVcsInfo: function(name) {
-       let component = this.getComponent(name);
-        let src = component['src']
-        let [keytype, uri] = Vcs.parseSrcKey(src);
-        let branch = component['branch'];
-        let tag = component['tag'];
-        let branchOrTag = branch || tag;
-       return [keytype, uri, branchOrTag];
     }
 });
diff --git a/src/js/tasks/task-resolve.js b/src/js/tasks/task-resolve.js
index f43ac46..4d6a401 100644
--- a/src/js/tasks/task-resolve.js
+++ b/src/js/tasks/task-resolve.js
@@ -72,12 +72,8 @@ const TaskResolve = new Lang.Class({
        let componentNames = this._snapshot.getAllComponentNames();
        for (let i = 0; i < componentNames.length; i++) {
            let component = this._snapshot.getComponent(componentNames[i]);
-            let src = component['src'];
-            let [keytype, uri] = Vcs.parseSrcKey(src);
-            let branch = component['branch'];
-            let tag = component['tag'];
-            let branchOrTag = branch || tag;
-            let mirrordir = Vcs.ensureVcsMirror(this.mirrordir, keytype, uri, branchOrTag, cancellable);
+           let branchOrTag = component['branch'] || component['tag'];
+            let mirrordir = Vcs.ensureVcsMirror(this.mirrordir, component, cancellable);
             let revision = Vcs.describeVersion(mirrordir, branchOrTag);
             component['revision'] = revision;
        }
diff --git a/src/js/vcs.js b/src/js/vcs.js
index b1a5ee8..bd466e1 100644
--- a/src/js/vcs.js
+++ b/src/js/vcs.js
@@ -171,11 +171,22 @@ function _listSubmodules(mirrordir, mirror, keytype, uri, branch, cancellable) {
     return submodules;
 }
 
-function ensureVcsMirror(mirrordir, keytype, uri, branch, cancellable,
+function ensureVcsMirror(mirrordir, component, cancellable,
                         params) {
     params = Params.parse(params, { fetch: false,
                                    fetchKeepGoing: false,
                                    timeoutSec: 0 });
+    let [keytype, uri] = parseSrcKey(component['src']);
+    if (keytype == 'git' || keytype == 'local') {
+       let branch = component['branch'] || component['tag'];
+       return this._ensureVcsMirrorGit(mirrordir, uri, branch, cancellable, params);
+    } else {
+       throw new Error("Unhandled keytype=" + keytype);
+    }
+}
+
+function _ensureVcsMirrorGit(mirrordir, uri, branch, cancellable, params) {
+    let keytype = 'git';
     let fetch = params.fetch;
     let mirror = getMirrordir(mirrordir, keytype, uri);
     let tmpMirror = mirror.get_parent().get_child(mirror.get_basename() + '.tmp');
@@ -228,7 +239,7 @@ function ensureVcsMirror(mirrordir, keytype, uri, branch, cancellable,
        _listSubmodules(mirrordir, mirror, keytype, uri, branch, cancellable).forEach(function (elt) {
            let [subChecksum, subName, subUrl] = elt;
            print("Processing submodule " + subName + " at " + subChecksum + " from " + subUrl);
-            ensureVcsMirror(mirrordir, keytype, subUrl, subChecksum, cancellable, params);
+            _ensureVcsMirrorGit(mirrordir, subUrl, subChecksum, cancellable, params);
        });
     }
     
@@ -244,9 +255,9 @@ function uncacheRepository(mirrordir, keytype, uri, branch, cancellable) {
     GSystem.shutil_rm_rf(lastFetchPath, cancellable);
 }
 
-function fetch(mirrordir, keytype, uri, branch, cancellable, params) {
+function fetch(mirrordir, component, cancellable, params) {
     params = Params.parse(params, {keepGoing: false, timeoutSec: 0});
-    ensureVcsMirror(mirrordir, keytype, uri, branch, cancellable,
+    ensureVcsMirror(mirrordir, component, cancellable,
                      { fetch:true,
                        fetchKeepGoing: params.keepGoing,
                        timeoutSec: params.timeoutSec });


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