Browse Source

Adds toPsuedoCommits to status for reuse

main
Eric Amodio 4 years ago
parent
commit
4397a74fb3
3 changed files with 90 additions and 85 deletions
  1. +75
    -4
      src/git/models/status.ts
  2. +14
    -80
      src/views/nodes/fileHistoryNode.ts
  3. +1
    -1
      src/views/nodes/lineHistoryNode.ts

+ 75
- 4
src/git/models/status.ts View File

@ -1,10 +1,12 @@
'use strict';
import { Uri } from 'vscode';
import { GlyphChars } from '../../constants';
import { memoize, Strings } from '../../system';
import { GitUri } from '../gitUri';
import { GitBranch, GitTrackingState } from './branch';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitFile, GitFileStatus } from './file';
import { GitUri } from '../gitUri';
import { GitCommitType, GitLogCommit, GitRevision } from './models';
import { memoize, Strings } from '../../system';
export interface ComputedWorkingTreeGitStatus {
staged: number;
@ -224,12 +226,16 @@ export class GitStatusFile implements GitFile {
public readonly originalFileName?: string,
) {}
get edited() {
return this.workingTreeStatus != null;
}
get status(): GitFileStatus {
return this.indexStatus ?? this.workingTreeStatus ?? '?';
}
get staged() {
return this.indexStatus !== undefined;
return this.indexStatus != null;
}
@memoize()
@ -253,6 +259,71 @@ export class GitStatusFile implements GitFile {
return GitFile.getStatusText(this.status);
}
async toPsuedoCommits(): Promise<GitLogCommit[]> {
if (this.workingTreeStatus == null && this.indexStatus == null) return [];
const commits = [];
const user = await Container.git.getCurrentUser(this.repoPath);
if (this.workingTreeStatus != null && this.indexStatus != null) {
commits.push(
new GitLogCommit(
GitCommitType.LogFile,
this.repoPath,
GitRevision.uncommitted,
'You',
user?.email ?? undefined,
new Date(),
new Date(),
'',
this.fileName,
[this],
this.status,
this.originalFileName,
GitRevision.uncommittedStaged,
this.originalFileName ?? this.fileName,
),
new GitLogCommit(
GitCommitType.LogFile,
this.repoPath,
GitRevision.uncommittedStaged,
'You',
user != null ? user.email : undefined,
new Date(),
new Date(),
'',
this.fileName,
[this],
this.status,
this.originalFileName,
'HEAD',
this.originalFileName ?? this.fileName,
),
);
} else {
commits.push(
new GitLogCommit(
GitCommitType.LogFile,
this.repoPath,
this.workingTreeStatus != null ? GitRevision.uncommitted : GitRevision.uncommittedStaged,
'You',
user?.email ?? undefined,
new Date(),
new Date(),
'',
this.fileName,
[this],
this.status,
this.originalFileName,
'HEAD',
this.originalFileName ?? this.fileName,
),
);
}
return commits;
}
with(changes: {
indexStatus?: GitFileStatus | null;
workTreeStatus?: GitFileStatus | null;

+ 14
- 80
src/views/nodes/fileHistoryNode.ts View File

@ -2,9 +2,7 @@
import { Disposable, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Container } from '../../container';
import {
GitCommitType,
GitLog,
GitLogCommit,
GitRevision,
RepositoryChange,
RepositoryChangeEvent,
@ -41,89 +39,25 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
async getChildren(): Promise<ViewNode[]> {
const children: ViewNode[] = [];
if (this.uri.sha === undefined) {
if (this.uri.sha == null) {
const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath);
if (status?.workingTreeStatus !== undefined || status?.indexStatus !== undefined) {
const user = await Container.git.getCurrentUser(this.uri.repoPath!);
if (status.workingTreeStatus !== undefined && status.indexStatus !== undefined) {
let commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
GitRevision.uncommitted,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
GitRevision.uncommittedStaged,
status.originalFileName ?? status.fileName,
);
children.push(
new CommitFileNode(this.view, this, status, commit, {
displayAsCommit: true,
inFileHistory: true,
}),
);
commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
GitRevision.uncommittedStaged,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
'HEAD',
status.originalFileName ?? status.fileName,
);
children.push(
new CommitFileNode(this.view, this, status, commit, {
displayAsCommit: true,
inFileHistory: true,
}),
);
} else {
const commit = new GitLogCommit(
GitCommitType.LogFile,
this.uri.repoPath!,
status.workingTreeStatus !== undefined
? GitRevision.uncommitted
: GitRevision.uncommittedStaged,
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
status.status,
status.originalFileName,
'HEAD',
status.originalFileName ?? status.fileName,
);
children.push(
new CommitFileNode(this.view, this, status, commit, {
displayAsCommit: true,
inFileHistory: true,
}),
);
}
const commits = await status?.toPsuedoCommits();
if (commits?.length) {
children.push(
...commits.map(
commit =>
new CommitFileNode(this.view, this, status!, commit, {
displayAsCommit: true,
inFileHistory: true,
}),
),
);
}
}
const log = await this.getLog();
if (log !== undefined) {
if (log != null) {
children.push(
...insertDateMarkers(
Iterables.map(

+ 1
- 1
src/views/nodes/lineHistoryNode.ts View File

@ -52,7 +52,7 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
let selection = this.selection;
if (this.uri.sha === undefined) {
if (this.uri.sha == null) {
// Check for any uncommitted changes in the range
const blame = this._editorContents
? await Container.git.getBlameForRangeContents(this.uri, selection, this._editorContents)

Loading…
Cancel
Save