Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
fix: parse large files from git
Browse files Browse the repository at this point in the history
- increase maxBuffer to 100MB
- call toString() on Buffer
- remove redundant Buffer.from for Buffer
  • Loading branch information
amtrack committed Jul 28, 2020
1 parent f7ed2af commit 85ec228
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Diff.prototype.getMetadataContainers = function(opts) {
// retrieve file using git
var parts = file.index[0].split('..');
if (!file.new) {
fileFrom.contents = Buffer.from(self.git.show(parts[0]));
fileFrom.contents = self.git.show(parts[0]);
}
if (!file.deleted) {
fileTo.contents = Buffer.from(self.git.show(parts[1]));
fileTo.contents = self.git.show(parts[1]);
}
}
containerFrom.add(fileFrom, []);
Expand Down Expand Up @@ -86,10 +86,10 @@ Diff.stream = function(opts) {
// retrieve file using git
var parts = file.index[0].split('..');
if (!file.new) {
fileFrom.contents = Buffer.from(git.show(parts[0]));
fileFrom.contents = git.show(parts[0]);
}
if (!file.deleted) {
fileTo.contents = Buffer.from(git.show(parts[1]));
fileTo.contents = git.show(parts[1]);
}
}
containerFrom.add(fileFrom, []);
Expand Down
3 changes: 2 additions & 1 deletion lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Git = module.exports = function(basedir) {
Git.prototype.show = function(revision) {
var self = this;
return child.spawnSync('git', ['show', revision], {
cwd: self.basedir
cwd: self.basedir,
maxBuffer: 1024 * 1024 * 100 // 100 MB
}).stdout;
};
6 changes: 3 additions & 3 deletions lib/metadata-file-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ MetadataFileContainer.prototype.parse = function() {
if (!self.contents || self.contents.length === 0) {
return self;
}
var parsed = new xmldoc.XmlDocument(self.contents);
var parsed = new xmldoc.XmlDocument(self.contents.toString());
var type = self.getMetadataType();
var objectName = self.getComponent().fullName;
if (type.childXmlNames) {
Expand Down Expand Up @@ -190,7 +190,7 @@ MetadataFileContainer.prototype.contentsWithoutChilds = function(includedChildCo

var childComponents = this.getMetadataType().childXmlNames;
if (childComponents) {
var parsed = new xmldoc.XmlDocument(this.contents);
var parsed = new xmldoc.XmlDocument(this.contents.toString());
var parentMetadata = '<' + parsed.name + ' xmlns="http://soap.sforce.com/2006/04/metadata">';
var tagIncludedChildNames = includedChildComponents ?
includedChildComponents.map(function(child) {
Expand Down Expand Up @@ -255,7 +255,7 @@ MetadataFileContainer.prototype.toString = function() {
var groupedComponents = self.getGroupedAndSortedComponents();
_.keys(groupedComponents).sort(MetadataUtils.compareMetadataTypeNames).forEach(function(metadataType) {
groupedComponents[metadataType].forEach(function(cmp) {
lines.push(cmp.contents);
lines.push(cmp.contents.toString());
});
});
lines.push("</" + type.xmlName + ">");
Expand Down
2 changes: 1 addition & 1 deletion test-functional/lib/force-dev-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Cli {
expect(spawnRet.stdout.toString()).to.include('Running Validation of directory');
return spawnRet;
} else {
let out = JSON.parse(spawnRet.stdout);
let out = JSON.parse(spawnRet.stdout.toString());
expect(out.status, JSON.stringify(out.result.details)).to.equal(fail ? 1 : 0);
return out;
}
Expand Down
2 changes: 1 addition & 1 deletion test-functional/lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Repository {
cwd: this._cwd
});
if (result.status !== 0) {
throw result.stdout + '\n' + result.stderr;
throw result.stdout.toString() + '\n' + result.stderr.toString();
}
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions test-integration/changeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe("force-dev-tool changeset create ...", function() {
cwd: gitDir
}
);
assert.deepEqual(gitCloneCmd.status, 0, gitCloneCmd.stderr);
assert.deepEqual(gitCloneCmd.status, 0, gitCloneCmd.stderr.toString());
var gitCheckoutCmd = child.spawnSync("git", ["checkout", test.branch], {
cwd: gitDir
});
assert.deepEqual(gitCheckoutCmd.status, 0, gitCheckoutCmd.stderr);
assert.deepEqual(gitCheckoutCmd.status, 0, gitCheckoutCmd.stderr.toString());
var changesetArgs = [fdt, "changeset", "create", "test"];
[].push.apply(changesetArgs, test.patterns);
var changesetCreateCmd = child.spawnSync(
Expand All @@ -45,7 +45,7 @@ describe("force-dev-tool changeset create ...", function() {
assert.deepEqual(
changesetCreateCmd.status,
0,
changesetCreateCmd.stdout
changesetCreateCmd.stdout.toString()
);
var diffDirsCmd = child.spawnSync(
"diff", [
Expand All @@ -57,7 +57,7 @@ describe("force-dev-tool changeset create ...", function() {
cwd: gitDir
}
);
assert.deepEqual(diffDirsCmd.status, 0, diffDirsCmd.stdout);
assert.deepEqual(diffDirsCmd.status, 0, diffDirsCmd.stdout.toString());
});
});
});
8 changes: 4 additions & 4 deletions test-integration/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('force-dev-tool deploy', function() {
this.timeout(1000 * 60 * 10);
this.slow(1000 * 60 * 5);
var deployCmd = child.spawnSync("node", [fdt, 'deploy', '-c', '-f', path.resolve(__dirname, '..', 'test', 'data', 'unpackaged', 'layout-with-umlauts.zip')]);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr.toString());
assert(/Running Validation of zip file/.test(deployCmd.stdout.toString()));
assert(/Visit https/.test(deployCmd.stdout.toString()));
});
Expand All @@ -27,7 +27,7 @@ describe('force-dev-tool deploy', function() {
return done(err);
}
var deployCmd = child.spawnSync("node", [fdt, 'deploy', '-c', '-d', unzipDir]);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr.toString());
assert(/Running Validation of directory/.test(deployCmd.stdout.toString()));
assert(/Visit https/.test(deployCmd.stdout.toString()));
done();
Expand All @@ -37,15 +37,15 @@ describe('force-dev-tool deploy', function() {
this.timeout(1000 * 60 * 10);
this.slow(1000 * 60 * 5);
var deployCmd = child.spawnSync("node", [fdt, 'deploy', '-c', '-t', '-d', path.resolve(__dirname, '..', 'test', 'data', 'metadata', 'visualforce')]);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr.toString());
assert(/Running Validation with test execution of directory/.test(deployCmd.stdout.toString()));
assert(/Visit https/.test(deployCmd.stdout.toString()));
});
it('should simulate deploying an apex class with a test class', function() {
this.timeout(1000 * 60 * 10);
this.slow(1000 * 60 * 5);
var deployCmd = child.spawnSync("node", [fdt, 'deploy', '-c', '-t', '-d', path.resolve(__dirname, '..', 'test', 'data', 'unpackaged', 'apex')]);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr);
assert.deepEqual(deployCmd.status, 0, deployCmd.stderr.toString());
assert(/Running Validation with test execution of directory/.test(deployCmd.stdout.toString()));
assert(/Visit https/.test(deployCmd.stdout.toString()));
});
Expand Down
6 changes: 3 additions & 3 deletions test-integration/fetch-package-retrieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ describe('force-dev-tool fetch package retrieve', function() {
var fetchCmd = child.spawnSync("node", [fdt, 'fetch'], {
cwd: tmpobj.name
});
assert.deepEqual(fetchCmd.status, 0, fetchCmd.stderr);
assert.deepEqual(fetchCmd.status, 0, fetchCmd.stderr.toString());
assert(/Fetching from remote env/.test(fetchCmd.stdout.toString()));
assert(/Fetching remotes finished/.test(fetchCmd.stdout.toString()));

var packageCmd = child.spawnSync("node", [fdt, 'package'], {
cwd: tmpobj.name
});
assert.deepEqual(packageCmd.status, 0, packageCmd.stderr);
assert.deepEqual(packageCmd.status, 0, packageCmd.stderr.toString());
assert(/Created src.*package\.xml/.test(packageCmd.stdout.toString()));

var retrieveCmd = child.spawnSync("node", [fdt, 'retrieve'], {
cwd: tmpobj.name
});
assert.deepEqual(retrieveCmd.status, 0, retrieveCmd.stderr);
assert.deepEqual(retrieveCmd.status, 0, retrieveCmd.stderr.toString());
assert(/Retrieving from remote env to directory src/.test(retrieveCmd.stdout.toString()));
assert(/Succeeded/.test(retrieveCmd.stdout.toString()));
});
Expand Down
2 changes: 1 addition & 1 deletion test-integration/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('force-dev-tool login', function() {
var loginCmd = child.spawnSync("node", [fdt, 'login'], {
cwd: tmpobj.name
});
assert.deepEqual(loginCmd.status, 0, loginCmd.stderr);
assert.deepEqual(loginCmd.status, 0, loginCmd.stderr.toString());
assert(/Logged in successfully/.test(loginCmd.stdout.toString()));
assert(/https/.test(loginCmd.stdout.toString()));
});
Expand Down
2 changes: 1 addition & 1 deletion test/metadata-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('MetadataComponent', function() {
fileName: path.join('pages', 'Test.page'),
contents: 'hello'
});
assert.deepEqual(metadataComponentWithContents.contents, 'hello');
assert.deepEqual(metadataComponentWithContents.contents.toString(), 'hello');
});
it('should return a metadata component for an ApexPage', function() {
var metadataComponent = new MetadataComponent('ApexPage/Test');
Expand Down
6 changes: 3 additions & 3 deletions test/metadata-file-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('MetadataFileContainer', function() {
});
assert.deepEqual(mfc.components.length, 1);
assert.deepEqual(
mfc.components[0].contents,
mfc.components[0].contents.toString(),
TestObject.fields.textField1
);
});
Expand All @@ -55,7 +55,7 @@ describe('MetadataFileContainer', function() {
});
assert.deepEqual(mfc.components.length, 1);
assert.deepEqual(
mfc.components[0].contents,
mfc.components[0].contents.toString(),
TestProfile.classAccesses.classAccess1
);
});
Expand All @@ -66,7 +66,7 @@ describe('MetadataFileContainer', function() {
});
assert.deepEqual(mfc.components.length, 1);
assert.deepEqual(
mfc.components[0].contents,
mfc.components[0].contents.toString(),
TestProfile.fieldPermissions.fieldPermission1
);
});
Expand Down

0 comments on commit 85ec228

Please sign in to comment.