Skip to content

Commit

Permalink
Remove dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhedwardyang committed Oct 24, 2018
1 parent 4c56ddd commit 6959b3a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 144 deletions.
97 changes: 0 additions & 97 deletions node/lib/util/git_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const NodeGit = require("nodegit");
const path = require("path");

const ConfigUtil = require("./config_util");
const DoWorkQueue = require("./do_work_queue");
const Hook = require("./hook");
const GitUtilFast = require("./git_util_fast");
const UserError = require("./user_error");
Expand Down Expand Up @@ -548,102 +547,6 @@ exports.fetchSha = co.wrap(function *(repo, url, sha) {
return true;
});



/**
* Return a list the shas of commits in the history of the specified `commit`
* not present in the history of the specified `remote` in the specified
* `repo`. Note that this command does not do a *fetch*; the check is made
* against what commits are locally known.
*
* async
* @param {NodeGit.Repository} repo
* @param {String} remote
* @param {String} commit
* @return {NodeGit.Oid []}
*/
exports.listUnpushedCommits = co.wrap(function *(repo, remote, commit) {
// I wish there were a simpler way to do this. Our algorithm:
// 1. List all the refs for 'remote'.
// 2. Compute the list of different commits between each the head of each
// matching remote ref.
// 3. Return the shortest list.
// 4. If no matching refs return a list of all commits that are in the
// history of 'commit'.

assert.instanceOf(repo, NodeGit.Repository);
assert.isString(remote);
assert.isString(commit);

const refs = yield repo.getReferenceNames(NodeGit.Reference.TYPE.LISTALL);

const commitId = NodeGit.Oid.fromString(commit);

let bestResult = null;

const regex = new RegExp(`^refs/remotes/${remote}/`);

// The `fastWalk` method takes a max count for the number of items it will
// return. We should investigate why some time because I don't think it
// should be necessary. My guess is that they are creating a fixed size
// array to populate with the commits; an exponential growth algorithm
// like that used by `std::vector` would provide the same (amortized)
// performance. See http://www.nodegit.org/api/revwalk/#fastWalk.
//
// For now, I'm choosing the value 1000000 as something not big enough to
// blow out memory but more than large enough for any repo we're likely to
// encounter.

const MAX_COMMIT_COUNT = 1000000;

const checkRef = co.wrap(function *(name) {

// If we've already matched the commit, no need to do any checking.

if ([] === bestResult) {
return; // RETURN
}

// Check to see if the name of the ref indicates that it is for
// 'remote'.

const nameResult = regex.exec(name);
if (!nameResult) {
return; // RETURN
}

const refHeadCommit = yield repo.getReferenceCommit(name);
const refHead = refHeadCommit.id();

// Use 'RevWalk' to generate the list of commits different between the
// head of the remote branch and our commit.

let revWalk = repo.createRevWalk();
revWalk.pushRange(`${refHead}..${commit}`);
const commitDiff = yield revWalk.fastWalk(MAX_COMMIT_COUNT);

// If this list is shorter than the current best list (or there is no
// current best), store it as the best so far.

if (null === bestResult || bestResult.length > commitDiff.length) {
bestResult = commitDiff;
}
});

yield DoWorkQueue.doInParallel(refs, checkRef);

// If we found no results (no branches for 'remote', return a list
// containing 'commit' and all its history.

if (null === bestResult) {
let revWalk = repo.createRevWalk();
revWalk.push(commitId);
return yield revWalk.fastWalk(MAX_COMMIT_COUNT); // RETURN
}

return bestResult;
});

/**
* Return true if the specified `source` commit is up-to-date with the
* specified `target` commit in the specified `repo`. A commit is up-to-date
Expand Down
47 changes: 0 additions & 47 deletions node/test/util/git_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,53 +744,6 @@ describe("GitUtil", function () {
}));
});

describe("listUnpushedCommits", function () {
const cases = {
"no branches": {
input: "S:Rorigin=foo",
from: "1",
remote: "origin",
expected: ["1"],
},
"up to date": {
input: "S:Rorigin=foo moo=1",
from: "1",
remote: "origin",
expected: [],
},
"one not pushed": {
input: "S:C2-1;Bmaster=2;Rorigin=foo moo=1",
from: "2",
remote: "origin",
expected: ["2"],
},
"two not pushed": {
input: "S:C3-2;C2-1;Bmaster=3;Rorigin=foo moo=1",
from: "3",
remote: "origin",
expected: ["2","3"],
},
};
Object.keys(cases).forEach(caseName => {
const c = cases[caseName];
it(caseName, co.wrap(function *() {
const ast = ShorthandParserUtil.parseRepoShorthand(c.input);
const path = yield TestUtil.makeTempDir();
const written = yield WriteRepoASTUtil.writeRAST(ast, path);
const fromSha = written.oldCommitMap[c.from];
const unpushed = yield GitUtil.listUnpushedCommits(
written.repo,
c.remote,
fromSha);
const unpushedShas = unpushed.map(id => {
assert.instanceOf(id, NodeGit.Oid);
return written.commitMap[id.tostrS()];
});
assert.sameMembers(unpushedShas, c.expected);
}));
});
});

describe("isUpToDate", function () {
const cases = {
"trivial": {
Expand Down

0 comments on commit 6959b3a

Please sign in to comment.