Bladeren bron

Cleans up some duplicate code

main
Eric Amodio 7 jaren geleden
bovenliggende
commit
64ae82075e
6 gewijzigde bestanden met toevoegingen van 74 en 21 verwijderingen
  1. +3
    -3
      src/commands.ts
  2. +3
    -1
      src/extension.ts
  3. +28
    -7
      src/git/formatters/commit.ts
  4. +22
    -0
      src/git/gitUri.ts
  5. +16
    -0
      src/git/models/status.ts
  6. +2
    -10
      src/quickPicks/commitDetails.ts

+ 3
- 3
src/commands.ts Bestand weergeven

@ -21,16 +21,16 @@ export * from './commands/openInRemote';
export * from './commands/openRepoInRemote';
export * from './commands/resetSuppressedWarnings';
export * from './commands/showBlameHistory';
export * from './commands/showCommitSearch';
export * from './commands/showFileBlame';
export * from './commands/showFileHistory';
export * from './commands/showLastQuickPick';
export * from './commands/showLineBlame';
export * from './commands/showQuickBranchHistory';
export * from './commands/showQuickCommitDetails';
export * from './commands/showQuickCommitFileDetails';
export * from './commands/showCommitSearch';
export * from './commands/showQuickFileHistory';
export * from './commands/showQuickBranchHistory';
export * from './commands/showQuickCurrentBranchHistory';
export * from './commands/showQuickFileHistory';
export * from './commands/showQuickRepoStatus';
export * from './commands/showQuickStashList';
export * from './commands/stashApply';

+ 3
- 1
src/extension.ts Bestand weergeven

@ -21,8 +21,8 @@ import { CodeLensLocations, IConfig, LineHighlightLocations } from './configurat
import { ApplicationInsightsKey, ExtensionKey, QualifiedExtensionId, WorkspaceState } from './constants';
import { CurrentLineController, LineAnnotationType } from './currentLineController';
import { GitContentProvider } from './gitContentProvider';
import { GitContextTracker, GitService } from './gitService';
import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider';
import { GitContextTracker, GitService } from './gitService';
import { Logger } from './logger';
import { Messages, SuppressedKeys } from './messages';
import { Telemetry } from './telemetry';
@ -270,6 +270,8 @@ async function notifyOnNewGitLensVersion(context: ExtensionContext, version: str
const [major, minor] = version.split('.');
const [prevMajor, prevMinor] = previousVersion.split('.');
if (major === prevMajor && minor === prevMinor) return;
// Don't notify on downgrades
if (major < prevMajor || (major === prevMajor && minor < prevMinor)) return;
await Messages.showUpdateMessage(version);
}

+ 28
- 7
src/git/formatters/commit.ts Bestand weergeven

