FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bluebird promises + thenify by heavyk · Pull Request #615 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (58) .json  (1) .md  (1) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 3 additions & 8 deletions examples/add-and-commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["ensureDir", "writeFile"]);
var fileName = "newfile.txt";
var fileContent = "hello world";
var directoryName = "salad/toast/strangerinastrangeland/theresnowaythisexists";
// ensureDir is an alias to mkdirp, which has the callback with a weird name
// and in the 3rd position of 4 (the 4th being used for recursion). We have to
// force promisify it, because promisify-node won't detect it on its
// own and assumes sync
fse.ensureDir = promisify(fse.ensureDir);

/**
* This example creates a certain file `newfile.txt`, adds it to the git
Expand Down Expand Up @@ -71,6 +66,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))

return repo.createCommit("HEAD", author, committer, "message", oid, [parent]);
})
.done(function(commitId) {
.then(function(commitId) {
console.log("New Commit: ", commitId);
});
6 changes: 3 additions & 3 deletions examples/clone.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var nodegit = require("../");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove"]);
var path = "/tmp/nodegit-clone-demo";

fse.remove(path).then(function() {
Expand Down Expand Up @@ -28,7 +28,7 @@ fse.remove(path).then(function() {
entry = entryResult;
return entry.getBlob();
})
.done(function(blob) {
.then(function(blob) {
console.log(entry.filename(), entry.sha(), blob.rawsize() + "b");
console.log("========================================================\n\n");
var firstTenLines = blob.toString().split("\n").slice(0, 10).join("\n");
Expand Down
6 changes: 3 additions & 3 deletions examples/cloneFromGithubWith2Factor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var nodegit = require("../");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove"]);
var path = "/tmp/nodegit-github-2factor-demo";

var token = "{Your GitHub user token}";
Expand Down Expand Up @@ -35,7 +35,7 @@ var opts = {

fse.remove(path).then(function() {
nodegit.Clone(repoUrl, path, opts)
.done(function(repo) {
.then(function(repo) {
if (repo instanceof nodegit.Repository) {
console.info("We cloned the repo!");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/create-branch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
repo.defaultSignature(),
"Created new-branch on HEAD");
});
}).done(function() {
}).then(function() {
console.log("All done!");
});
8 changes: 3 additions & 5 deletions examples/create-new-repo.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["ensureDir", "writeFile"]);
var fileName = "newfile.txt";
var fileContent = "hello world";
var repoDir = "../../newRepo";

fse.ensureDir = promisify(fse.ensureDir);

var repository;
var index;

Expand Down Expand Up @@ -45,6 +43,6 @@ fse.ensureDir(path.resolve(__dirname, repoDir))
// normal we don't get the head either, because there isn't one yet.
return repository.createCommit("HEAD", author, committer, "message", oid, []);
})
.done(function(commitId) {
.then(function(commitId) {
console.log("New Commit: ", commitId);
});
2 changes: 1 addition & 1 deletion examples/details-for-tree-entry.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
});
});
})
.done(function() {
.then(function() {
console.log("Done!");
});
2 changes: 1 addition & 1 deletion examples/diff-commits.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))

return commit.getDiff();
})
.done(function(diffList) {
.then(function(diffList) {
diffList.forEach(function(diff) {
diff.patches().forEach(function(patch) {
console.log("diff", patch.oldFile().path(), patch.newFile().path());
Expand Down
2 changes: 1 addition & 1 deletion examples/fetch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
return nodegit.Cred.sshKeyFromAgent(userName);
}
});
}).done(function() {
}).then(function() {
console.log("It worked!");
});
4 changes: 2 additions & 2 deletions examples/general.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var nodegit = require("../");
var path = require("path");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var oid;
var odb;
var repo;
Expand Down Expand Up @@ -362,6 +362,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
return Promise.all(promises);
})

.done(function() {
.then(function() {
console.log("Done!");
});
8 changes: 4 additions & 4 deletions examples/index-add-and-remove.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var nodegit = require("../");
var path = require("path");
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var Promise = require("bluebird");
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["writeFile"]);

nodegit.Repository.open(path.resolve(__dirname, "../.git"))
.then(function(repo) {
Expand Down Expand Up @@ -129,6 +129,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
console.log("New files in index: " + newFiles.length);
});
});
}).done(function() {
}).then(function() {
console.log("All done!");
});
7 changes: 3 additions & 4 deletions examples/merge-cleanly.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
fse.ensureDir = promisify(fse.ensureDir);
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove", "ensureDir", "writeFile"]);

var ourFileName = "ourNewFile.txt";
var ourFileContent = "I like Toll Roads. I have an EZ-Pass!";
Expand Down Expand Up @@ -123,7 +122,7 @@ fse.remove(path.resolve(__dirname, repoDir))
return repository.createCommit(ourBranch.name(), ourSignature,
ourSignature, "we merged their commit", oid, [ourCommit, theirCommit]);
})
.done(function(commitId) {
.then(function(commitId) {
// We never changed the HEAD after the initial commit;
// it should still be the same as master.
console.log("New Commit: ", commitId);
Expand Down
10 changes: 5 additions & 5 deletions examples/merge-with-conflicts.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
fse.ensureDir = promisify(fse.ensureDir);
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove", "ensureDir", "writeFile"]);
var fs = require("fs");

var repoDir = "../../newRepo";
var fileName = "newFile.txt";
Expand Down Expand Up @@ -163,7 +163,7 @@ fse.remove(path.resolve(__dirname, repoDir))

// if the merge had comflicts, solve them
// (in this case, we simply overwrite the file)
fse.writeFileSync(
fs.writeFileSync(
path.join(repository.workdir(), fileName),
finalFileContent
);
Expand All @@ -187,6 +187,6 @@ fse.remove(path.resolve(__dirname, repoDir))
return repository.createCommit(ourBranch.name(), baseSignature,
baseSignature, "Stop this bob sized fued", oid, [ourCommit, theirCommit]);
})
.done(function(commitId) {
.then(function(commitId) {
console.log("New Commit: ", commitId);
});
2 changes: 1 addition & 1 deletion examples/pull.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ nodegit.Repository.open(path.resolve(__dirname, repoDir))
.then(function() {
return repository.mergeBranches("master", "origin/master");
})
.done(function() {
.then(function() {
console.log("Done!");
});
7 changes: 3 additions & 4 deletions examples/push.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
fse.ensureDir = promisify(fse.ensureDir);
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove", "ensureDir", "writeFile"]);

var fileName = "newFile.txt";
var fileContent = "hello world";
Expand Down Expand Up @@ -64,6 +63,6 @@ fse.remove(path.resolve(__dirname, repoDir))
repository.defaultSignature(),
"Push to master");
});
}).done(function() {
}).then(function() {
console.log("Done!");
});
2 changes: 1 addition & 1 deletion examples/read-file.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
console.log(firstTenLines);
console.log("...");
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/remove-and-commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// from the filesystem.
console.log("New Commit:", commitId.allocfmt());
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/walk-history-for-file.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// Don't forget to call `start()`!
history.start();
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/walk-history.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// Don't forget to call `start()`!
history.start();
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/walk-tree.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// Don't forget to call `start()`!
walker.start();
})
.done();
.then();
4 changes: 1 addition & 3 deletions generate/scripts/generateMissingTests.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const path = require("path");
const Promise = require("nodegit-promise");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const Promise = require("bluebird");
const utils = require("./utils");

const testFilesPath = "../test/tests";
Expand Down
9 changes: 3 additions & 6 deletions generate/scripts/generateNativeCode.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const path = require("path");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});

const promisify = require("thenify-all");
const fse = promisify(require("fs-extra"), ["remove", 'copy']);
const exec = promisify(require("child_process").exec);
const utils = require("./utils");

module.exports = function generateNativeCode() {
Expand Down
4 changes: 2 additions & 2 deletions generate/scripts/utils.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const promisify = require("promisify-node");
const fse = require("fs-extra");
const promisify = require("thenify-all");
const fse = require("fs-extra", []);

const fs = require("fs");
const path = require("path");
Expand Down
67 changes: 65 additions & 2 deletions generate/templates/templates/nodegit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,70 @@
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var Promise = require("bluebird");
var rawApi;

function promisify(source) {
var destination = {};
if (typeof source === "function") {
return thenify(source);
} else {
Object.keys(source).forEach(function (name) {
if (typeof source[name] === "function") {
destination[name] = thenify(source[name]);
}
});
}
}

function thenify ($$__fn__$$) {
return eval(createWrapper($$__fn__$$.name));
}

function createWrapper (name) {
name = name ? ~[
// js reserved words
// "abstract", "arguments", "boolean", "break", "byte", "case", "catch",
// "char", "class", "const", "continue", "debugger", "while", "with",
// "yield", "do", "double", "else", "enum", "eval", "export", "extends",
// "false", "final", "finally", "float", "for", "function", "goto", "if",
// "implements", "import", "in", "instanceof", "int", "interface", "let",
// "long", "native", "new", "null", "package", "private", "protected",
// "public", "return", "short", "static", "super", "switch", "synchronized",
// "this", "throw", "throws", "transient", "true", "try", "typeof", "var",
// "void", "volatile",

"default", "delete"
].indexOf(name) ? "$$" + name : name : "";

/* jshint ignore:start */
return "(function " + name + "() {\n"
+ "var self = this\n"
+ "var len = arguments.length\n"
+ "var args = new Array(len + 1)\n"
+ "for (var i = 0; i < len; ++i) args[i] = arguments[i]\n"
+ "var lastIndex = i\n"
+ "return new Promise(function (resolve, reject) {\n"
+ "args[lastIndex] = createCallback(resolve, reject)\n"
+ "$$__fn__$$.apply(self, args)\n"
+ "})\n"
+ "})"
/* jshint ignore:end */
}

