| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,9 @@ | |||
| 1 | + - make normalizeOid do more work. | ||
| 2 | + - extract out more partials | ||
| 3 | + | ||
| 1 | 4 | - audit all ** methods so that all finds go through the repo in js land so that the .repo pointer is set. | |
| 2 | 5 | - rename files remove .h | |
| 3 | - - Cleanup diff api | ||
| 4 | - - free everything malloc'd | ||
| 6 | + - free everything malloc'd, or figure out the right coding conventions for copying. | ||
| 5 | 7 | - codegen documentation | |
| 6 | - - extract out more partials | ||
| 7 | 8 | - audit return types for things that should be copied | |
| 8 | 9 | - array handling | |
| 9 | - - make normalizeOid do more work. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,7 +127,7 @@ Commit.prototype.getParents = function(callback) { | |||
| 127 | 127 | * | |
| 128 | 128 | * @param {Commit~parentsDiffTreesCallback} callback | |
| 129 | 129 | */ | |
| 130 | - Commit.prototype.diff = function(callback) { | ||
| 130 | + Commit.prototype.getDiff = function(callback) { | ||
| 131 | 131 | /** | |
| 132 | 132 | * @callback Commit~parentsDiffTreesCallback Callback executed on diff trees retrieval. | |
| 133 | 133 | * @param {GitError|null} error An Error or null if successful. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + function ConvenientHunk(raw, i) { | ||
| 2 | + this.raw = raw; | ||
| 3 | + this.i = i; | ||
| 4 | + } | ||
| 5 | + | ||
| 6 | + ConvenientHunk.prototype.size = function() { | ||
| 7 | + return this.raw.hunk(this.i).lines; | ||
| 8 | + }; | ||
| 9 | + | ||
| 10 | + ConvenientHunk.prototype.lines = function() { | ||
| 11 | + var result = []; | ||
| 12 | + for (var i = 0; i < this.size(); i++) | ||
| 13 | + result.push(this.raw.line(this.i, i)); | ||
| 14 | + return result; | ||
| 15 | + }; | ||
| 16 | + | ||
| 17 | + exports.ConvenientHunk = ConvenientHunk; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,68 @@ | |||
| 1 | + var git = require('../'), | ||
| 2 | + DiffList = git.DiffList, | ||
| 3 | + ConvenientHunk = require('./convenient_hunk').ConvenientHunk; | ||
| 4 | + | ||
| 5 | + function ConvenientPatch(raw) { | ||
| 6 | + this.raw = raw; | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + ConvenientPatch.prototype.oldFile = function() { | ||
| 10 | + return this.raw.delta.oldFile(); | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + ConvenientPatch.prototype.newFile = function() { | ||
| 14 | + return this.raw.delta.newFile(); | ||
| 15 | + }; | ||
| 16 | + | ||
| 17 | + ConvenientPatch.prototype.size = function() { | ||
| 18 | + return this.raw.patch.size(); | ||
| 19 | + }; | ||
| 20 | + | ||
| 21 | + ConvenientPatch.prototype.status = function() { | ||
| 22 | + return this.raw.delta.status(); | ||
| 23 | + }; | ||
| 24 | + | ||
| 25 | + ConvenientPatch.prototype.isUnmodified = function() { | ||
| 26 | + return this.status() == DiffList.Delta.Unmodified; | ||
| 27 | + }; | ||
| 28 | + | ||
| 29 | + ConvenientPatch.prototype.isAdded = function() { | ||
| 30 | + return this.status() == DiffList.Delta.Added; | ||
| 31 | + }; | ||
| 32 | + | ||
| 33 | + ConvenientPatch.prototype.isDeleted = function() { | ||
| 34 | + return this.status() == DiffList.Delta.Deleted; | ||
| 35 | + }; | ||
| 36 | + | ||
| 37 | + ConvenientPatch.prototype.isModified = function() { | ||
| 38 | + return this.status() == DiffList.Delta.Modified; | ||
| 39 | + }; | ||
| 40 | + | ||
| 41 | + ConvenientPatch.prototype.isRenamed = function() { | ||
| 42 | + return this.status() == DiffList.Delta.Renamed; | ||
| 43 | + }; | ||
| 44 | + | ||
| 45 | + ConvenientPatch.prototype.isCopied = function() { | ||
| 46 | + return this.status() == DiffList.Delta.Copied; | ||
| 47 | + }; | ||
| 48 | + | ||
| 49 | + ConvenientPatch.prototype.isIgnored = function() { | ||
| 50 | + return this.status() == DiffList.Delta.Ignored; | ||
| 51 | + }; | ||
| 52 | + | ||
| 53 | + ConvenientPatch.prototype.isUntracked = function() { | ||
| 54 | + return this.status() == DiffList.Delta.Untracked; | ||
| 55 | + }; | ||
| 56 | + | ||
| 57 | + ConvenientPatch.prototype.isTypeChange = function() { | ||
| 58 | + return this.status() == DiffList.Delta.TypeChange; | ||
| 59 | + }; | ||
| 60 | + | ||
| 61 | + ConvenientPatch.prototype.hunks = function() { | ||
| 62 | + var result = []; | ||
| 63 | + for (var i = 0; i < this.size(); i++) | ||
| 64 | + result.push(new ConvenientHunk(this.raw.patch, i)); | ||
| 65 | + return result; | ||
| 66 | + }; | ||
| 67 | + | ||
| 68 | + exports.ConvenientPatch = ConvenientPatch; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,10 @@ | |||
| 1 | 1 | var git = require('../'), | |
| 2 | 2 | DiffList = git.DiffList, | |
| 3 | + ConvenientPatch = require('./convenient_patch').ConvenientPatch, | ||
| 3 | 4 | events = require('events'); | |
| 4 | 5 | ||
| 6 | + console.log(ConvenientPatch); | ||
| 7 | + | ||
| 5 | 8 | /** | |
| 6 | 9 | * Refer to vendor/libgit2/include/git2/diff.h for delta type definitions. | |
| 7 | 10 | * | |
@@ -37,7 +40,6 @@ DiffList.LineOrigin = { | |||
| 37 | 40 | /** 'B' */ Binary: 102 | |
| 38 | 41 | }; | |
| 39 | 42 | ||
| 40 | - | ||
| 41 | 43 | /** | |
| 42 | 44 | * Retrieve patches | |
| 43 | 45 | * | |
@@ -47,7 +49,7 @@ DiffList.prototype.patches = function() { | |||
| 47 | 49 | var size = this.size(); | |
| 48 | 50 | result = []; | |
| 49 | 51 | for (var i = 0; i < size; i++) { | |
| 50 | - result.push(this.patch(i)); | ||
| 52 | + result.push(new ConvenientPatch(this.patch(i))); | ||
| 51 | 53 | } | |
| 52 | 54 | return result; | |
| 53 | 55 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,65 +5,59 @@ var git = require('../'), | |||
| 5 | 5 | var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; | |
| 6 | 6 | ||
| 7 | 7 | exports.message = function(test) { | |
| 8 | - test.expect(3); | ||
| 8 | + test.expect(2); | ||
| 9 | 9 | git.Repo.open('../.git', function(error, repository) { | |
| 10 | 10 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 11 | 11 | var message = commit.message(); | |
| 12 | 12 | test.equals(error, null, 'There should be no error'); | |
| 13 | - test.notEqual(message, null, 'Message should not be null'); | ||
| 14 | 13 | test.equals(message, 'Update README.md', 'Message should match expected value'); | |
| 15 | 14 | test.done(); | |
| 16 | 15 | }); | |
| 17 | 16 | }); | |
| 18 | 17 | }; | |
| 19 | 18 | ||
| 20 | 19 | exports.sha = function(test) { | |
| 21 | - test.expect(3); | ||
| 20 | + test.expect(2); | ||
| 22 | 21 | git.Repo.open('../.git', function(error, repository) { | |
| 23 | 22 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 24 | 23 | var sha = commit.sha(); | |
| 25 | 24 | test.equals(error, null, 'There should be no error'); | |
| 26 | - test.notEqual(sha, null, 'SHA should not be null'); | ||
| 27 | 25 | test.equals(sha, historyCountKnownSHA, 'SHA should match expected value'); | |
| 28 | 26 | test.done(); | |
| 29 | 27 | }); | |
| 30 | 28 | }); | |
| 31 | 29 | }; | |
| 32 | 30 | ||
| 33 | 31 | exports.time = function(test) { | |
| 34 | - test.expect(3); | ||
| 32 | + test.expect(2); | ||
| 35 | 33 | git.Repo.open('../.git', function(error, repository) { | |
| 36 | 34 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 37 | 35 | var time = commit.timeMs(); | |
| 38 | 36 | test.equals(error, null, 'There should be no error'); | |
| 39 | - test.notEqual(time, null, 'Time should not be null'); | ||
| 40 | 37 | test.equals(time, 1362012884000, 'Time should match expected value'); | |
| 41 | 38 | test.done(); | |
| 42 | 39 | }); | |
| 43 | 40 | }); | |
| 44 | 41 | }; | |
| 45 | 42 | ||
| 46 | 43 | exports.date = function(test) { | |
| 47 | - test.expect(4); | ||
| 44 | + test.expect(2); | ||
| 48 | 45 | git.Repo.open('../.git', function(error, repository) { | |
| 49 | 46 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 50 | 47 | var date = commit.date(); | |
| 51 | 48 | test.equals(error, null, 'There should be no error'); | |
| 52 | - test.notEqual(date, null, 'Date should not be null'); | ||
| 53 | - test.equal(date instanceof Date, true, 'Date should be a date object'); | ||
| 54 | 49 | test.equals(date.getTime(), 1362012884000, 'Date should match expected value'); | |
| 55 | 50 | test.done(); | |
| 56 | 51 | }); | |
| 57 | 52 | }); | |
| 58 | 53 | }; | |
| 59 | 54 | ||
| 60 | 55 | exports.offset = function(test) { | |
| 61 | - test.expect(3); | ||
| 56 | + test.expect(2); | ||
| 62 | 57 | git.Repo.open('../.git', function(error, repository) { | |
| 63 | 58 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 64 | 59 | var offset = commit.offset(); | |
| 65 | 60 | test.equals(error, null, 'There should be no error'); | |
| 66 | - test.notEqual(offset, null, 'Offset should not be null'); | ||
| 67 | 61 | test.equals(offset, 780, 'Offset should match expected value'); | |
| 68 | 62 | test.done(); | |
| 69 | 63 | }); | |
@@ -226,14 +220,14 @@ exports.tree = function(test) { | |||
| 226 | 220 | }; | |
| 227 | 221 | ||
| 228 | 222 | /** | |
| 229 | - * Test that parentsDiffTrees works as expected. | ||
| 223 | + * Test that getDiff works as expected. | ||
| 230 | 224 | */ | |
| 231 | - exports.parentsDiffTrees = function(test) { | ||
| 225 | + exports.getDiff = function(test) { | ||
| 232 | 226 | test.expect(1); | |
| 233 | 227 | git.Repo.open('../.git', function(error, repository) { | |
| 234 | 228 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 235 | - commit.diff(function(error, parentsDiffTrees) { | ||
| 236 | - test.equals(parentsDiffTrees.length, 1, 'Should be one item in parents diff trees'); | ||
| 229 | + commit.getDiff(function(error, diff) { | ||
| 230 | + test.equals(diff.length, 1, 'Should be one item in parents diff trees'); | ||
| 237 | 231 | test.done(); | |
| 238 | 232 | }); | |
| 239 | 233 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,40 +13,35 @@ exports.walkingDiffs = function(test) { | |||
| 13 | 13 | test.expect(16); | |
| 14 | 14 | git.Repo.open('../.git', function(error, repository) { | |
| 15 | 15 | repository.getCommit(historyCountKnownSHA, function(error, commit) { | |
| 16 | - commit.getParents(function(error, parents) { | ||
| 17 | - parents[0].getTree(function(error, parentTree) { | ||
| 18 | - commit.getTree(function(error, commitTree) { | ||
| 19 | - parentTree.diff(commitTree, function(error, diffList) { | ||
| 20 | - test.equal(null, error, 'Should not error'); | ||
| 21 | - | ||
| 22 | - diffList.patches().forEach(function(patch) { | ||
| 23 | - var delta = patch.delta, patch = patch.patch; | ||
| 24 | - test.equal(null, error, 'Should not error'); | ||
| 25 | - test.equal(delta.oldFile().path(), 'README.md', 'Old file path should match expected'); | ||
| 26 | - test.equal(delta.newFile().path(), 'README.md', 'New file path should match expected'); | ||
| 27 | - test.equal(patch.size(), 1, 'Content array should be of known length'); | ||
| 28 | - var hunk = patch.hunk(0); | ||
| 29 | - | ||
| 30 | - test.equal(hunk.lines, 5, 'Content array should be of known length'); | ||
| 31 | - test.equal(delta.status(), git.DiffList.Delta.Modified, 'Status should be known type'); | ||
| 32 | - | ||
| 33 | - test.equal(patch.line(0, 0).lineOrigin, git.DiffList.LineOrigin.Context, 'First content item should be context'); | ||
| 34 | - test.equal(patch.line(0, 1).lineOrigin, git.DiffList.LineOrigin.Context, 'Second content item should be context'); | ||
| 35 | - test.equal(patch.line(0, 2).lineOrigin, git.DiffList.LineOrigin.Context, 'Third content item should be context'); | ||
| 36 | - | ||
| 37 | - var oldContent = '__Before submitting a pull request, please ensure both unit tests and lint checks pass.__\n'; | ||
| 38 | - test.equal(patch.line(0, 3).content, oldContent, 'Old content should match known value'); | ||
| 39 | - test.equal(patch.line(0, 3).lineOrigin, git.DiffList.LineOrigin.Deletion, 'Fourth content item should be deletion'); | ||
| 40 | - test.equal(patch.line(0, 3).length, 90, 'Fourth content length should match known value'); | ||
| 41 | - | ||
| 42 | - 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'; | ||
| 43 | - test.equal(patch.line(0, 4).content, newContent, 'New content should match known value'); | ||
| 44 | - test.equal(patch.line(0, 4).lineOrigin, git.DiffList.LineOrigin.Addition, 'Fifth content item should be addition'); | ||
| 45 | - test.equal(patch.line(0, 4).length, 162, 'Fifth content length should match known value'); | ||
| 46 | - test.done(); | ||
| 47 | - }); | ||
| 48 | - }); | ||
| 49 | - }); | ||
| 16 | + commit.getDiff(function(error, diffList) { | ||
| 17 | + test.equal(null, error, 'Should not error'); | ||
| 18 | + | ||
| 19 | + diffList[0].patches().forEach(function(patch) { | ||
| 20 | + test.equal(null, error, 'Should not error'); | ||
| 21 | + | ||
| 22 | + test.equal(patch.oldFile().path(), 'README.md', 'Old file path should match expected'); | ||
| 23 | + test.equal(patch.newFile().path(), 'README.md', 'New file path should match expected'); | ||
| 24 | + test.equal(patch.size(), 1, 'Content array should be of known length'); | ||
| 25 | + test.ok(patch.isModified(), 'Status should be known type'); | ||
| 26 | + | ||
| 27 | + var hunk = patch.hunks()[0]; | ||
| 28 | + test.equal(hunk.size(), 5, 'Content array should be of known length'); | ||
| 29 | + var lines = hunk.lines(); | ||
| 30 | + | ||
| 31 | + test.equal(lines[0].lineOrigin, git.DiffList.LineOrigin.Context, 'First content item should be context'); | ||
| 32 | + test.equal(lines[1].lineOrigin, git.DiffList.LineOrigin.Context, 'Second content item should be context'); | ||
| 33 | + test.equal(lines[2].lineOrigin, git.DiffList.LineOrigin.Context, 'Third content item should be context'); | ||
| 34 | + | ||
| 35 | + var oldContent = '__Before submitting a pull request, please ensure both unit tests and lint checks pass.__\n'; | ||
| 36 | + test.equal(lines[3].content, oldContent, 'Old content should match known value'); | ||
| 37 | + test.equal(lines[3].lineOrigin, git.DiffList.LineOrigin.Deletion, 'Fourth content item should be deletion'); | ||
| 38 | + test.equal(lines[3].length, 90, 'Fourth content length should match known value'); | ||
| 39 | + | ||
| 40 | + 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'; | ||
| 41 | + test.equal(lines[4].content, newContent, 'New content should match known value'); | ||
| 42 | + test.equal(lines[4].lineOrigin, git.DiffList.LineOrigin.Addition, 'Fifth content item should be addition'); | ||
| 43 | + test.equal(lines[4].length, 162, 'Fifth content length should match known value'); | ||
| 44 | + test.done(); | ||
| 50 | 45 | }); | |
| 51 | 46 | }); | |
| 52 | 47 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments