Skip to content

Commit a8e08dc

Browse files
committed
Privatizing as mutch as possible
1 parent d01a5ed commit a8e08dc

File tree

5 files changed

+88
-100
lines changed

5 files changed

+88
-100
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Fix: Rewrote all the tests
1010
* Fix: Updating dependencies
1111
* Fix: Updating preview video/image
12-
* Enhancment: Prettifying with [Prettier](https://prettier.io/)
12+
* Enhancement: Prettifying with [Prettier](https://prettier.io/)
1313
* Enhancement: Tslintifying with [TSLint](https://palantir.github.io/tslint/)
1414

1515
## 2.2.0 (September 07, 2017)

src/git/blame.ts

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ export class GitBlame {
5050
return commit.hash === HASH_NO_COMMIT_GIT;
5151
}
5252

53-
public static isGeneratedCommit(commit: IGitCommitInfo): boolean {
54-
return commit.generated;
55-
}
56-
5753
public static internalHash(hash: string): string {
5854
return hash.substr(0, Property.get(Properties.InternalHashLength));
5955
}
@@ -71,7 +67,56 @@ export class GitBlame {
7167
this.init();
7268
}
7369

74-
public setupDisposables(): void {
70+
public async blameLink(): Promise<void> {
71+
const commitInfo = await this.getCommitInfo();
72+
const commitToolUrl = this.getToolUrl(commitInfo);
73+
74+
if (commitToolUrl) {
75+
commands.executeCommand("vscode.open", commitToolUrl);
76+
} else {
77+
window.showErrorMessage(
78+
"Missing gitblame.commitUrl configuration value.",
79+
);
80+
}
81+
}
82+
83+
public async showMessage(): Promise<void> {
84+
const commitInfo = await this.getCommitInfo();
85+
const messageFormat = Property.get(Properties.InfoMessageFormat);
86+
const normalizedTokens = TextDecorator.normalizeCommitInfoTokens(
87+
commitInfo,
88+
);
89+
const message = TextDecorator.parseTokens(
90+
messageFormat,
91+
normalizedTokens,
92+
);
93+
const extraActions = this.generateMessageActions(commitInfo);
94+
95+
this.updateView(commitInfo);
96+
97+
const actionedItem = await window.showInformationMessage(
98+
message,
99+
...(await extraActions),
100+
);
101+
102+
if (actionedItem) {
103+
actionedItem.takeAction();
104+
}
105+
}
106+
107+
public defaultWebPath(url: string, hash: string): string {
108+
return url.replace(
109+
/^(git@|https:\/\/)([^:\/]+)[:\/](.*)\.git$/,
110+
`https://$2/$3/commit/${ hash }`,
111+
);
112+
}
113+
114+
public dispose(): void {
115+
Disposable.from(...Object.values(this.files)).dispose();
116+
this.disposable.dispose();
117+
}
118+
119+
private setupDisposables(): void {
75120
const disposables: Disposable[] = [];
76121

77122
// The blamer does not use the ErrorHandler but
@@ -87,7 +132,7 @@ export class GitBlame {
87132
);
88133
}
89134

90-
public setupListeners(): void {
135+
private setupListeners(): void {
91136
const disposables: Disposable[] = [];
92137

93138
window.onDidChangeActiveTextEditor(
@@ -109,16 +154,16 @@ export class GitBlame {
109154
this.disposable = Disposable.from(this.disposable, ...disposables);
110155
}
111156

112-
public init(): void {
157+
private init(): void {
113158
this.onTextEditorMove();
114159
}
115160

116-
public async onTextEditorMove(): Promise<void> {
161+
private async onTextEditorMove(): Promise<void> {
117162
const beforeBlameOpenFile = this.getCurrentActiveFileName();
118163
const beforeBlameLineNumber = this.getCurrentActiveLineNumber();
119164
const commitInfo = await this.getCurrentLineInfo();
120165

121-
// Only update if we haven"t moved since we started blaming
166+
// Only update if we haven't moved since we started blaming
122167
if (
123168
beforeBlameOpenFile === this.getCurrentActiveFileName() &&
124169
beforeBlameLineNumber === this.getCurrentActiveLineNumber()
@@ -127,55 +172,6 @@ export class GitBlame {
127172
}
128173
}
129174

130-
public async blameLink(): Promise<void> {
131-
const commitInfo = await this.getCommitInfo();
132-
const commitToolUrl = this.getToolUrl(commitInfo);
133-
134-
if (commitToolUrl) {
135-
commands.executeCommand("vscode.open", commitToolUrl);
136-
} else {
137-
window.showErrorMessage(
138-
"Missing gitblame.commitUrl configuration value.",
139-
);
140-
}
141-
}
142-
143-
public async showMessage(): Promise<void> {
144-
const commitInfo = await this.getCommitInfo();
145-
const messageFormat = Property.get(Properties.InfoMessageFormat);
146-
const normalizedTokens = TextDecorator.normalizeCommitInfoTokens(
147-
commitInfo,
148-
);
149-
const message = TextDecorator.parseTokens(
150-
messageFormat,
151-
normalizedTokens,
152-
);
153-
const extraActions = this.generateMessageActions(commitInfo);
154-
155-
this.updateView(commitInfo);
156-
157-
const actionedItem = await window.showInformationMessage(
158-
message,
159-
...(await extraActions),
160-
);
161-
162-
if (actionedItem) {
163-
actionedItem.takeAction();
164-
}
165-
}
166-
167-
public defaultWebPath(url: string, hash: string): string {
168-
return url.replace(
169-
/^(git@|https:\/\/)([^:\/]+)[:\/](.*)\.git$/,
170-
`https://$2/$3/commit/${ hash }`,
171-
);
172-
}
173-
174-
public dispose(): void {
175-
Disposable.from(...Object.values(this.files)).dispose();
176-
this.disposable.dispose();
177-
}
178-
179175
private getCurrentActiveFileName(): string {
180176
return (
181177
window.activeTextEditor && window.activeTextEditor.document.fileName
@@ -213,7 +209,7 @@ export class GitBlame {
213209
private async getCommitInfo(): Promise<IGitCommitInfo> {
214210
const commitInfo = await this.getCurrentLineInfo();
215211

216-
if (GitBlame.isGeneratedCommit(commitInfo)) {
212+
if (commitInfo.generated) {
217213
window.showErrorMessage(
218214
"The current file and line can not be blamed.",
219215
);
@@ -244,7 +240,7 @@ export class GitBlame {
244240
}
245241

246242
private updateView(commitInfo: IGitCommitInfo): void {
247-
if (GitBlame.isGeneratedCommit(commitInfo)) {
243+
if (commitInfo.generated) {
248244
this.statusBarView.clear();
249245
} else {
250246
this.statusBarView.update(commitInfo);

src/git/file.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { GitBlame } from "git/blame";
66
import { ErrorHandler } from "util/errorhandler";
77

88
export class GitFile {
9-
public fileName: Uri;
10-
public workTree: string;
9+
public readonly fileName: Uri;
1110
public disposeCallback: () => void;
1211

1312
private cacheClearInterval: NodeJS.Timer;
@@ -35,14 +34,6 @@ export class GitFile {
3534
}, TIME_CACHE_LIFETIME);
3635
}
3736

38-
public async getGitWorkTree(): Promise<string> {
39-
return this.workTree;
40-
}
41-
42-
public changed(): void {
43-
delete this.workTree;
44-
}
45-
4637
public async blame(): Promise<IGitBlameInfo> {
4738
return GitBlame.blankBlameInfo();
4839
}

src/git/filephysical.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { getGitCommand } from "util/gitcommand";
1515
export class GitFilePhysical extends GitFile {
1616
private blameInfoPromise: Promise<IGitBlameInfo>;
1717
private readonly fileSystemWatcher: FileSystemWatcher;
18+
private workTree: string;
1819
private workTreePromise: Promise<string>;
1920
private blameProcess: GitBlameStream;
2021

@@ -24,25 +25,6 @@ export class GitFilePhysical extends GitFile {
2425
this.fileSystemWatcher = this.setupWatcher();
2526
}
2627

27-
public async getGitWorkTree(): Promise<string> {
28-
if (this.workTree) {
29-
return this.workTree;
30-
}
31-
32-
if (!this.workTreePromise) {
33-
this.workTreePromise = this.findWorkTree();
34-
}
35-
36-
this.workTree = await this.workTreePromise;
37-
38-
return this.workTree;
39-
}
40-
41-
public changed(): void {
42-
super.changed();
43-
delete this.blameInfoPromise;
44-
}
45-
4628
public async blame(): Promise<IGitBlameInfo> {
4729
StatusBarView.getInstance().startProgress();
4830

@@ -81,6 +63,25 @@ export class GitFilePhysical extends GitFile {
8163
return fsWatcher;
8264
}
8365

66+
private changed(): void {
67+
delete this.workTree;
68+
delete this.blameInfoPromise;
69+
}
70+
71+
private async getGitWorkTree(): Promise<string> {
72+
if (this.workTree) {
73+
return this.workTree;
74+
}
75+
76+
if (!this.workTreePromise) {
77+
this.workTreePromise = this.findWorkTree();
78+
}
79+
80+
this.workTree = await this.workTreePromise;
81+
82+
return this.workTree;
83+
}
84+
8485
private async findWorkTree(): Promise<string> {
8586
const workTree = await this.executeGitRevParseCommand(
8687
"--show-toplevel",

src/view.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ export class StatusBarView {
3030
this.spinner = new Spinner();
3131
}
3232

33-
public setText(text: string, hasCommand: boolean = true): void {
34-
this.statusBarItem.text = text ? `${this.prefix} ${text}` : this.prefix;
35-
this.statusBarItem.tooltip = hasCommand
36-
? "git blame"
37-
: "git blame - No info about the current line";
38-
this.statusBarItem.command = hasCommand ? "gitblame.quickInfo" : "";
39-
this.statusBarItem.show();
40-
}
41-
4233
public clear(): void {
4334
this.stopProgress();
4435
this.setText("", false);
@@ -47,7 +38,7 @@ export class StatusBarView {
4738
public update(commitInfo: IGitCommitInfo): void {
4839
this.stopProgress();
4940

50-
if (commitInfo && !GitBlame.isGeneratedCommit(commitInfo)) {
41+
if (commitInfo && !commitInfo.generated) {
5142
const clickable = !GitBlame.isBlankCommit(commitInfo);
5243

5344
this.setText(TextDecorator.toTextView(commitInfo), clickable);
@@ -84,6 +75,15 @@ export class StatusBarView {
8475
this.statusBarItem.dispose();
8576
}
8677

78+
private setText(text: string, hasCommand: boolean = true): void {
79+
this.statusBarItem.text = text ? `${this.prefix} ${text}` : this.prefix;
80+
this.statusBarItem.tooltip = hasCommand
81+
? "git blame"
82+
: "git blame - No info about the current line";
83+
this.statusBarItem.command = hasCommand ? "gitblame.quickInfo" : "";
84+
this.statusBarItem.show();
85+
}
86+
8787
private setSpinner(): void {
8888
this.setText(`${this.spinner} Waiting for git blame response`, false);
8989
}

0 commit comments

Comments
 (0)