/* jshint ignore:start */
function createCallback(resolve, reject) {
return function(err, value) {
if (err) return reject(err)
var length = arguments.length
if (length <= 2) return resolve(value)
var values = new Array(length - 1)
for (var i = 1; i < length; ++i) values[i - 1] = arguments[i]
resolve(values)
}
}
/* jshint ignore:end */




// Attempt to load the production release first, if it fails fall back to the
// debug release.
try {
Expand Down
2 changes: 1 addition & 1 deletion guides/repositories/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NodeGit.Repository.open(pathToRepo).then(function (sucessfulResult) {
// This is the first function of the then which contains the successfully
// calculated result of the promise
})
.done(function () {
.then(function () {
// If we have a .done then the error will be thrown if there was an error that
// wasn't caught by either providing a 2nd function to the `.then` or a
// `.catch` function
Expand Down
2 changes: 1 addition & 1 deletion guides/repositories/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ NodeGit.Repository.open(pathToRepo).then(function (repo) {
// You can also provide a catch function which will contain the reason why
// any above promises that weren't handled have failed
})
.done(function() {
.then(function() {
// If we have a .done then the error will be thrown if there was an error that
// wasn't caught by either providing a 2nd function to the `.then` or a
// `.catch` function
Expand Down
2 changes: 1 addition & 1 deletion lib/commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var events = require("events");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var NodeGit = require("../");
var Commit = NodeGit.Commit;
var LookupWrapper = NodeGit.Utils.lookupWrapper;
Expand Down
2 changes: 1 addition & 1 deletion lib/convenient_hunk.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var NodeGit = require("../");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var ConvenientLine = NodeGit.ConvenientLine;

function ConvenientHunk(hunk, linesInHunk, patch, i) {
Expand Down
Loading

Back | FazBrowse Home | New Git URL