Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Make git.countUserAdjacentCommits synchronous.
Browse files Browse the repository at this point in the history
Close #363.
  • Loading branch information
henvic committed Feb 25, 2015
1 parent 0c0737d commit 7ea1c66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
16 changes: 8 additions & 8 deletions lib/cmds/pull-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,18 +741,18 @@ PullRequest.prototype.open = function(opt_callback) {

PullRequest.prototype.setMergeCommentRequiredOptions_ = function(opt_callback) {
var options = this.options,
lastCommitSHA = git.getLastCommitSHA();
lastCommitSHA = git.getLastCommitSHA(),
changes = git.countUserAdjacentCommits();

options.currentSHA = lastCommitSHA;

git.countUserAdjacentCommits(function(err, counter) {
if (counter > 0) {
options.changes = counter;
}
options.pullHeadSHA = lastCommitSHA + '~' + counter;
if (changes > 0) {
options.changes = changes;
}

opt_callback && opt_callback();
});
options.pullHeadSHA = lastCommitSHA + '~' + changes;

opt_callback && opt_callback();
};

PullRequest.prototype.sortPullsByComplexity_ = function(data) {
Expand Down
36 changes: 19 additions & 17 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,29 @@ exports.clone = function(url, folder) {
});
};

exports.countUserAdjacentCommits = function(opt_callback) {
var skip = 0,
counter = [0],
myUser = exports.getConfig('user.name');

exports.countUserAdjacentCommits_(opt_callback, skip, myUser, counter);
};
exports.countUserAdjacentCommits = function() {
var git,
params,
commits = 0,
user = exports.getConfig('user.name'),
author;

exports.countUserAdjacentCommits_ = function(opt_callback, skip, myUser, counter) {
skip = skip || 0;
do {
params = ['log', '-1', '--skip=' + commits, '--pretty=%an'];
git = exec.spawnSync(git_command, params);

exports.spawnGit('log', ['-1', '--skip=' + skip, '--pretty="%an"'], function(err, user) {
if (myUser === user.trim()) {
skip++;
counter[0]++;
exports.countUserAdjacentCommits_(opt_callback, skip, myUser, counter);
return;
if (git.status !== 0) {
logger.error(git.stderr);
}

opt_callback(err, counter[0]);
});
author = git.stdout;

commits += 1;
} while (author === user);

commits -= 1;

return commits;
};

exports.deleteArrayEmptyValues_ = function(values) {
Expand Down

0 comments on commit 7ea1c66

Please sign in to comment.