cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject cordova-lib git commit: CB-8908 Make fetching via git faster via --depth=1
Date Fri, 24 Apr 2015 20:07:26 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master d25812f66 -> 860ff12b2


CB-8908 Make fetching via git faster via --depth=1


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/860ff12b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/860ff12b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/860ff12b

Branch: refs/heads/master
Commit: 860ff12b2507df67946a6a1801599c88fa260ff8
Parents: d25812f
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Apr 24 16:04:56 2015 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Apr 24 16:04:56 2015 -0400

----------------------------------------------------------------------
 cordova-lib/spec-plugman/util/plugins.spec.js | 75 ----------------------
 cordova-lib/src/gitclone.js                   | 39 +++++++----
 2 files changed, 26 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/860ff12b/cordova-lib/spec-plugman/util/plugins.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/util/plugins.spec.js b/cordova-lib/spec-plugman/util/plugins.spec.js
deleted file mode 100644
index f8930e9..0000000
--- a/cordova-lib/spec-plugman/util/plugins.spec.js
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env node
-/*
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-var osenv  = require('osenv'),
-    path   = require('path'),
-    temp   = path.join(osenv.tmpdir(), 'plugman'),
-    shell  = require('shelljs'),
-    child_process = require('child_process'),
-    xml_helpers = require('../../src/util/xml-helpers'),
-    plugins = require('../../src/plugman/util/plugins');
-
-var et = require('elementtree');
-
-describe('plugins utility module', function(){
-    describe('clonePluginGitRepo', function(){
-        var fake_id = 'VillageDrunkard';
-        var execSpy, cp_spy, xml_spy, done;
-        beforeEach(function() {
-            execSpy = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
-                if (!cb) cb = opts;
-                cb(null, 'git output');
-            });
-            spyOn(shell, 'which').andReturn(true);
-            cp_spy = spyOn(shell, 'cp');
-            xml_spy = spyOn(xml_helpers, 'parseElementtreeSync').andReturn(new et.ElementTree(et.XML('<plugin
id="' + fake_id + '"/>')));
-            done = false;
-        });
-        it('should shell out to git clone with correct arguments', function(){
-            var plugin_git_url = 'https://github.com/imhotep/org.test.plugins.childbrowser';
-
-            runs(function() {
-                plugins.clonePluginGitRepo(plugin_git_url, temp, '.', undefined, null)
-                .then(function(val) { done = val; }, function(err) { done = err.stack; });
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                expect(execSpy).toHaveBeenCalled();
-                var git_clone_regex = new RegExp('^git clone "' + plugin_git_url + '" ".*"$',
'gi');
-                expect(execSpy.mostRecentCall.args[0]).toMatch(git_clone_regex);
-
-                expect(done).toMatch(new RegExp(path.sep + fake_id + '$'));
-            });
-        });
-        it('should take into account subdirectory argument when copying over final repository
into plugins+plugin_id directory', function() {
-            var plugin_git_url = 'https://github.com/imhotep/org.test.plugins.childbrowser';
-            var fake_subdir = 'TheBrainRecoilsInHorror';
-            runs(function() {
-                plugins.clonePluginGitRepo(plugin_git_url, temp, fake_subdir, null)
-                .then(function(val) { done = val || true; }, function(err) { done = err;
});
-            });
-            waitsFor(function() { return done; }, 'promise never resolved', 500);
-            runs(function() {
-                var expected_subdir_cp_path = new RegExp(fake_subdir + '[\\\\\\/]\\*$', 'gi');
-                expect(cp_spy.mostRecentCall.args[1]).toMatch(expected_subdir_cp_path);
-                expect(cp_spy.mostRecentCall.args[2]).toEqual(path.join(temp, fake_id));
-            });
-        });
-    });
-});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/860ff12b/cordova-lib/src/gitclone.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/gitclone.js b/cordova-lib/src/gitclone.js
index edc26bc..8ddaeb9 100644
--- a/cordova-lib/src/gitclone.js
+++ b/cordova-lib/src/gitclone.js
@@ -21,8 +21,8 @@ var  Q             = require('q'),
      shell         = require('shelljs'),
      events        = require('./events'),
      path          = require('path'),
-     globalUtil    = require('util'),
-     child_process = require('child_process'),
+     semver        = require('semver'),
+     superspwan    = require('./cordova/superspawn'),
      os            = require('os');
 
 
@@ -31,6 +31,7 @@ exports.clone = clone;
 //  clone_dir, if provided is the directory that git will clone into.
 //  if no clone_dir is supplied, a temp directory will be created and used by git.
 function clone(git_url, git_ref, clone_dir){
+    var needsGitCheckout = !!git_ref;
     if (!shell.which('git')) {
         return Q.reject(new Error('"git" command line tool is not installed: make sure it
is accessible on your PATH.'));
     }
@@ -43,19 +44,31 @@ function clone(git_url, git_ref, clone_dir){
     shell.rm('-rf', tmp_dir);
     shell.mkdir('-p', tmp_dir);
 
-    var cmd = globalUtil.format('git clone "%s" "%s"', git_url, tmp_dir);
-    events.emit('verbose', 'Cloning repository via git-clone command: ' + cmd);
-
-    return Q.ninvoke(child_process, 'exec', cmd, {}).then(function () {
-	if(git_ref){
-	    var checkoutCmd = globalUtil.format('git checkout "%s"', git_ref);
-            events.emit('verbose', 'Checking out git ref via command: ' + checkoutCmd);
-            return Q.ninvoke(child_process, 'exec', checkoutCmd, { cwd: tmp_dir }).then(function(){
-		events.emit('log', 'Repository "' + git_url + '" checked out to git ref "' + git_ref +
'".');
-	    });
+    return superspwan.spawn('git', ['--version'])
+    .then(function(output) {
+        var gitVersion = /\d+\.\d+(\.\d+)?/.exec(output);
+        gitVersion = gitVersion ? gitVersion[0] : '1.0.0';
+        var cloneArgs = ['clone'];
+        if (semver.gte(gitVersion, '1.7.0')) {
+            if (git_ref) {
+                cloneArgs.push('--branch', git_ref);
+                needsGitCheckout = false;
+            }
+            if (semver.gte(gitVersion, '1.7.10')) {
+                cloneArgs.push('--single-branch');
+            }
+            cloneArgs.push('--depth=1');
+        }
+        cloneArgs.push('--', git_url, tmp_dir);
+        return superspwan.spawn('git', cloneArgs);
+    }).then(function() {
+	if (needsGitCheckout){
+            return superspwan.spawn('git', ['checkout', git_ref], {
+                cwd: tmp_dir
+            });
 	}
-	return Q();
     }).then(function(){
+        events.emit('log', 'Repository "' + git_url + '" checked out to git ref "' + git_ref
+ '".');
 	return tmp_dir;
     }).fail(function (err) {
         shell.rm('-rf', tmp_dir);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message