Skip to content

Commit

Permalink
#3 Fix: Use child_process spawn instead of exec for git commands prod…
Browse files Browse the repository at this point in the history
…ucing large output (more than 200Kb)
  • Loading branch information
mhutchie committed Feb 18, 2019
1 parent e63ae36 commit 964f226
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.3.2 - 2019-02-18
* Fixes an issue when viewing some large graphs of more than 500 commits.
* Significantly reduced package size.

## 1.3.1 - 2019-02-17
* View the Visual Studio Code Diff of a file change in a commit, by clicking on the file in the commit details view.
* All git commands are run asynchronously to improve responsiveness.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "git-graph",
"displayName": "Git Graph",
"version": "1.3.1",
"version": "1.3.2",
"publisher": "mhutchie",
"author": {
"name": "Michael Hutchison",
Expand Down
31 changes: 27 additions & 4 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,16 @@ export class DataSource {

public async getCommitFile(commitHash: string, filePath: string) {
return new Promise<string>((resolve) => {
cp.exec('git show "' + commitHash + '":"' + filePath + '"', { cwd: this.workspaceDir }, (err, stdout) => {
resolve(!err ? stdout : '');
let args = ['show', commitHash + ':' + filePath], stdout = '', err = false;
const cmd = cp.spawn('git', args, { cwd: this.workspaceDir });
cmd.stdout.on('data', (d) => { stdout += d; });
cmd.on('error', () => {
resolve('');
err = true;
});
cmd.on('exit', (code) => {
if (err) return;
resolve(code === 0 ? stdout : '');
});
});
}
Expand Down Expand Up @@ -248,8 +256,23 @@ export class DataSource {

private async getGitLog(branch: string, num: number, showRemoteBranches: boolean) {
return new Promise<GitCommit[]>((resolve) => {
cp.exec('git log ' + (branch !== '' ? escapeRefName(branch) : '--branches' + (showRemoteBranches ? ' --remotes' : '')) + ' --max-count=' + num + ' --format="' + gitLogFormat + '"', { cwd: this.workspaceDir }, (err, stdout) => {
if (!err) {
let args = ['log', '--max-count=' + num, '--format=' + gitLogFormat], stdout = '', err = false;
if (branch !== '') {
args.push(escapeRefName(branch));
} else {
args.push('--branches');
if (showRemoteBranches) args.push('--remotes');
}

const cmd = cp.spawn('git', args, { cwd: this.workspaceDir });
cmd.stdout.on('data', (d) => { stdout += d; });
cmd.on('error', () => {
resolve([]);
err = true;
});
cmd.on('exit', (code) => {
if (err) return;
if (code === 0) {
let lines = stdout.split(eolRegex);
let gitCommits: GitCommit[] = [];
for (let i = 0; i < lines.length - 1; i++) {
Expand Down

0 comments on commit 964f226

Please sign in to comment.