Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Put a lock around requests so we don't ask the same question in paral…

…lel to the subprocess.
  • Loading branch information...
commit c34dab79c8618440fe88a2a2b92f58104322a977 1 parent d459edd
@creationix authored
Showing with 30 additions and 20 deletions.
  1. +30 −20 lib/git.js
View
50 lib/git.js
@@ -1,26 +1,23 @@
/*
Copyright (c) 2010 Tim Caswell <tim@creationix.com>
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
*/
var ChildProcess = require('child_process'),
@@ -56,8 +53,16 @@ var Git = module.exports = function (repo) {
};
+
+var execQueue = {};
// Internal helper to talk to the git subprocess
function gitExec(commands, callback) {
+ var key = commands.join(' ');
+ if (execQueue[key]) {
+ execQueue[key].push(callback);
+ return;
+ }
+ execQueue[key] = [callback];
commands = gitCommands.concat(commands);
var child = ChildProcess.spawn("git", commands);
var stdout = "", stderr = "";
@@ -69,11 +74,16 @@ function gitExec(commands, callback) {
stderr += text;
});
child.addListener('exit', function (code) {
+ var args;
if (code > 0) {
- callback(new Error("git " + commands.join(" ") + "\n" + stderr));
+ args = new Error("git " + commands.join(" ") + "\n" + stderr);
} else {
- callback(null, stdout);
+ args = [null, stdout];
}
+ execQueue[key].forEach(function (callback) {
+ callback.apply(null, args);
+ });
+ delete execQueue[key];
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.