From bd4bf7e8418993b5296713bf07448d89e09103fd Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Wed, 19 Nov 2014 17:25:33 -0700 Subject: [PATCH 1/7] automatically rename functions with weird two-word words Conflicts: generate/descriptor.json generate/utils.js --- generate/descriptor.json | 23 +++++++++-------------- generate/utils.js | 14 ++++++++++++-- lib/index.js | 2 +- lib/tree.js | 6 ++++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/generate/descriptor.json b/generate/descriptor.json index eb55e625d..eb92871b8 100644 --- a/generate/descriptor.json +++ b/generate/descriptor.json @@ -554,9 +554,6 @@ "git_index_add_all": { "ignore": true }, - "git_index_add_bypath": { - "jsFunctionName": "addByPath" - }, "git_index_conflict_get": { "ignore": true }, @@ -584,13 +581,13 @@ "git_index_new": { "ignore": true }, - "git_index_read": { - "args": { - "force": { - "isOptional": true - } - } - }, + "git_index_read": { + "args": { + "force": { + "isOptional": true + } + } + }, "git_index_remove_all": { "ignore": true }, @@ -599,7 +596,7 @@ }, "git_index_update_all": { "ignore": true - }, + }, "git_index_write": { "args": { "force": { @@ -827,7 +824,6 @@ "ignore": true }, "git_oid_fromstr": { - "jsFunctionName": "fromString", "isAsync": false }, "git_oid_fromstrn": { @@ -852,8 +848,7 @@ "ignore": true }, "git_oid_tostr": { - "ignore": true, - "jsFunctionName": "toString" + "ignore": true } }, "fields": { diff --git a/generate/utils.js b/generate/utils.js index cbc3e70b1..ff75d67b3 100644 --- a/generate/utils.js +++ b/generate/utils.js @@ -75,7 +75,18 @@ var Utils = { }, cTypeToJsName: function(cType, ownerType) { - return Utils.camelCase(Utils.cTypeToCppName(cType, ownerType).replace("Git", "")); + var output = Utils.camelCase(Utils.cTypeToCppName(cType, ownerType).replace(/^Git/, "")); + var mergedPrefixes = ["from", "by"]; + + mergedPrefixes.forEach(function(prefix) { + var reg = new RegExp("(^" + prefix + "|" + Utils.titleCase(prefix) + ")([a-z]+)$"); + output = output.replace(reg, function(all, prefixMatch, otherWord) { + return prefixMatch + Utils.titleCase(otherWord); + }); + }); + + output = output.replace(/([a-z])Str$/, "$1String") + return output; }, isConstructorFunction: function(cType, fnName) { @@ -287,7 +298,6 @@ var Utils = { fnDef.jsFunctionName = Utils.cTypeToJsName(key, "git_" + typeDef.typeName); //fnDef.isAsync = false; // until proven otherwise - if (fnDef.cppFunctionName == typeDef.cppClassName) { fnDef.cppFunctionName = fnDef.cppFunctionName.replace("Git", ""); } diff --git a/lib/index.js b/lib/index.js index f9beecba3..e49597512 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,7 +11,7 @@ Index.prototype.entries = function() { var result = []; for (var i = 0; i < size; i++) { - result.push(this.entry(i)); + result.push(this.getByIndex(i)); } return result; diff --git a/lib/tree.js b/lib/tree.js index e4d7ec184..c034429bc 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -4,6 +4,7 @@ var Treebuilder = git.Treebuilder; var Diff = git.Diff; var events = require("events"); +var oldEntryByIndex = Tree.prototype.entryByIndex; // Backwards compatibility. Object.defineProperties(Tree.prototype, { "size": { @@ -34,8 +35,9 @@ Tree.prototype.diff = function(tree, callback) { * @param {Number} i * @return {TreeEntry} */ + Tree.prototype.entryByIndex = function(i) { - var entry = this.entryByindex(i); + var entry = oldEntryByIndex.call(this, i); entry.parent = this; return entry; }; @@ -62,7 +64,7 @@ Tree.prototype.entryByName = function(name) { Tree.prototype.getEntry = function(path, callback) { var tree = this; - return this.entryBypath(path).then(function(entry) { + return this.entryByPath(path).then(function(entry) { entry.parent = tree; if (typeof callback === "function") { From 002ed81ac5ff854fe310f2334b3d7a3201d2628c Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 20 Nov 2014 18:06:42 -0700 Subject: [PATCH 2/7] remove manually generated enums --- example/general.js | 4 +- example/walk-history.js | 5 +-- generate/descriptor.json | 63 ++++++++++++++++++++++++++++++-- generate/index.js | 22 +---------- generate/libgit2-supplement.json | 34 +++++++++++++++++ generate/setup.js | 6 +-- generate/templates/enums.js | 17 ++++----- lib/blob.js | 4 +- lib/convenient_patch.js | 18 ++++----- lib/diff.js | 35 ------------------ lib/object.js | 21 ++--------- lib/refs.js | 14 ++++--- lib/repository.js | 6 +-- lib/revwalk.js | 10 ----- lib/tree.js | 23 ++++-------- lib/tree_entry.js | 21 ++--------- test/tests/blob.js | 4 +- test/tests/commit.js | 36 +++++++++++------- test/tests/diff.js | 12 +++--- test/tests/odb.js | 8 ++-- test/tests/tag.js | 2 +- 21 files changed, 180 insertions(+), 185 deletions(-) diff --git a/example/general.js b/example/general.js index 92a8b9f7a..973085dce 100644 --- a/example/general.js +++ b/example/general.js @@ -179,7 +179,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) oid = nodegit.Oid.fromString("e1b0c7ea57bfc5e30ec279402a98168a27838ac9"); return repo.getTree(oid); }).then(function(tree) { - console.log("Tree Size:", tree.size()); + console.log("Tree Size:", tree.entryCount()); function dfs(tree) { var promises = []; @@ -248,7 +248,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) // of `branch1`. var revWalk = repo.createRevWalk(); - revWalk.sorting(nodegit.Revwalk.Sort.Topological, nodegit.Revwalk.Sort.Reverse); + revWalk.sorting(nodegit.Revwalk.SORT.TOPOLOGICAL, nodegit.Revwalk.SORT.REVERSE); revWalk.push(oid); diff --git a/example/walk-history.js b/example/walk-history.js index f12e6503f..42d3ccb44 100644 --- a/example/walk-history.js +++ b/example/walk-history.js @@ -1,6 +1,5 @@ var nodegit = require('../'), - path = require('path'), - sort = nodegit.Revwalk.Sort; + path = require('path'); // This code walks the history of the master branch and prints results // that look very similar to calling `git log` from the command line @@ -9,7 +8,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) return repo.getMasterCommit(); }).then(function(firstCommitOnMaster){ // History returns an event. - var history = firstCommitOnMaster.history(sort.Time); + var history = firstCommitOnMaster.history(nodegit.Revwalk.SORT.Time); // History emits 'commit' event for each commit in the branch's history history.on('commit', function(commit) { diff --git a/generate/descriptor.json b/generate/descriptor.json index eb92871b8..30cee7850 100644 --- a/generate/descriptor.json +++ b/generate/descriptor.json @@ -12,6 +12,9 @@ } } }, + "delta": { + "owner": "Diff" + }, "error": { "JsName": "ERROR", "isMask": false @@ -23,6 +26,57 @@ } } }, + "filemode": { + "owner": "TreeEntry", + "values": { + "GIT_FILEMODE_BLOB_EXECUTABLE": { + "JsName": "EXECUTABLE" + } + } + }, + "otype": { + "JsName": "TYPE", + "owner": "Object", + "values": { + "GIT_OBJ_ANY": { + "JsName": "ANY" + }, + "GIT_OBJ_BAD": { + "JsName": "BAD" + }, + "GIT_OBJ__EXT1": { + "JsName": "EXT1" + }, + "GIT_OBJ_COMMIT": { + "JsName": "COMMIT" + }, + "GIT_OBJ_TREE": { + "JsName": "TREE" + }, + "GIT_OBJ_BLOB": { + "JsName": "BLOB" + }, + "GIT_OBJ_TAG": { + "JsName": "TAG" + }, + "GIT_OBJ__EXT2": { + "JsName": "EXT2" + }, + "GIT_OBJ_OFS_DELTA": { + "JsName": "OFS_DELTA" + }, + "GIT_OBJ_REF_DELTA": { + "JsName": "REF_DELTA" + } + } + }, + "ref": { + "owner": "Refs", + "JsName": "TYPE" + }, + "sort": { + "owner": "Revwalk" + }, "status": { "JsName": "STATUS", "isMask": false @@ -575,9 +629,6 @@ "git_index_free": { "ignore": true }, - "git_index_get_byindex": { - "jsFunctionName": "entry" - }, "git_index_new": { "ignore": true }, @@ -1222,6 +1273,12 @@ }, "tree": { "functions": { + "git_tree_entry_byindex": { + "jsFunctionName": "_entryByIndex" + }, + "git_tree_entrycount": { + "jsFunctionName": "entryCount" + }, "git_tree_walk": { "ignore": true } diff --git a/generate/index.js b/generate/index.js index ce8d558e4..ea479600f 100644 --- a/generate/index.js +++ b/generate/index.js @@ -88,10 +88,8 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() { // Write out all the classes. - var enums = []; enabled.forEach(function(idef) { try { - if (idef.type == "struct") { file.write("../src/" + idef.filename + ".cc", templates.struct_content.render(idef)); file.write("../include/" + idef.filename + ".h", templates.struct_header.render(idef)); @@ -100,29 +98,11 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() { file.write("../src/" + idef.filename + ".cc", templates.class_content.render(idef)); file.write("../include/" + idef.filename + ".h", templates.class_header.render(idef)); } - else if (idef.type == "enum") { - enums.push(idef); - } } catch (e) { console.log(e); } }); - enums = enums.reduce(function(memo, enumerable) { - - memo[enumerable.owner] = memo[enumerable.owner] || []; - - memo[enumerable.owner].push(enumerable); - delete enumerable.owner; - return memo; - }, {}); - - - var output = []; - Object.keys(enums).forEach(function(key) { - output.push({owner: key, enums: enums[key]}); - }); - - file.write("../lib/enums.js", templates.enums.render(output)); + file.write("../lib/enums.js", templates.enums.render(enabled)); }); diff --git a/generate/libgit2-supplement.json b/generate/libgit2-supplement.json index b813a7bc2..73e33edc9 100644 --- a/generate/libgit2-supplement.json +++ b/generate/libgit2-supplement.json @@ -188,6 +188,40 @@ "type": "enum" } ], + [ + "git_sort_t", + { + "type": "enum", + "description": "Flags to specify the sorting which a revwalk should perform.", + "fields": [ + { + "type": "int", + "name": "GIT_SORT_NONE", + "comments": "Sort the repository contents in no particular ordering; this sorting is arbitrary, implementation-specific and subject to change at any time. This is the default sorting for new walkers.", + "value": 0 + }, + { + "type": "int", + "name": "GIT_SORT_TOPOLOGICAL", + "comments": "Sort the repository contents in topological order (parents before children); this sorting mode can be combined with time sorting.", + "value": 1 + }, + { + "type": "int", + "name": "GIT_SORT_TIME", + "comments": "Sort the repository contents by commit time; this sorting mode can be combined with topological sorting.", + "value": 2 + }, + { + "type": "int", + "name": "GIT_SORT_REVERSE", + "comments": "Iterate through the repository contents in reverse order; this sorting mode can be combined with any of the above.", + "value": 4 + } + ], + "comments": "" + } + ], [ "git_time_t", { diff --git a/generate/setup.js b/generate/setup.js index 4b9c12274..f8ce34cea 100644 --- a/generate/setup.js +++ b/generate/setup.js @@ -160,9 +160,7 @@ output.forEach(function (def) { def.name = path.basename(def.filename, ".h"); def.functions.forEach(function(fn) { - if (fn) { - fn.cppClassName = def.cppClassName; - } + fn.cppClassName = def.cppClassName; }); }); @@ -179,7 +177,7 @@ _(enums).forEach(function(enumerable) { var override = descriptor.enums[enumerable.typeName] || {}; - enumerable.owner = enumerable.owner || "Enums"; + enumerable.owner = override.owner || enumerable.owner || "Enums"; enumerable.JsName = enumerable.typeName .replace(new RegExp("^" + enumerable.owner.toLowerCase()), "") diff --git a/generate/templates/enums.js b/generate/templates/enums.js index d70904e95..210ddcf91 100644 --- a/generate/templates/enums.js +++ b/generate/templates/enums.js @@ -2,18 +2,15 @@ var NodeGit = require("../"); NodeGit.Enums = {}; /* jshint ignore:start */ -{% each %} -var {{ owner }} = NodeGit.{{ owner }}; - - {% each enums as enumerable %} - {% if enumerable.type == "enum" %} -{{ owner }}.{{ enumerable.JsName }} = { - {% each enumerable.values as value %} +{% each . as enumerable %} +{% if enumerable.type == "enum" %} +NodeGit.{{ enumerable.owner }}.{{ enumerable.JsName }} = { +{% each enumerable.values as value %} {{ value.JsName }}: {{ value.value }}, - {% endeach %} +{% endeach %} }; - {% endif %} - {% endeach %} +{% endif %} {% endeach %} + /* jshint ignore:end */ diff --git a/lib/blob.js b/lib/blob.js index 5c0c87e16..4f8527273 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -27,9 +27,9 @@ Blob.prototype.toString = function() { * @return {number} The filemode. */ Blob.prototype.filemode = function() { - var FileMode = TreeEntry.FileMode; + var FileMode = TreeEntry.FILEMODE; - return this.isBinary() ? FileMode.Executable : FileMode.Blob; + return this.isBinary() ? FileMode.EXECUTABLE : FileMode.BLOB; }; module.exports = Blob; diff --git a/lib/convenient_patch.js b/lib/convenient_patch.js index 54fedc17e..b6f915114 100644 --- a/lib/convenient_patch.js +++ b/lib/convenient_patch.js @@ -59,7 +59,7 @@ ConvenientPatch.prototype.status = function() { * @return {Boolean} */ ConvenientPatch.prototype.isUnmodified = function() { - return this.status() == Diff.Delta.Unmodified; + return this.status() == Diff.DELTA.UNMODIFIED; }; /** @@ -67,7 +67,7 @@ ConvenientPatch.prototype.isUnmodified = function() { * @return {Boolean} */ ConvenientPatch.prototype.isAdded = function() { - return this.status() == Diff.Delta.Added; + return this.status() == Diff.DELTA.ADDED; }; /** @@ -75,7 +75,7 @@ ConvenientPatch.prototype.isAdded = function() { * @return {Boolean} */ ConvenientPatch.prototype.isDeleted = function() { - return this.status() == Diff.Delta.Deleted; + return this.status() == Diff.DELTA.DELETED; }; /** @@ -83,7 +83,7 @@ ConvenientPatch.prototype.isDeleted = function() { * @return {Boolean} */ ConvenientPatch.prototype.isModified = function() { - return this.status() == Diff.Delta.Modified; + return this.status() == Diff.DELTA.MODIFIED; }; /** @@ -91,7 +91,7 @@ ConvenientPatch.prototype.isModified = function() { * @return {Boolean} */ ConvenientPatch.prototype.isRenamed = function() { - return this.status() == Diff.Delta.Renamed; + return this.status() == Diff.DELTA.RENAMED; }; /** @@ -99,7 +99,7 @@ ConvenientPatch.prototype.isRenamed = function() { * @return {Boolean} */ ConvenientPatch.prototype.isCopied = function() { - return this.status() == Diff.Delta.Copied; + return this.status() == Diff.DELTA.COPIED; }; /** @@ -107,7 +107,7 @@ ConvenientPatch.prototype.isCopied = function() { * @return {Boolean} */ ConvenientPatch.prototype.isIgnored = function() { - return this.status() == Diff.Delta.Ignored; + return this.status() == Diff.DELTA.IGNORED; }; /** @@ -115,7 +115,7 @@ ConvenientPatch.prototype.isIgnored = function() { * @return {Boolean} */ ConvenientPatch.prototype.isUntracked = function() { - return this.status() == Diff.Delta.Untracked; + return this.status() == Diff.DELTA.UNTRACKED; }; /** @@ -123,7 +123,7 @@ ConvenientPatch.prototype.isUntracked = function() { * @return {Boolean} */ ConvenientPatch.prototype.isTypeChange = function() { - return this.status() == Diff.Delta.TypeChange; + return this.status() == Diff.DELTA.TYPECHANGE; }; module.exports = ConvenientPatch; diff --git a/lib/diff.js b/lib/diff.js index 9804bc5c9..d46f24207 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -4,41 +4,6 @@ var ConvenientPatch = require("./convenient_patch"); var Diff = NodeGit.Diff; -/** - * Refer to vendor/libgit2/include/git2/diff.h for delta type definitions. - * - * @readonly - * @enum {Integer} - */ -Diff.Delta = { - /** 0 */ Unmodified: 0, - /** 1 */ Added: 1, - /** 2 */ Deleted: 2, - /** 3 */ Modified: 3, - /** 4 */ Renamed: 4, - /** 5 */ Copied: 5, - /** 6 */ Ignored: 6, - /** 7 */ Untracked: 7, - /** 8 */ TypeChange: 8 -}; - -/** - * Refer to vendor/libgit2/include/git2/diff.h for line origin type definitions. - * - * @readOnly - * @enum {String} - */ -Diff.LineOrigin = { - /** " " */ Context: 32, - /** "+" */ Addition: 43, - /** "-" */ Deletion: 45, - /** "\n" */ AddEofNl: 13, - /** "" */ DelEofNl: 0, - /** "F" */ FileHdr: 106, - /** "H" */ HunkHdr: 110, - /** "B" */ Binary: 102 -}; - /** * Retrieve patches in this difflist * diff --git a/lib/object.js b/lib/object.js index 7037cac0d..2ae11b3c2 100644 --- a/lib/object.js +++ b/lib/object.js @@ -2,25 +2,12 @@ var NodeGit = require("../"); var Obj = NodeGit.Object; -Obj.Type = { - Any: -2, /**< Obj can be any of the following */ - Bad: -1, /**< Obj is invalid. */ - Ext1: 0, /**< Reserved for future use. */ - Commit: 1, /**< A commit object. */ - Tree: 2, /**< A tree (directory listing) object. */ - Blob: 3, /**< A file revision object. */ - Tag: 4, /**< An annotated tag object. */ - Ext2: 5, /**< Reserved for future use. */ - OffsetDelta: 6, /**< A delta, base is given by an offset. */ - OidDelta: 7 /**< A delta, base is given by object id. */ -}; - /** * Is this object a commit? * @return {Boolean} */ Obj.prototype.isCommit = function() { - return this.type() == Obj.Type.Commit; + return this.type() == Obj.TYPE.COMMIT; }; /** @@ -28,7 +15,7 @@ Obj.prototype.isCommit = function() { * @return {Boolean} */ Obj.prototype.isTree = function() { - return this.type() == Obj.Type.Tree; + return this.type() == Obj.TYPE.TREE; }; /** @@ -36,7 +23,7 @@ Obj.prototype.isTree = function() { * @return {Boolean} */ Obj.prototype.isBlob = function() { - return this.type() == Obj.Type.Blob; + return this.type() == Obj.TYPE.BLOB; }; /** @@ -44,7 +31,7 @@ Obj.prototype.isBlob = function() { * @return {Boolean} */ Obj.prototype.isTag = function() { - return this.type() == Obj.Type.Tag; + return this.type() == Obj.TYPE.TAG; }; module.exports = Obj; diff --git a/lib/refs.js b/lib/refs.js index c6775d58d..50f8d3f70 100644 --- a/lib/refs.js +++ b/lib/refs.js @@ -3,10 +3,12 @@ var NodeGit = require("../"); var Reference = NodeGit.Refs; var Branch = NodeGit.Branch; -Reference.Type = { - Oid: 1, - Symbolic: 2, - All: 3 +/** + * Returns true if this reference is valid + * @return {Boolean} + */ +Reference.prototype.isValid = function() { + return this.type() != Reference.TYPE.INVALID; }; /** @@ -14,7 +16,7 @@ Reference.Type = { * @return {Boolean} */ Reference.prototype.isConcrete = function() { - return this.type() == Reference.Type.Oid; + return this.type() == Reference.TYPE.OID; }; /** @@ -22,7 +24,7 @@ Reference.prototype.isConcrete = function() { * @return {Boolean} */ Reference.prototype.isSymbolic = function() { - return this.type() == Reference.Type.Symbolic; + return this.type() == Reference.TYPE.SYMBOLIC; }; /** diff --git a/lib/repository.js b/lib/repository.js index bd6a9c0bf..0ad711380 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -120,7 +120,7 @@ Repository.prototype.getReference = function(name, callback) { var repository = this; return Reference.lookup(this, name).then(function(reference) { - if (reference.type() == Reference.Type.Symbolic) { + if (reference.isSymbolic()) { return reference.resolve(function (error, reference) { reference.repo = repository; @@ -148,13 +148,13 @@ Repository.getReferences = function(repo, type, refNamesOnly, callback) { refList.forEach(function(refName) { refFilterPromises.push(Reference.lookup(repo, refName) .then(function(ref) { - if (type == Reference.Type.All || ref.type() == type) { + if (type == Reference.TYPE.ALL || ref.type() == type) { if (refNamesOnly) { filteredRefs.push(refName); return; } - if (ref.type() == Reference.Type.Symbolic) { + if (ref.isSymbolic()) { return ref.resolve().then(function(resolvedRef) { resolvedRef.repo = repo; diff --git a/lib/revwalk.js b/lib/revwalk.js index 80c9fddb5..cf4875bc4 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -5,16 +5,6 @@ var Revwalk = NodeGit.Revwalk; var oldSorting = Revwalk.prototype.sorting; -/** - * Refer to vendor/libNodeGit2/include/NodeGit2/revwalk.h for sort definitions. - */ -Revwalk.Sort = { - None: 0, - Topological: 1, - Time: 2, - Reverse: 4 -}; - /** * Set the sort order for the revwalk. This function takes variable arguments * like `revwalk.sorting(NodeGit.RevWalk.Topological, NodeGit.RevWalk.Reverse).` diff --git a/lib/tree.js b/lib/tree.js index c034429bc..03a897fdf 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -4,15 +4,6 @@ var Treebuilder = git.Treebuilder; var Diff = git.Diff; var events = require("events"); -var oldEntryByIndex = Tree.prototype.entryByIndex; -// Backwards compatibility. -Object.defineProperties(Tree.prototype, { - "size": { - value: Tree.prototype.entrycount, - enumerable: false - } -}); - /** * Diff two trees * @param {Tree} tree to diff against @@ -35,9 +26,8 @@ Tree.prototype.diff = function(tree, callback) { * @param {Number} i * @return {TreeEntry} */ - Tree.prototype.entryByIndex = function(i) { - var entry = oldEntryByIndex.call(this, i); + var entry = this._entryByIndex(i); entry.parent = this; return entry; }; @@ -80,11 +70,14 @@ Tree.prototype.getEntry = function(path, callback) { * @return {[TreeEntry]} an array of TreeEntrys */ Tree.prototype.entries = function() { - var size = this.entrycount(); + var size = this.entryCount(); var result = []; + var temp = []; for (var i = 0; i < size; i++) { - result.push(this.entryByIndex(i)); + var ent = this.entryByIndex(i) + temp.push(i + " " + ent.filename() + " " + ent.attr()); + result.push(ent); } return result; @@ -119,8 +112,8 @@ Tree.prototype.walk = function(blobsOnly) { if (error) { return event.emit("error", error); } - - tree.entries().forEach(function (entry) { + var entries = tree.entries(); + entries.forEach(function (entry, entryIndex) { if (!blobsOnly || entry.isFile()) { event.emit("entry", entry); entries.push(entry); diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 0b2e9fa98..0d926c4db 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -4,28 +4,13 @@ var NodeGit = require("../"); var Tree = NodeGit.Tree; var TreeEntry = NodeGit.TreeEntry; -/** - * Refer to vendor/libgit2/include/git2/types.h for filemode definitions. - * - * @readonly - * @enum {Integer} - */ -TreeEntry.FileMode = { - /** 0000000 */ New: 0, - /** 0040000 */ Tree: 16384, - /** 0100644 */ Blob: 33188, - /** 0100755 */ Executable: 33261, - /** 0120000 */ Link: 40960, - /** 0160000 */ Commit: 57344 -}; - /** * Is this TreeEntry a blob? (i.e., a file) * @return {Boolean} */ TreeEntry.prototype.isFile = function() { - return this.attr() === TreeEntry.FileMode.Blob || - this.attr() === TreeEntry.FileMode.Executable; + return this.attr() === TreeEntry.FILEMODE.BLOB || + this.attr() === TreeEntry.FILEMODE.EXECUTABLE; }; /** @@ -33,7 +18,7 @@ TreeEntry.prototype.isFile = function() { * @return {Boolean} */ TreeEntry.prototype.isTree = function() { - return this.attr() === TreeEntry.FileMode.Tree; + return this.attr() === TreeEntry.FILEMODE.TREE; }; /** diff --git a/test/tests/blob.js b/test/tests/blob.js index 3370fadd2..06856cc03 100644 --- a/test/tests/blob.js +++ b/test/tests/blob.js @@ -6,7 +6,7 @@ describe("Blob", function() { var oid = "111dd657329797f6165f52f5085f61ac976dcf04"; var Repository = require("../../lib/repository"); - var FileMode = require("../../lib/tree_entry").FileMode; + var FileMode = require("../../lib/tree_entry").FILEMODE; before(function() { var test = this; @@ -34,6 +34,6 @@ describe("Blob", function() { }); it("can determine if a blob is not a binary", function() { - assert.equal(this.blob.filemode(), FileMode.Blob); + assert.equal(this.blob.filemode(), FileMode.BLOB); }); }); diff --git a/test/tests/commit.js b/test/tests/commit.js index 61b847cd8..bbc177b0a 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -197,27 +197,35 @@ describe("Commit", function() { }); }); - it("can retrieve and walk a commit tree", function(done) { + it("can retrieve and walk a commit tree", function() { var commitTreeEntryCount = 0; var expectedCommitTreeEntryCount = 198; - this.commit.getTree().then(function(tree) { - var treeWalker = tree.walk(); + return this.commit.getTree().then(function(tree) { + return new Promise(function(resolve, fail) { - treeWalker.on("entry", function(entry) { - commitTreeEntryCount++; - }); + var treeWalker = tree.walk(); - treeWalker.on("error", function() { - assert.ok(false); - }); + treeWalker.on("entry", function(entry) { + commitTreeEntryCount++; + }); - treeWalker.on("end", function(entries) { - assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount); - done(); - }); + treeWalker.on("error", function(error) { + fail(error); + }); - treeWalker.start(); + treeWalker.on("end", function(entries) { + try { + assert.equal(commitTreeEntryCount, expectedCommitTreeEntryCount); + resolve(); + } + catch (e) { + fail(e); + } + }); + + treeWalker.start(); + }); }); }); diff --git a/test/tests/diff.js b/test/tests/diff.js index eff7a4252..23800e6ff 100644 --- a/test/tests/diff.js +++ b/test/tests/diff.js @@ -26,7 +26,7 @@ describe("Diff", function() { it("can walk a DiffList", function() { var patch = this.diff[0].patches()[0]; - + assert.equal(patch.oldFile().path(), "README.md"); assert.equal(patch.newFile().path(), "README.md"); assert.equal(patch.size(), 1); @@ -36,21 +36,21 @@ describe("Diff", function() { assert.equal(hunk.size(), 5); var lines = hunk.lines(); - assert.equal(lines[0].origin(), Diff.LineOrigin.Context); - assert.equal(lines[1].origin(), Diff.LineOrigin.Context); - assert.equal(lines[2].origin(), Diff.LineOrigin.Context); + assert.equal(lines[0].origin(), Diff.LINE.CONTEXT); + assert.equal(lines[1].origin(), Diff.LINE.CONTEXT); + assert.equal(lines[2].origin(), Diff.LINE.CONTEXT); var oldContent = "\n__Before submitting a pull request, please ensure " + "both unit tests and lint checks pass.__\n"; assert.equal(lines[2].content(), oldContent); - assert.equal(lines[3].origin(), Diff.LineOrigin.Deletion); + assert.equal(lines[3].origin(), Diff.LINE.DELETION); assert.equal(lines[4].contentLen(), 90); var newContent = "__Before submitting a pull request, please ensure " + "both that you've added unit tests to cover your shiny new code, " + "and that all unit tests and lint checks pass.__\n"; assert.equal(lines[3].content(), newContent); - assert.equal(lines[4].origin(), Diff.LineOrigin.Addition); + assert.equal(lines[4].origin(), Diff.LINE.ADDITION); assert.equal(lines[3].contentLen(), 162); }); }); diff --git a/test/tests/odb.js b/test/tests/odb.js index 1e882f5c2..2c24c2b3a 100644 --- a/test/tests/odb.js +++ b/test/tests/odb.js @@ -28,14 +28,14 @@ describe("Odb", function() { var oid = Oid.fromString("32789a79e71fbc9e04d3eff7425e1771eb595150"); return this.odb.read(oid).then(function (object) { - assert.equal(object.type(), Obj.Type.Commit); + assert.equal(object.type(), Obj.TYPE.COMMIT); }); }); it("can read objects directly from the odb using a string", function() { return this.odb.read("32789a79e71fbc9e04d3eff7425e1771eb595150") .then(function (object) { - assert.equal(object.type(), Obj.Type.Commit); + assert.equal(object.type(), Obj.TYPE.COMMIT); }); }); @@ -43,12 +43,12 @@ describe("Odb", function() { var obj = "test data"; var odb = this.odb; - return odb.write(obj, obj.length, Obj.Type.Blob).then(function(oid) { + return odb.write(obj, obj.length, Obj.TYPE.BLOB).then(function(oid) { assert.ok(oid instanceof Oid); return odb.read(oid); }).then(function(object) { - assert.equal(object.type(), Obj.Type.Blob); + assert.equal(object.type(), Obj.TYPE.BLOB); assert.equal(object.toString(), obj); assert.equal(object.size(), obj.length); }); diff --git a/test/tests/tag.js b/test/tests/tag.js index c3e81caae..7a8ba14d5 100644 --- a/test/tests/tag.js +++ b/test/tests/tag.js @@ -16,7 +16,7 @@ describe("Tag", function() { function testTag(tag) { assert.equal(tag.name(), tagName); - assert.equal(tag.targetType(), Obj.Type.Commit); + assert.equal(tag.targetType(), Obj.TYPE.COMMIT); assert.equal(tag.message(), tagMessage); var target = tag.target(); From 56849eb94f218809610fc6c4f5a8cc380c1ed310 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 20 Nov 2014 18:51:40 -0700 Subject: [PATCH 3/7] remove one more manual enum --- lib/attr.js | 8 -------- lib/status.js | 5 +++++ lib/tree.js | 6 +----- test/tests/attr.js | 7 ++++--- 4 files changed, 10 insertions(+), 16 deletions(-) create mode 100644 lib/status.js diff --git a/lib/attr.js b/lib/attr.js index fe41d68a1..f84ddaa29 100644 --- a/lib/attr.js +++ b/lib/attr.js @@ -2,12 +2,4 @@ var NodeGit = require("../"); var Attr = NodeGit.Attr; -Attr.Check = { - FILE_THEN_INDEX: 0, - INDEX_THEN_FILE: 1, - INDEX_ONLY: 2, - - NO_SYSTEM: 1 << 2 -}; - module.exports = Attr; diff --git a/lib/status.js b/lib/status.js new file mode 100644 index 000000000..a6f930a13 --- /dev/null +++ b/lib/status.js @@ -0,0 +1,5 @@ +var NodeGit = require("../"); + +var Status = NodeGit.Status; + +module.exports = Status; diff --git a/lib/tree.js b/lib/tree.js index 03a897fdf..9abb4662d 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -73,11 +73,8 @@ Tree.prototype.entries = function() { var size = this.entryCount(); var result = []; - var temp = []; for (var i = 0; i < size; i++) { - var ent = this.entryByIndex(i) - temp.push(i + " " + ent.filename() + " " + ent.attr()); - result.push(ent); + result.push(this.entryByIndex(i)); } return result; @@ -100,7 +97,6 @@ Tree.prototype.walk = function(blobsOnly) { var self = this; var event = new events.EventEmitter(); - var entries = []; var total = 1; diff --git a/test/tests/attr.js b/test/tests/attr.js index f847812ec..c8ad44a6f 100644 --- a/test/tests/attr.js +++ b/test/tests/attr.js @@ -6,6 +6,7 @@ describe("Attr", function() { var Repository = require("../../lib/repository"); var Attr = require("../../lib/attr"); + var Status = require("../../lib/status"); before(function() { var test = this; @@ -25,8 +26,8 @@ describe("Attr", function() { Attr.cacheFlush(this.repository); }); - it("can lookup the value of a git attribute", function() { - var flags = Attr.Check.NO_SYSTEM; - Attr.get(this.repository, flags, ".gitattributes", "test"); + it.only("can lookup the value of a git attribute", function() { + var flags = Status.SHOW.INDEX_AND_WORKDIR; + return Attr.get(this.repository, flags, ".gitattributes", "test"); }); }); From 04d2e01e95468db4fb79a503aa7d603c7625ecbd Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 20 Nov 2014 19:00:36 -0700 Subject: [PATCH 4/7] rename Refs to Reference --- example/add-and-commit.js | 2 +- example/general.js | 2 +- example/remove-and-commit.js | 2 +- generate/descriptor.json | 3 +-- lib/nodegit.js | 3 ++- lib/{refs.js => reference.js} | 2 +- lib/repository.js | 2 +- test/tests/attr.js | 2 +- test/tests/commit.js | 2 +- test/tests/refs.js | 18 +++++++++--------- 10 files changed, 19 insertions(+), 19 deletions(-) rename lib/{refs.js => reference.js} (96%) diff --git a/example/add-and-commit.js b/example/add-and-commit.js index b640ddb03..f88f913cc 100644 --- a/example/add-and-commit.js +++ b/example/add-and-commit.js @@ -39,7 +39,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) }) .then(function(oidResult) { oid = oidResult; - return nodegit.Refs.nameToId(repo, 'HEAD'); + return nodegit.Reference.nameToId(repo, 'HEAD'); }) .then(function(head) { return repo.getCommit(head); diff --git a/example/general.js b/example/general.js index 973085dce..70039b8f2 100644 --- a/example/general.js +++ b/example/general.js @@ -294,7 +294,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) // references such as branches, tags and remote references (everything in // the .git/refs directory). - return repo.getReferenceNames(nodegit.Refs.Type.All); + return repo.getReferenceNames(nodegit.Reference.Type.All); }).then(function(referenceNames) { var promises = []; diff --git a/example/remove-and-commit.js b/example/remove-and-commit.js index c5ec94d7e..0bbf8273b 100644 --- a/example/remove-and-commit.js +++ b/example/remove-and-commit.js @@ -27,7 +27,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) return _index.writeTree(); }).then(function(oid) { _oid = oid; - return nodegit.Refs.nameToId(_repository, "HEAD"); + return nodegit.Reference.nameToId(_repository, "HEAD"); }).then(function(head) { return _repository.getCommit(head); }).then(function(parent) { diff --git a/generate/descriptor.json b/generate/descriptor.json index 30cee7850..6b18e20d4 100644 --- a/generate/descriptor.json +++ b/generate/descriptor.json @@ -71,7 +71,7 @@ } }, "ref": { - "owner": "Refs", + "owner": "Reference", "JsName": "TYPE" }, "sort": { @@ -1002,7 +1002,6 @@ }, "reference": { "cppClassName": "GitRefs", - "jsClassName": "Refs", "functions": { "git_reference__alloc": { "ignore": true diff --git a/lib/nodegit.js b/lib/nodegit.js index cff01781b..856f229e0 100644 --- a/lib/nodegit.js +++ b/lib/nodegit.js @@ -55,12 +55,13 @@ require("./odb"); require("./odb_object"); require("./oid"); require("./patch"); -require("./refs"); +require("./reference"); require("./remote"); require("./revwalk"); require("./repository"); require("./revwalk"); require("./signature"); +require("./status"); require("./tree"); require("./tree_entry"); diff --git a/lib/refs.js b/lib/reference.js similarity index 96% rename from lib/refs.js rename to lib/reference.js index 50f8d3f70..eab158eb0 100644 --- a/lib/refs.js +++ b/lib/reference.js @@ -1,6 +1,6 @@ var NodeGit = require("../"); -var Reference = NodeGit.Refs; +var Reference = NodeGit.Reference; var Branch = NodeGit.Branch; /** diff --git a/lib/repository.js b/lib/repository.js index 0ad711380..f42314724 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -3,7 +3,7 @@ var normalizeOid = require("./util/normalize_oid"); var Blob = require("./blob"); var Tree = require("./tree"); var Tag = require("./tag"); -var Reference = require("./refs"); +var Reference = require("./reference"); var Revwalk = require("./revwalk"); var Commit = require("./commit"); var Remote = require("./remote"); diff --git a/test/tests/attr.js b/test/tests/attr.js index c8ad44a6f..c5b7690f1 100644 --- a/test/tests/attr.js +++ b/test/tests/attr.js @@ -26,7 +26,7 @@ describe("Attr", function() { Attr.cacheFlush(this.repository); }); - it.only("can lookup the value of a git attribute", function() { + it("can lookup the value of a git attribute", function() { var flags = Status.SHOW.INDEX_AND_WORKDIR; return Attr.get(this.repository, flags, ".gitattributes", "test"); }); diff --git a/test/tests/commit.js b/test/tests/commit.js index bbc177b0a..233896a66 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -82,7 +82,7 @@ describe("Commit", function() { }) .then(function(oidResult) { treeOid = oidResult; - return NodeGit.Refs.nameToId(repo, "HEAD"); + return NodeGit.Reference.nameToId(repo, "HEAD"); }) .then(function(head) { return repo.getCommit(head); diff --git a/test/tests/refs.js b/test/tests/refs.js index f0a22e029..674797724 100644 --- a/test/tests/refs.js +++ b/test/tests/refs.js @@ -7,11 +7,11 @@ var exec = promisify(function(command, opts, callback) { return require("child_process").exec(command, opts, callback); }); -describe("Refs", function() { +describe("Reference", function() { var reposPath = path.resolve("test/repos/workdir/.git"); var Repository = require("../../lib/repository"); - var Refs = require("../../lib/refs"); + var Reference = require("../../lib/reference"); before(function() { var test = this; @@ -25,27 +25,27 @@ describe("Refs", function() { return repository.getReference("refs/heads/master"); }) - .then(function(refs) { - test.refs = refs; + .then(function(reference) { + test.reference = reference; }); }); it("can look up a reference", function() { - assert.ok(this.refs instanceof Refs); + assert.ok(this.reference instanceof Reference); }); it("can determine if the reference is symbolic", function() { - assert.equal(this.refs.isSymbolic(), false); + assert.equal(this.reference.isSymbolic(), false); }); it("will return undefined looking up the symbolic target if not symbolic", function() { - var refs = this.refs; - assert(refs.symbolicTarget() === undefined); + var reference = this.reference; + assert(reference.symbolicTarget() === undefined); }); it("can look up the HEAD sha", function() { - return Refs.nameToId(this.repository, "HEAD").then(function(oid) { + return Reference.nameToId(this.repository, "HEAD").then(function(oid) { var sha = oid.allocfmt(); assert.equal(sha, "32789a79e71fbc9e04d3eff7425e1771eb595150"); }); From 010d68a2b9849b5e907d1c7aff7ce1e50b0d4784 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 20 Nov 2014 19:08:15 -0700 Subject: [PATCH 5/7] fix examples --- example/general.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/general.js b/example/general.js index 70039b8f2..94d60dd6e 100644 --- a/example/general.js +++ b/example/general.js @@ -73,7 +73,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) // it gives you direct access to the key/value properties of Git. Here // we'll write a new blob object that just contains a simple string. // Notice that we have to specify the object type. - return odb.write("test data", "test data".length, nodegit.Object.Type.Blob); + return odb.write("test data", "test data".length, nodegit.Object.TYPE.BLOB); }).then(function(oid) { // Now that we've written the object, we can check out what SHA1 was // generated when the object was written to our database. @@ -294,7 +294,7 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) // references such as branches, tags and remote references (everything in // the .git/refs directory). - return repo.getReferenceNames(nodegit.Reference.Type.All); + return repo.getReferenceNames(nodegit.Reference.TYPE.ALL); }).then(function(referenceNames) { var promises = []; From 4854df81b14c53dfece61afba5138df4242dbf01 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 20 Nov 2014 19:18:53 -0700 Subject: [PATCH 6/7] add "removeString" to enums to clean up js names --- generate/descriptor.json | 33 +-------------------------------- generate/setup.js | 1 + 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/generate/descriptor.json b/generate/descriptor.json index 6b18e20d4..a209e0d14 100644 --- a/generate/descriptor.json +++ b/generate/descriptor.json @@ -37,38 +37,7 @@ "otype": { "JsName": "TYPE", "owner": "Object", - "values": { - "GIT_OBJ_ANY": { - "JsName": "ANY" - }, - "GIT_OBJ_BAD": { - "JsName": "BAD" - }, - "GIT_OBJ__EXT1": { - "JsName": "EXT1" - }, - "GIT_OBJ_COMMIT": { - "JsName": "COMMIT" - }, - "GIT_OBJ_TREE": { - "JsName": "TREE" - }, - "GIT_OBJ_BLOB": { - "JsName": "BLOB" - }, - "GIT_OBJ_TAG": { - "JsName": "TAG" - }, - "GIT_OBJ__EXT2": { - "JsName": "EXT2" - }, - "GIT_OBJ_OFS_DELTA": { - "JsName": "OFS_DELTA" - }, - "GIT_OBJ_REF_DELTA": { - "JsName": "REF_DELTA" - } - } + "removeString": "OBJ_" }, "ref": { "owner": "Reference", diff --git a/generate/setup.js b/generate/setup.js index f8ce34cea..c92d44b13 100644 --- a/generate/setup.js +++ b/generate/setup.js @@ -187,6 +187,7 @@ _(enums).forEach(function(enumerable) { enumerable.values.forEach(function(value) { value.JsName = value.name .replace(/^GIT_/, "") + .replace(override.removeString || "", "") .replace(new RegExp("^" + enumerable.owner.toUpperCase()), "") .replace(/^_/, "") .replace(new RegExp("^" + enumerable.JsName), "") From ee85ba1b0d19e2337d624a4a3150e63f5f9f55e7 Mon Sep 17 00:00:00 2001 From: Maximiliano Korp Date: Thu, 20 Nov 2014 19:27:24 -0700 Subject: [PATCH 7/7] the last (seemingly) of legacy compat --- generate/descriptor.json | 5 +---- lib/index.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/generate/descriptor.json b/generate/descriptor.json index a209e0d14..4deba4d1d 100644 --- a/generate/descriptor.json +++ b/generate/descriptor.json @@ -590,7 +590,7 @@ "ignore": true }, "git_index_entrycount": { - "jsFunctionName": "size" + "jsFunctionName": "entryCount" }, "git_index_find": { "ignore": true @@ -611,9 +611,6 @@ "git_index_remove_all": { "ignore": true }, - "git_index_remove_bypath": { - "jsFunctionName": "removeByPath" - }, "git_index_update_all": { "ignore": true }, diff --git a/lib/index.js b/lib/index.js index e49597512..a5ed5b344 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,7 +7,7 @@ var Index = NodeGit.Index; * @return {[IndexEntry]} an array of IndexEntrys */ Index.prototype.entries = function() { - var size = this.size(); + var size = this.entryCount(); var result = []; for (var i = 0; i < size; i++) {