Skip to content

Commit 964f226

Browse files
committed
#3 Fix: Use child_process spawn instead of exec for git commands producing large output (more than 200Kb)
1 parent e63ae36 commit 964f226

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 1.3.2 - 2019-02-18
4+
* Fixes an issue when viewing some large graphs of more than 500 commits.
5+
* Significantly reduced package size.
6+
37
## 1.3.1 - 2019-02-17
48
* View the Visual Studio Code Diff of a file change in a commit, by clicking on the file in the commit details view.
59
* All git commands are run asynchronously to improve responsiveness.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "git-graph",
33
"displayName": "Git Graph",
4-
"version": "1.3.1",
4+
"version": "1.3.2",
55
"publisher": "mhutchie",
66
"author": {
77
"name": "Michael Hutchison",

src/dataSource.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,16 @@ export class DataSource {
170170

171171
public async getCommitFile(commitHash: string, filePath: string) {
172172
return new Promise<string>((resolve) => {
173-
cp.exec('git show "' + commitHash + '":"' + filePath + '"', { cwd: this.workspaceDir }, (err, stdout) => {
174-
resolve(!err ? stdout : '');
173+
let args = ['show', commitHash + ':' + filePath], stdout = '', err = false;
174+
const cmd = cp.spawn('git', args, { cwd: this.workspaceDir });
175+
cmd.stdout.on('data', (d) => { stdout += d; });
176+
cmd.on('error', () => {
177+
resolve('');
178+
err = true;
179+
});
180+
cmd.on('exit', (code) => {
181+
if (err) return;
182+
resolve(code === 0 ? stdout : '');
175183
});
176184
});
177185
}
@@ -248,8 +256,23 @@ export class DataSource {
248256

249257
private async getGitLog(branch: string, num: number, showRemoteBranches: boolean) {
250258
return new Promise<GitCommit[]>((resolve) => {
251-
cp.exec('git log ' + (branch !== '' ? escapeRefName(branch) : '--branches' + (showRemoteBranches ? ' --remotes' : '')) + ' --max-count=' + num + ' --format="' + gitLogFormat + '"', { cwd: this.workspaceDir }, (err, stdout) => {
252-
if (!err) {
259+
let args = ['log', '--max-count=' + num, '--format=' + gitLogFormat], stdout = '', err = false;
260+
if (branch !== '') {
261+
args.push(escapeRefName(branch));
262+
} else {
263+
args.push('--branches');
264+
if (showRemoteBranches) args.push('--remotes');
265+
}
266+
267+
const cmd = cp.spawn('git', args, { cwd: this.workspaceDir });
268+
cmd.stdout.on('data', (d) => { stdout += d; });
269+
cmd.on('error', () => {
270+
resolve([]);
271+
err = true;
272+
});
273+
cmd.on('exit', (code) => {
274+
if (err) return;
275+
if (code === 0) {
253276
let lines = stdout.split(eolRegex);
254277
let gitCommits: GitCommit[] = [];
255278
for (let i = 0; i < lines.length - 1; i++) {

0 commit comments

Comments
 (0)