Skip to content

Commit cd5c051

Browse files
committed
Normalize fn names for overrides
When we override a function on a nodegit type, what we generally do is pull the function out and save it, and write a new function to the object that calls the old saved value. The names we used to save things were never consistant. Using the made up reset.getCommit as an example, we might have `originalGetCommit`, `_getCommit`, `resetGetCommit`, or if it wasn't a keyword, just `getCommit`. I changed them all to `_getCommit`. Also sometimes they would be at tht eotp of the file, sometimes down by the override. I moved them all up top.
1 parent ba081a7 commit cd5c051

File tree

19 files changed

+88
-79
lines changed

19 files changed

+88
-79
lines changed

lib/blame.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var NodeGit = require("../");
22
var normalizeOptions = NodeGit.Utils.normalizeOptions;
33
var Blame = NodeGit.Blame;
4+
45
var _file = Blame.file;
56

67
/**

lib/clone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Clone.clone = function(url, local_path, options) {
5454
return NodeGit.Repository.open(local_path);
5555
};
5656

57-
return clone.call(this, url, local_path, options)
57+
return _clone.call(this, url, local_path, options)
5858
.then(freeRepository)
5959
.then(openRepository);
6060
};

lib/commit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var NodeGit = require("../");
33
var Commit = NodeGit.Commit;
44
var LookupWrapper = NodeGit.Utils.lookupWrapper;
55

6+
var _amend = Commit.prototype.amend;
67
/**
78
* Retrieves the commit pointed to by the oid
89
* @async
@@ -23,7 +24,6 @@ Commit.lookup = LookupWrapper(Commit);
2324
* @param {Tree|Oid} tree
2425
* @param {Oid} callback
2526
*/
26-
var amend = Commit.prototype.amend;
2727
Commit.prototype.amend = function (
2828
updateRef, author, committer, message_encoding, message, tree, callback) {
2929
var repo = this.repo;
@@ -38,7 +38,7 @@ Commit.prototype.amend = function (
3838

3939
return treePromise
4040
.then(function(treeObject){
41-
return amend.call(_this,
41+
return _amend.call(_this,
4242
updateRef,
4343
author,
4444
committer,

lib/diff.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ var Diff = NodeGit.Diff;
33
var normalizeOptions = NodeGit.Utils.normalizeOptions;
44
var Patch = NodeGit.Patch;
55

6-
var blobToBuffer = Diff.blobToBuffer;
6+
var _blobToBuffer = Diff.blobToBuffer;
7+
var _indexToWorkdir = Diff.indexToWorkdir;
8+
var _treeToIndex = Diff.treeToIndex;
9+
var _treeToTree = Diff.treeToTree;
10+
var _treeToWorkdir = Diff.treeToWorkdir;
11+
var _treeToWorkdirWithIndex = Diff.treeToWorkdirWithIndex;
12+
13+
var _findSimilar = Diff.prototype.findSimilar;
14+
715
/**
816
* Directly run a diff between a blob and a buffer.
917
* @async
@@ -42,7 +50,7 @@ Diff.blobToBuffer= function(
4250

4351
opts = normalizeOptions(opts, NodeGit.DiffOptions);
4452

45-
return blobToBuffer.call(
53+
return _blobToBuffer.call(
4654
this,
4755
old_blob,
4856
old_as_path,
@@ -58,45 +66,39 @@ Diff.blobToBuffer= function(
5866
};
5967

6068
// Override Diff.indexToWorkdir to normalize opts
61-
var indexToWorkdir = Diff.indexToWorkdir;
6269
Diff.indexToWorkdir = function(repo, index, opts) {
6370
opts = normalizeOptions(opts, NodeGit.DiffOptions);
64-
return indexToWorkdir(repo, index, opts);
71+
return _indexToWorkdir(repo, index, opts);
6572
};
6673

6774
// Override Diff.treeToIndex to normalize opts
68-
var treeToIndex = Diff.treeToIndex;
6975
Diff.treeToIndex = function(repo, tree, index, opts) {
7076
opts = normalizeOptions(opts, NodeGit.DiffOptions);
71-
return treeToIndex(repo, tree, index, opts);
77+
return _treeToIndex(repo, tree, index, opts);
7278
};
7379

7480
// Override Diff.treeToTree to normalize opts
75-
var treeToTree = Diff.treeToTree;
7681
Diff.treeToTree = function(repo, from_tree, to_tree, opts) {
7782
opts = normalizeOptions(opts, NodeGit.DiffOptions);
78-
return treeToTree(repo, from_tree, to_tree, opts);
83+
return _treeToTree(repo, from_tree, to_tree, opts);
7984
};
8085

8186
// Override Diff.treeToWorkdir to normalize opts
82-
var treeToWorkdir = Diff.treeToWorkdir;
8387
Diff.treeToWorkdir = function(repo, tree, opts) {
8488
opts = normalizeOptions(opts, NodeGit.DiffOptions);
85-
return treeToWorkdir(repo, tree, opts);
89+
return _treeToWorkdir(repo, tree, opts);
8690
};
8791

8892
// Override Diff.treeToWorkdir to normalize opts
89-
var treeToWorkdirWithIndex = Diff.treeToWorkdirWithIndex;
9093
Diff.treeToWorkdirWithIndex = function(repo, tree, opts) {
9194
opts = normalizeOptions(opts, NodeGit.DiffOptions);
92-
return treeToWorkdirWithIndex(repo, tree, opts);
95+
return _treeToWorkdirWithIndex(repo, tree, opts);
9396
};
9497

9598
// Override Diff.findSimilar to normalize opts
96-
var findSimilar = Diff.prototype.findSimilar;
9799
Diff.prototype.findSimilar = function(opts) {
98100
opts = normalizeOptions(opts, NodeGit.DiffFindOptions);
99-
return findSimilar.call(this, opts);
101+
return _findSimilar.call(this, opts);
100102
};
101103

102104
/**

lib/diff_line.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var NodeGit = require("../");
22
var DiffLine = NodeGit.DiffLine;
33

4+
var _rawContent = DiffLine.prototype.content;
5+
46
/**
57
* The relevant line
68
* @return {String}
@@ -23,9 +25,8 @@ DiffLine.prototype.content = function() {
2325
* The non utf8 translated text
2426
* @return {String}
2527
*/
26-
var rawContent = DiffLine.prototype.content;
2728
DiffLine.prototype.rawContent = function() {
28-
return rawContent.call(this);
29+
return _rawContent.call(this);
2930
};
3031

3132
NodeGit.DiffLine = DiffLine;

lib/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ var NodeGit = require("../");
22

33
var Index = NodeGit.Index;
44

5-
var addAll = Index.prototype.addAll;
5+
var _addAll = Index.prototype.addAll;
6+
var _removeAll = Index.prototype.removeAll;
7+
var _updateAll = Index.prototype.updateAll;
8+
69
Index.prototype.addAll = function(pathspec, flags, matchedCallback) {
7-
return addAll.call(this, pathspec || "*", flags, matchedCallback, null);
10+
return _addAll.call(this, pathspec || "*", flags, matchedCallback, null);
811
};
912

1013
/**
@@ -22,12 +25,10 @@ Index.prototype.entries = function() {
2225
return result;
2326
};
2427

25-
var removeAll = Index.prototype.removeAll;
2628
Index.prototype.removeAll = function(pathspec, matchedCallback) {
27-
return removeAll.call(this, pathspec || "*", matchedCallback, null);
29+
return _removeAll.call(this, pathspec || "*", matchedCallback, null);
2830
};
2931

30-
var updateAll = Index.prototype.updateAll;
3132
Index.prototype.updateAll = function(pathspec, matchedCallback) {
32-
return updateAll.call(this, pathspec || "*", matchedCallback, null);
33+
return _updateAll.call(this, pathspec || "*", matchedCallback, null);
3334
};

lib/merge.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ var NodeGit = require("../");
22
var normalizeOptions = NodeGit.Utils.normalizeOptions;
33

44
var Merge = NodeGit.Merge;
5-
var mergeCommits = Merge.commits;
6-
var mergeMerge = Merge.merge;
5+
var _commits = Merge.commits;
6+
var _merge = Merge.merge;
77

88
/**
99
* Merge 2 commits together and create an new index that can
@@ -21,7 +21,7 @@ Merge.commits = function(repo, ourCommit, theirCommit, options) {
2121
repo.getCommit(ourCommit),
2222
repo.getCommit(theirCommit)
2323
]).then(function(commits) {
24-
return mergeCommits.call(this, repo, commits[0], commits[1], options);
24+
return _commits.call(this, repo, commits[0], commits[1], options);
2525
});
2626
};
2727

@@ -42,6 +42,6 @@ Merge.merge = function(repo, theirHead, mergeOpts, checkoutOpts) {
4242
// exactly one to have been passed in or it will throw an error... ¯\_(ツ)_/¯
4343
var theirHeads = [theirHead];
4444

45-
return mergeMerge.call(this, repo, theirHeads, theirHeads.length,
45+
return _merge.call(this, repo, theirHeads, theirHeads.length,
4646
mergeOpts, checkoutOpts);
4747
};

lib/note.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ var NodeGit = require("../");
22

33
var Note = NodeGit.Note;
44

5+
var _foreach = Note.foreach;
6+
57
// Override Note.foreach to eliminate the need to pass null payload
6-
var foreach = Note.foreach;
78
Note.foreach = function(repo, notesRef, callback) {
89
function wrapperCallback(blobId, objectId) {
910
// We need to copy the OID since libgit2 types are getting cleaned up
@@ -12,5 +13,5 @@ Note.foreach = function(repo, notesRef, callback) {
1213
return callback(blobId.copy(), objectId.copy());
1314
}
1415

15-
return foreach(repo, notesRef, wrapperCallback, null);
16+
return _foreach(repo, notesRef, wrapperCallback, null);
1617
};

lib/odb.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var NodeGit = require("../");
22

33
var Odb = NodeGit.Odb;
4-
var read = Odb.prototype.read;
4+
5+
var _read = Odb.prototype.read;
56

67
Odb.prototype.read = function(oid, callback) {
7-
return read.call(this, oid).then(function(odbObject) {
8+
return _read.call(this, oid).then(function(odbObject) {
89
if (typeof callback === "function") {
910
callback(null, odbObject);
1011
}

lib/rebase.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var Rebase = NodeGit.Rebase;
33
var normalizeOptions = NodeGit.Utils.normalizeOptions;
44
var shallowClone = NodeGit.Utils.shallowClone;
55

6+
var _init = Rebase.init;
7+
var _open = Rebase.open;
68
/**
79
* Initializes a rebase
810
* @async
@@ -57,13 +59,12 @@ function defaultRebaseOptions(options, checkoutStrategy) {
5759
return options;
5860
}
5961

60-
var init = Rebase.init;
6162
Rebase.init = function(repository, branch, upstream, onto, options) {
6263
options = defaultRebaseOptions(
6364
options,
6465
NodeGit.Checkout.STRATEGY.FORCE
6566
);
66-
return init(repository, branch, upstream, onto, options);
67+
return _init(repository, branch, upstream, onto, options);
6768
};
6869

6970
/**
@@ -75,11 +76,10 @@ Rebase.init = function(repository, branch, upstream, onto, options) {
7576
* @param {Function} callback
7677
* @return {Remote}
7778
*/
78-
var rebaseOpen = Rebase.open;
7979
Rebase.open = function(repository, options) {
8080
options = defaultRebaseOptions(
8181
options,
8282
NodeGit.Checkout.STRATEGY.SAFE
8383
);
84-
return rebaseOpen(repository, options);
84+
return _open(repository, options);
8585
};

0 commit comments

Comments
 (0)