@ -17,9 +17,18 @@ export interface ICommitFormatOptions {
export class CommitFormatter {
private _commit: GitCommit;
private _options: ICommitFormatOptions;
constructor(private commit: GitCommit, options?: ICommitFormatOptions) {
constructor(commit: GitCommit, options?: ICommitFormatOptions) {
this.reset(commit, options);
}
reset(commit: GitCommit, options?: ICommitFormatOptions) {
this._commit = commit;
if (options === undefined && this._options !== undefined) return;
options = options || {};
if (options.tokenOptions == null) {
options.tokenOptions = {};
@ -33,31 +42,31 @@ export class CommitFormatter {
}
get ago() {
const ago = moment(this.commit.date).fromNow();
const ago = moment(this._commit.date).fromNow();
return this._padOrTruncate(ago, this._options.tokenOptions!.ago);
}
get author() {
const author = this.commit.author;
const author = this._commit.author;
return this._padOrTruncate(author, this._options.tokenOptions!.author);
}
get authorAgo() {
const authorAgo = `${this.commit.author}, ${moment(this.commit.date).fromNow()}`;
const authorAgo = `${this._commit.author}, ${moment(this._commit.date).fromNow()}`;
return this._padOrTruncate(authorAgo, this._options.tokenOptions!.authorAgo);
}
get date() {
const date = moment(this.commit.date).format(this._options.dateFormat!);
const date = moment(this._commit.date).format(this._options.dateFormat!);
return this._padOrTruncate(date, this._options.tokenOptions!.date);
}
get id() {
return this.commit.shortSha;
return this._commit.shortSha;
}
get message() {
const message = this.commit.isUncommitted ? 'Uncommitted change' : this.commit.message;
const message = this._commit.isUncommitted ? 'Uncommitted change' : this._commit.message;
return this._padOrTruncate(message, this._options.tokenOptions!.message);
}
@ -113,6 +122,18 @@ export class CommitFormatter {
return s;
}
private static _formatter: CommitFormatter | undefined = undefined;
static fromCommit(commit: GitCommit, options?: ICommitFormatOptions): CommitFormatter {
if (CommitFormatter._formatter === undefined) {
CommitFormatter._formatter = new CommitFormatter(commit, options);
}
else {
CommitFormatter._formatter.reset(commit, options);
}
return CommitFormatter._formatter;
}
static fromTemplate(template: string, commit: GitCommit, dateFormat: string | null): string;
static fromTemplate(template: string, commit: GitCommit, options?: ICommitFormatOptions): string;
static fromTemplate(template: string, commit: GitCommit, dateFormatOrOptions?: string | null | ICommitFormatOptions): string;

+ 22
- 0
src/git/gitUri.ts Bestand weergeven

@ -102,6 +102,28 @@ export class GitUri extends Uri {
const uri = Uri.file(path.resolve(repoPath, original ? status.originalFileName || status.fileName : status.fileName));
return new GitUri(uri, repoPathOrCommit);
}
static getDirectory(fileName: string): string {
const directory: string | undefined = GitService.normalizePath(path.dirname(fileName));
return (!directory || directory === '.') ? '' : directory;
}
static getFormattedPath(fileNameOrUri: string | Uri, separator: string = ' \u00a0\u2022\u00a0 '): string {
let fileName: string;
if (fileNameOrUri instanceof Uri) {
if (fileNameOrUri instanceof GitUri) return fileNameOrUri.getFormattedPath(separator);
fileName = fileNameOrUri.fsPath;
}
else {
fileName = fileNameOrUri;
}
const directory = GitUri.getDirectory(fileName);
return !directory
? path.basename(fileName)
: `${path.basename(fileName)}${separator}${directory}`;
}
}
export interface IGitCommitInfo {

+ 16
- 0
src/git/models/status.ts Bestand weergeven

@ -1,5 +1,6 @@
'use strict';
import { Uri } from 'vscode';
import { GitUri } from '../gitUri';
import * as path from 'path';
export interface GitStatus {
@ -32,6 +33,14 @@ export class GitStatusFile implements IGitStatusFile {
this.originalFileName = originalFileName;
}
getFormattedDirectory(includeOriginal: boolean = false): string {
return GitStatusFile.getFormattedDirectory(this, includeOriginal);
}
getFormattedPath(separator: string = ' \u00a0\u2022\u00a0 '): string {
return GitUri.getFormattedPath(this.fileName, separator);
}
getIcon() {
return getGitStatusIcon(this.status);
}
@ -39,6 +48,13 @@ export class GitStatusFile implements IGitStatusFile {
get Uri(): Uri {
return Uri.file(path.resolve(this.repoPath, this.fileName));
}
static getFormattedDirectory(status: IGitStatusFile, includeOriginal: boolean = false): string {
const directory = GitUri.getDirectory(status.fileName);
return (includeOriginal && status.status === 'R' && status.originalFileName)
? `${directory} \u00a0\u2190\u00a0 ${status.originalFileName}`
: directory;
}
}
const statusOcticonsMap = {

+ 2
- 10
src/quickPicks/commitDetails.ts Bestand weergeven

@ -3,7 +3,7 @@ import { Arrays, Iterables } from '../system';
import { commands, QuickPickOptions, TextDocumentShowOptions, Uri, window } from 'vscode';
import { Commands, CopyMessageToClipboardCommandArgs, CopyShaToClipboardCommandArgs, DiffDirectoryCommandCommandArgs, DiffWithPreviousCommandArgs, Keyboard, KeyNoopCommand, Keys, ShowQuickCommitDetailsCommandArgs, StashApplyCommandArgs, StashDeleteCommandArgs } from '../commands';
import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, KeyCommandQuickPickItem, OpenFileCommandQuickPickItem, OpenFilesCommandQuickPickItem, QuickPickItem } from './common';
import { getGitStatusIcon, GitCommit, GitLog, GitLogCommit, GitService, GitStashCommit, GitStatusFileStatus, GitUri, IGitCommitInfo, IGitStatusFile, RemoteResource } from '../gitService';
import { getGitStatusIcon, GitCommit, GitLog, GitLogCommit, GitService, GitStashCommit, GitStatusFile, GitStatusFileStatus, GitUri, IGitCommitInfo, IGitStatusFile, RemoteResource } from '../gitService';
import { OpenRemotesCommandQuickPickItem } from './remotes';
import * as moment from 'moment';
import * as path from 'path';
@ -19,15 +19,7 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI
constructor(commit: GitCommit, status: IGitStatusFile) {
const icon = getGitStatusIcon(status.status);
let directory: string | undefined = GitService.normalizePath(path.dirname(status.fileName));
if (!directory || directory === '.') {
directory = '';
}
const description = (status.status === 'R' && status.originalFileName)
? `${directory} \u00a0\u2190\u00a0 ${status.originalFileName}`
: directory;
const description = GitStatusFile.getFormattedDirectory(status, true);
let sha;
let shortSha;

Laden…
Annuleren
Opslaan