From 1a1540a202edb2615fd429816c9e5d44d0f3d557 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 4 Feb 2022 00:30:24 -0500 Subject: [PATCH] Passes the container to commits Moves formatting globals to the container --- src/annotations/gutterChangesAnnotationProvider.ts | 1 + src/container.ts | 53 +++++++++++++++++++++ src/env/node/git/localGitProvider.ts | 13 +++-- src/git/gitProviderService.ts | 20 ++++---- src/git/models/branch.ts | 14 +----- src/git/models/commit.ts | 55 ++++++++-------------- src/git/models/pullRequest.ts | 17 ++----- src/git/models/reflog.ts | 6 +-- src/git/models/status.ts | 6 ++- src/git/models/tag.ts | 15 ++---- src/git/parsers/blameParser.ts | 12 ++++- src/git/parsers/logParser.ts | 15 +++++- src/git/parsers/stashParser.ts | 13 +++-- src/premium/github/githubGitProvider.ts | 5 ++ src/views/nodes/branchNode.ts | 4 +- src/views/nodes/fileHistoryNode.ts | 4 +- src/views/nodes/lineHistoryNode.ts | 2 +- src/views/nodes/statusFilesNode.ts | 2 +- src/views/nodes/tagNode.ts | 13 +++-- src/webviews/webviewBase.ts | 1 + 20 files changed, 160 insertions(+), 111 deletions(-) diff --git a/src/annotations/gutterChangesAnnotationProvider.ts b/src/annotations/gutterChangesAnnotationProvider.ts index 6059398..9db0ecc 100644 --- a/src/annotations/gutterChangesAnnotationProvider.ts +++ b/src/annotations/gutterChangesAnnotationProvider.ts @@ -104,6 +104,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase { + this.BranchDateFormatting.dateFormat = configuration.get('defaultDateFormat'); + this.BranchDateFormatting.dateStyle = configuration.get('defaultDateStyle'); + }, + }; + + readonly CommitDateFormatting = { + dateFormat: null as string | null, + dateSource: DateSource.Authored, + dateStyle: DateStyle.Relative, + + reset: () => { + this.CommitDateFormatting.dateFormat = configuration.get('defaultDateFormat'); + this.CommitDateFormatting.dateSource = configuration.get('defaultDateSource'); + this.CommitDateFormatting.dateStyle = configuration.get('defaultDateStyle'); + }, + }; + + readonly CommitShaFormatting = { + length: 7, + + reset: () => { + // Don't allow shas to be shortened to less than 5 characters + this.CommitShaFormatting.length = Math.max(5, configuration.get('advanced.abbreviatedShaLength')); + }, + }; + + readonly PullRequestDateFormatting = { + dateFormat: null as string | null, + dateStyle: DateStyle.Relative, + + reset: () => { + this.PullRequestDateFormatting.dateFormat = configuration.get('defaultDateFormat'); + this.PullRequestDateFormatting.dateStyle = configuration.get('defaultDateStyle'); + }, + }; + + readonly TagDateFormatting = { + dateFormat: null as string | null, + dateStyle: DateStyle.Relative, + + reset: () => { + this.TagDateFormatting.dateFormat = configuration.get('defaultDateFormat'); + this.TagDateFormatting.dateStyle = configuration.get('defaultDateStyle'); + }, + }; + private _configsAffectedByMode: string[] | undefined; private _applyModeConfigurationTransformBound: | ((e: ConfigurationChangeEvent) => ConfigurationChangeEvent) diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 7a01908..8d8e17d 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -953,7 +953,7 @@ export class LocalGitProvider implements GitProvider, Disposable { args: this.container.config.advanced.blame.customArguments, ignoreWhitespace: this.container.config.blame.ignoreWhitespace, }); - const blame = GitBlameParser.parse(data, root, await this.getCurrentUser(root)); + const blame = GitBlameParser.parse(this.container, data, root, await this.getCurrentUser(root)); return blame; } catch (ex) { // Trap and cache expected blame errors @@ -1034,7 +1034,7 @@ export class LocalGitProvider implements GitProvider, Disposable { correlationKey: `:${key}`, ignoreWhitespace: this.container.config.blame.ignoreWhitespace, }); - const blame = GitBlameParser.parse(data, root, await this.getCurrentUser(root)); + const blame = GitBlameParser.parse(this.container, data, root, await this.getCurrentUser(root)); return blame; } catch (ex) { // Trap and cache expected blame errors @@ -1094,7 +1094,7 @@ export class LocalGitProvider implements GitProvider, Disposable { startLine: lineToBlame, endLine: lineToBlame, }); - const blame = GitBlameParser.parse(data, root, await this.getCurrentUser(root)); + const blame = GitBlameParser.parse(this.container, data, root, await this.getCurrentUser(root)); if (blame == null) return undefined; return { @@ -1145,7 +1145,7 @@ export class LocalGitProvider implements GitProvider, Disposable { startLine: lineToBlame, endLine: lineToBlame, }); - const blame = GitBlameParser.parse(data, root, await this.getCurrentUser(root)); + const blame = GitBlameParser.parse(this.container, data, root, await this.getCurrentUser(root)); if (blame == null) return undefined; return { @@ -1946,6 +1946,7 @@ export class LocalGitProvider implements GitProvider, Disposable { // } const log = GitLogParser.parse( + this.container, data, LogType.Log, repoPath, @@ -2166,6 +2167,7 @@ export class LocalGitProvider implements GitProvider, Disposable { useShow: useShow, }); const log = GitLogParser.parse( + this.container, data, LogType.Log, repoPath, @@ -2418,6 +2420,7 @@ export class LocalGitProvider implements GitProvider, Disposable { endLine: range == null ? undefined : range.end.line + 1, }); const log = GitLogParser.parse( + this.container, data, // If this is the log of a folder, parse it as a normal log rather than a file log isFolderGlob(file) ? LogType.Log : LogType.LogFile, @@ -3109,7 +3112,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const data = await this.git.stash__list(repoPath, { similarityThreshold: this.container.config.advanced.similarityThreshold, }); - stash = GitStashParser.parse(data, repoPath); + stash = GitStashParser.parse(this.container, data, repoPath); if (this.useCaching) { this._stashesCache.set(repoPath, stash ?? null); diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 109f5fa..4a5c6ae 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -31,10 +31,7 @@ import { VisitedPathsTrie } from '../system/trie'; import { GitProvider, GitProviderDescriptor, GitProviderId, PagedResult, ScmRepository } from './gitProvider'; import { GitUri } from './gitUri'; import { - BranchDateFormatting, BranchSortOptions, - CommitDateFormatting, - CommitShaFormatting, GitBlame, GitBlameLine, GitBlameLines, @@ -61,7 +58,6 @@ import { GitTreeEntry, GitUser, PullRequest, - PullRequestDateFormatting, PullRequestState, Repository, RepositoryChange, @@ -147,10 +143,10 @@ export class GitProviderService implements Disposable { }), ); - BranchDateFormatting.reset(); - CommitDateFormatting.reset(); - CommitShaFormatting.reset(); - PullRequestDateFormatting.reset(); + this.container.BranchDateFormatting.reset(); + this.container.CommitDateFormatting.reset(); + this.container.CommitShaFormatting.reset(); + this.container.PullRequestDateFormatting.reset(); this.updateContext(); } @@ -174,13 +170,13 @@ export class GitProviderService implements Disposable { configuration.changed(e, 'defaultDateSource') || configuration.changed(e, 'defaultDateStyle') ) { - BranchDateFormatting.reset(); - CommitDateFormatting.reset(); - PullRequestDateFormatting.reset(); + this.container.BranchDateFormatting.reset(); + this.container.CommitDateFormatting.reset(); + this.container.PullRequestDateFormatting.reset(); } if (configuration.changed(e, 'advanced.abbreviatedShaLength')) { - CommitShaFormatting.reset(); + this.container.CommitShaFormatting.reset(); } if (configuration.changed(e, 'views.contributors.showAllBranches')) { diff --git a/src/git/models/branch.ts b/src/git/models/branch.ts index c3cf610..0ae84b8 100644 --- a/src/git/models/branch.ts +++ b/src/git/models/branch.ts @@ -13,16 +13,6 @@ import { GitStatus } from './status'; const whitespaceRegex = /\s/; const detachedHEADRegex = /^(?=.*\bHEAD\b)?(?=.*\bdetached\b).*$/; -export const BranchDateFormatting = { - dateFormat: undefined! as string | null, - dateStyle: undefined! as DateStyle, - - reset: () => { - BranchDateFormatting.dateFormat = configuration.get('defaultDateFormat'); - BranchDateFormatting.dateStyle = configuration.get('defaultDateStyle'); - }, -}; - export interface GitTrackingState { ahead: number; behind: number; @@ -146,8 +136,8 @@ export class GitBranch implements GitBranchReference { } get formattedDate(): string { - return BranchDateFormatting.dateStyle === DateStyle.Absolute - ? this.formatDate(BranchDateFormatting.dateFormat) + return Container.instance.BranchDateFormatting.dateStyle === DateStyle.Absolute + ? this.formatDate(Container.instance.BranchDateFormatting.dateFormat) : this.formatDateFromNow(); } diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index 93fa437..fbd85c9 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -1,6 +1,6 @@ import { Uri } from 'vscode'; import { getAvatarUri } from '../../avatars'; -import { configuration, DateSource, DateStyle, GravatarDefaultStyle } from '../../configuration'; +import { DateSource, DateStyle, GravatarDefaultStyle } from '../../configuration'; import { GlyphChars } from '../../constants'; import { Container } from '../../container'; import { formatDate, fromNow } from '../../system/date'; @@ -15,27 +15,6 @@ import { GitReference, GitRevision, GitRevisionReference, GitStashReference } fr const stashNumberRegex = /stash@{(\d+)}/; -export const CommitDateFormatting = { - dateFormat: null as string | null, - dateSource: DateSource.Authored, - dateStyle: DateStyle.Relative, - - reset: () => { - CommitDateFormatting.dateFormat = configuration.get('defaultDateFormat'); - CommitDateFormatting.dateSource = configuration.get('defaultDateSource'); - CommitDateFormatting.dateStyle = configuration.get('defaultDateStyle'); - }, -}; - -export const CommitShaFormatting = { - length: 7, - - reset: () => { - // Don't allow shas to be shortened to less than 5 characters - CommitShaFormatting.length = Math.max(5, Container.instance.config.advanced.abbreviatedShaLength); - }, -}; - export class GitCommit implements GitRevisionReference { static is(commit: any): commit is GitCommit { return commit instanceof GitCommit; @@ -70,6 +49,7 @@ export class GitCommit implements GitRevisionReference { readonly number: string | undefined; constructor( + private readonly container: Container, public readonly repoPath: string, public readonly sha: string, public readonly author: GitCommitIdentity, @@ -84,7 +64,7 @@ export class GitCommit implements GitRevisionReference { ) { this.ref = this.sha; this.refType = stashName ? 'stash' : 'revision'; - this.shortSha = this.sha.substring(0, CommitShaFormatting.length); + this.shortSha = this.sha.substring(0, this.container.CommitShaFormatting.length); // Add an ellipsis to the summary if there is or might be more message if (message != null) { @@ -141,7 +121,9 @@ export class GitCommit implements GitRevisionReference { } get date(): Date { - return CommitDateFormatting.dateSource === DateSource.Committed ? this.committer.date : this.author.date; + return this.container.CommitDateFormatting.dateSource === DateSource.Committed + ? this.committer.date + : this.author.date; } private _file: GitFileChange | undefined; @@ -155,8 +137,8 @@ export class GitCommit implements GitRevisionReference { } get formattedDate(): string { - return CommitDateFormatting.dateStyle === DateStyle.Absolute - ? this.formatDate(CommitDateFormatting.dateFormat) + return this.container.CommitDateFormatting.dateStyle === DateStyle.Absolute + ? this.formatDate(this.container.CommitDateFormatting.dateFormat) : this.formatDateFromNow(); } @@ -202,10 +184,10 @@ export class GitCommit implements GitRevisionReference { if (this.isUncommitted || GitCommit.hasFullDetails(this)) return; const [commitResult, untrackedResult] = await Promise.allSettled([ - Container.instance.git.getCommit(this.repoPath, this.sha), + this.container.git.getCommit(this.repoPath, this.sha), // Check for any untracked files -- since git doesn't return them via `git stash list` :( // See https://stackoverflow.com/questions/12681529/ - this.stashName ? Container.instance.git.getCommit(this.repoPath, `${this.stashName}^3`) : undefined, + this.stashName ? this.container.git.getCommit(this.repoPath, `${this.stashName}^3`) : undefined, ]); if (commitResult.status !== 'fulfilled' || commitResult.value == null) return; @@ -285,18 +267,18 @@ export class GitCommit implements GitRevisionReference { if (this._files == null) return undefined; } - path = Container.instance.git.getRelativePath(path, this.repoPath); + path = this.container.git.getRelativePath(path, this.repoPath); return this._files.find(f => f.path === path); } formatDate(format?: string | null) { - return CommitDateFormatting.dateSource === DateSource.Committed + return this.container.CommitDateFormatting.dateSource === DateSource.Committed ? this.committer.formatDate(format) : this.author.formatDate(format); } formatDateFromNow(short?: boolean) { - return CommitDateFormatting.dateSource === DateSource.Committed + return this.container.CommitDateFormatting.dateSource === DateSource.Committed ? this.committer.fromNow(short) : this.author.fromNow(short); } @@ -377,10 +359,10 @@ export class GitCommit implements GitRevisionReference { async getAssociatedPullRequest(options?: { timeout?: number }): Promise { if (this._pullRequest == null) { async function getCore(this: GitCommit): Promise { - const remote = await Container.instance.git.getRichRemoteProvider(this.repoPath); + const remote = await this.container.git.getRichRemoteProvider(this.repoPath); if (remote?.provider == null) return undefined; - return Container.instance.git.getPullRequestForCommit(this.ref, remote, options); + return this.container.git.getPullRequestForCommit(this.ref, remote, options); } this._pullRequest = getCore.call(this); } @@ -393,7 +375,7 @@ export class GitCommit implements GitRevisionReference { } async getCommitForFile(file: string | GitFile): Promise { - const path = typeof file === 'string' ? Container.instance.git.getRelativePath(file, this.repoPath) : file.path; + const path = typeof file === 'string' ? this.container.git.getRelativePath(file, this.repoPath) : file.path; const foundFile = await this.findFile(path); if (foundFile == null) return undefined; @@ -413,7 +395,7 @@ export class GitCommit implements GitRevisionReference { @memoize() getGitUri(previous: boolean = false): GitUri { - const uri = this._file?.uri ?? Container.instance.git.getAbsoluteUri(this.repoPath, this.repoPath); + const uri = this._file?.uri ?? this.container.git.getAbsoluteUri(this.repoPath, this.repoPath); if (!previous) return new GitUri(uri, this); return new GitUri(this._file?.previousUri ?? uri, { @@ -425,7 +407,7 @@ export class GitCommit implements GitRevisionReference { @memoize((u, e, r) => `${u.toString()}|${e}|${r ?? ''}`) getPreviousLineDiffUris(uri: Uri, editorLine: number, ref: string | undefined) { return this.file?.path - ? Container.instance.git.getPreviousLineDiffUris(this.repoPath, uri, editorLine, ref) + ? this.container.git.getPreviousLineDiffUris(this.repoPath, uri, editorLine, ref) : Promise.resolve(undefined); } @@ -455,6 +437,7 @@ export class GitCommit implements GitRevisionReference { } return new GitCommit( + this.container, this.repoPath, changes.sha ?? this.sha, this.author, diff --git a/src/git/models/pullRequest.ts b/src/git/models/pullRequest.ts index 6ac0336..f8c42b1 100644 --- a/src/git/models/pullRequest.ts +++ b/src/git/models/pullRequest.ts @@ -1,20 +1,11 @@ import { ColorThemeKind, ThemeColor, ThemeIcon, window } from 'vscode'; -import { configuration, DateStyle } from '../../configuration'; +import { DateStyle } from '../../configuration'; import { Colors } from '../../constants'; +import { Container } from '../../container'; import { formatDate, fromNow } from '../../system/date'; import { memoize } from '../../system/decorators/memoize'; import { RemoteProviderReference } from './remoteProvider'; -export const PullRequestDateFormatting = { - dateFormat: undefined! as string | null, - dateStyle: undefined! as DateStyle, - - reset: () => { - PullRequestDateFormatting.dateFormat = configuration.get('defaultDateFormat'); - PullRequestDateFormatting.dateStyle = configuration.get('defaultDateStyle'); - }, -}; - export const enum PullRequestState { Open = 'Open', Closed = 'Closed', @@ -75,8 +66,8 @@ export class PullRequest { ) {} get formattedDate(): string { - return PullRequestDateFormatting.dateStyle === DateStyle.Absolute - ? this.formatDate(PullRequestDateFormatting.dateFormat) + return Container.instance.PullRequestDateFormatting.dateStyle === DateStyle.Absolute + ? this.formatDate(Container.instance.PullRequestDateFormatting.dateFormat) : this.formatDateFromNow(); } diff --git a/src/git/models/reflog.ts b/src/git/models/reflog.ts index eebe46e..e88ecee 100644 --- a/src/git/models/reflog.ts +++ b/src/git/models/reflog.ts @@ -1,7 +1,7 @@ import { DateStyle } from '../../config'; +import { Container } from '../../container'; import { formatDate, fromNow } from '../../system/date'; import { memoize } from '../../system/decorators/memoize'; -import { CommitDateFormatting } from './commit'; import { GitRevision } from './reference'; export interface GitReflog { @@ -38,8 +38,8 @@ export class GitReflogRecord { } get formattedDate(): string { - return CommitDateFormatting.dateStyle === DateStyle.Absolute - ? this.formatDate(CommitDateFormatting.dateFormat) + return Container.instance.CommitDateFormatting.dateStyle === DateStyle.Absolute + ? this.formatDate(Container.instance.CommitDateFormatting.dateFormat) : this.formatDateFromNow(); } diff --git a/src/git/models/status.ts b/src/git/models/status.ts index ee9622c..333d99c 100644 --- a/src/git/models/status.ts +++ b/src/git/models/status.ts @@ -431,7 +431,7 @@ export class GitStatusFile implements GitFile { return GitFile.getStatusText(this.status); } - getPseudoCommits(user: GitUser | undefined): GitCommit[] { + getPseudoCommits(container: Container, user: GitUser | undefined): GitCommit[] { const commits: GitCommit[] = []; const now = new Date(); @@ -439,6 +439,7 @@ export class GitStatusFile implements GitFile { if (this.conflictStatus != null) { commits.push( new GitCommit( + container, this.repoPath, GitRevision.uncommitted, new GitCommitIdentity('You', user?.email ?? undefined, now), @@ -469,6 +470,7 @@ export class GitStatusFile implements GitFile { commits.push( new GitCommit( + container, this.repoPath, GitRevision.uncommitted, new GitCommitIdentity('You', user?.email ?? undefined, now), @@ -487,6 +489,7 @@ export class GitStatusFile implements GitFile { [], ), new GitCommit( + container, this.repoPath, GitRevision.uncommittedStaged, new GitCommitIdentity('You', user?.email ?? undefined, older), @@ -502,6 +505,7 @@ export class GitStatusFile implements GitFile { } else { commits.push( new GitCommit( + container, this.repoPath, this.workingTreeStatus != null ? GitRevision.uncommitted : GitRevision.uncommittedStaged, new GitCommitIdentity('You', user?.email ?? undefined, now), diff --git a/src/git/models/tag.ts b/src/git/models/tag.ts index 8745820..e9bdba5 100644 --- a/src/git/models/tag.ts +++ b/src/git/models/tag.ts @@ -1,19 +1,10 @@ import { configuration, DateStyle, TagSorting } from '../../configuration'; +import { Container } from '../../container'; import { formatDate, fromNow } from '../../system/date'; import { memoize } from '../../system/decorators/memoize'; import { sortCompare } from '../../system/string'; import { GitReference, GitTagReference } from './reference'; -export const TagDateFormatting = { - dateFormat: undefined! as string | null, - dateStyle: undefined! as DateStyle, - - reset: () => { - TagDateFormatting.dateFormat = configuration.get('defaultDateFormat'); - TagDateFormatting.dateStyle = configuration.get('defaultDateStyle'); - }, -}; - export interface TagSortOptions { current?: boolean; orderBy?: TagSorting; @@ -56,8 +47,8 @@ export class GitTag implements GitTagReference { ) {} get formattedDate(): string { - return TagDateFormatting.dateStyle === DateStyle.Absolute - ? this.formatDate(TagDateFormatting.dateFormat) + return Container.instance.TagDateFormatting.dateStyle === DateStyle.Absolute + ? this.formatDate(Container.instance.TagDateFormatting.dateFormat) : this.formatDateFromNow(); } diff --git a/src/git/parsers/blameParser.ts b/src/git/parsers/blameParser.ts index 0d2b1a5..26344d4 100644 --- a/src/git/parsers/blameParser.ts +++ b/src/git/parsers/blameParser.ts @@ -1,3 +1,4 @@ +import type { Container } from '../../container'; import { debug } from '../../system/decorators/log'; import { getLines } from '../../system/string'; import { @@ -39,7 +40,12 @@ interface BlameEntry { export class GitBlameParser { @debug({ args: false, singleLine: true }) - static parse(data: string, repoPath: string, currentUser: GitUser | undefined): GitBlame | undefined { + static parse( + container: Container, + data: string, + repoPath: string, + currentUser: GitUser | undefined, + ): GitBlame | undefined { if (!data) return undefined; const authors = new Map(); @@ -153,7 +159,7 @@ export class GitBlameParser { entry.path = line.slice(key.length + 1); // Since the filename marks the end of a commit, parse the entry and clear it for the next - GitBlameParser.parseEntry(entry, repoPath, commits, authors, lines, currentUser); + GitBlameParser.parseEntry(container, entry, repoPath, commits, authors, lines, currentUser); entry = undefined; break; @@ -184,6 +190,7 @@ export class GitBlameParser { } private static parseEntry( + container: Container, entry: BlameEntry, repoPath: string, commits: Map, @@ -217,6 +224,7 @@ export class GitBlameParser { } commit = new GitCommit( + container, repoPath, entry.sha, new GitCommitIdentity(entry.author, entry.authorEmail, new Date((entry.authorDate as any) * 1000)), diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index 6c9b9f0..11d6ea8 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -1,4 +1,5 @@ import { Range } from 'vscode'; +import type { Container } from '../../container'; import { Arrays, debug } from '../../system'; import { normalizePath, relative } from '../../system/path'; import { getLines } from '../../system/string'; @@ -270,6 +271,7 @@ export class GitLogParser { @debug({ args: false }) static parse( + container: Container, data: string, type: LogType, repoPath: string | undefined, @@ -550,7 +552,16 @@ export class GitLogParser { truncationCount--; } - GitLogParser.parseEntry(entry, commit, type, repoPath, relativeFileName, commits, currentUser); + GitLogParser.parseEntry( + container, + entry, + commit, + type, + repoPath, + relativeFileName, + commits, + currentUser, + ); break; } @@ -570,6 +581,7 @@ export class GitLogParser { } private static parseEntry( + container: Container, entry: LogEntry, commit: GitCommit | undefined, type: LogType, @@ -608,6 +620,7 @@ export class GitLogParser { } commit = new GitCommit( + container, repoPath!, entry.sha!, new GitCommitIdentity(entry.author!, entry.authorEmail, new Date((entry.authorDate! as any) * 1000)), diff --git a/src/git/parsers/stashParser.ts b/src/git/parsers/stashParser.ts index 9725e2c..593f617 100644 --- a/src/git/parsers/stashParser.ts +++ b/src/git/parsers/stashParser.ts @@ -1,3 +1,4 @@ +import type { Container } from '../../container'; import { filterMap } from '../../system/array'; import { debug } from '../../system/decorators/log'; import { normalizePath } from '../../system/path'; @@ -44,7 +45,7 @@ export class GitStashParser { ].join('%n'); @debug({ args: false, singleLine: true }) - static parse(data: string, repoPath: string): GitStash | undefined { + static parse(container: Container, data: string, repoPath: string): GitStash | undefined { if (!data) return undefined; const lines = getLines(`${data}`); @@ -155,7 +156,7 @@ export class GitStashParser { } } - GitStashParser.parseEntry(entry, repoPath, commits); + GitStashParser.parseEntry(container, entry, repoPath, commits); entry = {}; } } @@ -167,10 +168,16 @@ export class GitStashParser { return stash; } - private static parseEntry(entry: StashEntry, repoPath: string, commits: Map) { + private static parseEntry( + container: Container, + entry: StashEntry, + repoPath: string, + commits: Map, + ) { let commit = commits.get(entry.ref!); if (commit == null) { commit = new GitCommit( + container, repoPath, entry.ref!, new GitCommitIdentity('You', undefined, new Date((entry.date! as any) * 1000)), diff --git a/src/premium/github/githubGitProvider.ts b/src/premium/github/githubGitProvider.ts index 856c5fa..88c4fda 100644 --- a/src/premium/github/githubGitProvider.ts +++ b/src/premium/github/githubGitProvider.ts @@ -419,6 +419,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { let commit = commits.get(c.oid); if (commit == null) { commit = new GitCommit( + this.container, uri.repoPath!, c.oid, new GitCommitIdentity(authorName, c.author.email, new Date(c.author.date), c.author.avatarUrl), @@ -716,6 +717,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { const committerName = viewer != null && commit.committer.name === viewer ? 'You' : commit.committer.name; return new GitCommit( + this.container, repoPath, commit.oid, new GitCommitIdentity( @@ -861,6 +863,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { const foundFile = files?.find(f => f.path === file); return new GitCommit( + this.container, repoPath, commit.oid, new GitCommitIdentity( @@ -1094,6 +1097,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { let c = commits.get(commit.oid); if (c == null) { c = new GitCommit( + this.container, repoPath, commit.oid, new GitCommitIdentity( @@ -1488,6 +1492,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { new GitFileChange(repoPath, file, GitFileIndexStatus.Modified); c = new GitCommit( + this.container, repoPath, commit.oid, new GitCommitIdentity( diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 9472074..bcf9397 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -1,9 +1,9 @@ import { MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri, window } from 'vscode'; import { ViewBranchesLayout, ViewShowBranchComparison } from '../../configuration'; import { Colors, GlyphChars } from '../../constants'; +import { Container } from '../../container'; import { GitUri } from '../../git/gitUri'; import { - BranchDateFormatting, GitBranch, GitBranchReference, GitLog, @@ -413,7 +413,7 @@ export class BranchNode }`; tooltip += `\n\nLast commit ${this.branch.formatDateFromNow()} (${this.branch.formatDate( - BranchDateFormatting.dateFormat, + Container.instance.BranchDateFormatting.dateFormat, )})`; } diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index 2ae7c70..18aff1c 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -81,7 +81,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl // Combine all the working/staged changes into single pseudo commits const commits = map( uniqueBy( - flatMap(fileStatuses, f => f.getPseudoCommits(currentUser)), + flatMap(fileStatuses, f => f.getPseudoCommits(this.view.container, currentUser)), c => c.sha, (original, c) => original.with({ files: { files: [...original.files!, ...c.files!] } }), ), @@ -90,7 +90,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl children.push(...commits); } else { const [file] = fileStatuses; - const commits = file.getPseudoCommits(currentUser); + const commits = file.getPseudoCommits(this.view.container, currentUser); if (commits.length) { children.push( ...commits.map(commit => new FileRevisionAsCommitNode(this.view, this, file, commit)), diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index 151a52a..6fcd4b4 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -116,7 +116,7 @@ export class LineHistoryNode }; const currentUser = await this.view.container.git.getCurrentUser(this.uri.repoPath!); - const pseudoCommits = status?.getPseudoCommits(currentUser); + const pseudoCommits = status?.getPseudoCommits(this.view.container, currentUser); if (pseudoCommits != null) { for (const commit of pseudoCommits.reverse()) { children.splice( diff --git a/src/views/nodes/statusFilesNode.ts b/src/views/nodes/statusFilesNode.ts index df7fca4..4255ee2 100644 --- a/src/views/nodes/statusFilesNode.ts +++ b/src/views/nodes/statusFilesNode.ts @@ -71,7 +71,7 @@ export class StatusFilesNode extends ViewNode { 0, 0, ...flatMap(this.status.files, f => - map(f.getPseudoCommits(undefined), c => this.getFileWithPseudoCommit(f, c)), + map(f.getPseudoCommits(this.view.container, undefined), c => this.getFileWithPseudoCommit(f, c)), ), ); } diff --git a/src/views/nodes/tagNode.ts b/src/views/nodes/tagNode.ts index bb39f84..238a21b 100644 --- a/src/views/nodes/tagNode.ts +++ b/src/views/nodes/tagNode.ts @@ -1,9 +1,10 @@ import { TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { ViewBranchesLayout } from '../../configuration'; import { GlyphChars } from '../../constants'; +import { Container } from '../../container'; import { emojify } from '../../emojis'; import { GitUri } from '../../git/gitUri'; -import { GitLog, GitRevision, GitTag, GitTagReference, TagDateFormatting } from '../../git/models'; +import { GitLog, GitRevision, GitTag, GitTagReference } from '../../git/models'; import { debug, gate, Iterables, Strings } from '../../system'; import { RepositoriesView } from '../repositoriesView'; import { TagsView } from '../tagsView'; @@ -74,11 +75,13 @@ export class TagNode extends ViewRefNode