Skip to content

Commit 6ba13bd

Browse files
committed
v11
1 parent 602f912 commit 6ba13bd

26 files changed

+293
-251
lines changed

CHANGELOG.md

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Change Log
22

3-
## 10.11.0 (May, 09, 2024)
3+
## 11.0.0 (May xx, 2024)
4+
* Feature: Will no longer blame files with more lines than `gitblame.maxLineCount` (default `16384`) [#172](https://github.com/Sertion/vscode-gitblame/issues/172)* Thanks to [webextensions](https://github.com/webextensions).
5+
* Fun fact: This number was selected as it is the last power of 2 lower than 20000. It has no other significance.
6+
7+
## 10.11.0 (May 09, 2024)
48
* Feature: *Copy commit hash on info message click [#171](https://github.com/Sertion/vscode-gitblame/issues/171)* Thanks to [Harsh](https://github.com/harshbhatt).
59
* Fix: Updating dependencies
610

7-
## 10.10.1 (April, 30, 2024)
11+
## 10.10.1 (April 30, 2024)
812
* Bug: *Status Bar block disappears after a change in extension settings [#155](https://github.com/Sertion/vscode-gitblame/issues/155)* Thanks to [ADTC](https://github.com/ADTC).
913
* Fix: Updating dependencies
1014

@@ -52,7 +56,7 @@
5256

5357
## 10.3.0 (June 23, 2023)
5458
* Bug: Spawns many Git processes and uses up CPU ([#144](https://github.com/Sertion/vscode-gitblame/issues/144)) Thanks to [Theo Crandall](https://github.com/thrandale)!
55-
* New setting `gitblame.parallelBlames` controlls how many git blame processes that will run in parallel. Defaults to `2`.
59+
* New setting `gitblame.parallelBlames` controls how many git blame processes that will run in parallel. Defaults to `2`.
5660
* Bug: Blame completing can sometimes update the status bar to info from the wrong file
5761
* Fix: Fewer dev dependencies
5862

@@ -121,7 +125,7 @@
121125
* Fix: CHANGELOG.md link to contributor
122126

123127
## 8.2.0 (May 13, 2022)
124-
* Feature: Blame information as soon as it is avalible. This will allow some lines to show blame information while others still are waiting for `git blame`.
128+
* Feature: Blame information as soon as it is available. This will allow some lines to show blame information while others still are waiting for `git blame`.
125129
* Feature: Allow blaming symlinked files [#121](https://github.com/Sertion/vscode-gitblame/pull/121) (Thanks to [Angel Fraga Parodi](https://github.com/angelfraga))
126130
* Bug: Blame info persistent over file change and file close [#115](https://github.com/Sertion/vscode-gitblame/issues/115) (Thanks to [Wenfang Du](https://github.com/wenfangdu) and [Viktor Stenqvist](https://github.com/Yottster))
127131
* Bug: commit.summary before commit.hash_short causes display bug [#119](https://github.com/Sertion/vscode-gitblame/issues/119) (Thanks to [Cathryne Linenweaver](https://github.com/Cathryne))
@@ -182,7 +186,7 @@
182186
* Bug: Stuck Waiting for git blame response (6.0.0) [#95](https://github.com/Sertion/vscode-gitblame/issues/95) (Thanks to [Vadzim Dambrouski](https://github.com/pftbest))
183187

184188
## 6.0.0 (October 14, 2020)
185-
* Breaking change: Removing setting `gitblame.logNonCritical` as we no longer produce any ciritcal errors
189+
* Breaking change: Removing setting `gitblame.logNonCritical` as we no longer produce any critical errors
186190
* Breaking change: The token `${|mod}` now expands to `|mod`, previously `${|mod}`
187191
* Breaking change: Renamed output channel from "Extension: gitblame" to "gitblame"
188192
* Bug: "Waiting for git blame response" (5.0.1) [#92](https://github.com/Sertion/vscode-gitblame/issues/92) (Thanks to [Dominik Zogg](https://github.com/dominikzogg) and [Alex Shelmire](https://github.com/shelmire))
@@ -204,15 +208,15 @@
204208
## 4.1.0 (July 09, 2020)
205209
* Feature: Improve time ago estimate [#83](https://github.com/Sertion/vscode-gitblame/pull/83) (Thanks to [Ben Langlois](https://github.com/BenLanglois))
206210
* Feature: Unable to open '': File is a directory. [#84](https://github.com/Sertion/vscode-gitblame/issues/84) (Thanks to [Matt Fletcher](https://github.com/MaffooBristol))
207-
* Bug: Refixing [#3](https://github.com/Sertion/vscode-gitblame/issues/3)
211+
* Bug: Re-fixing [#3](https://github.com/Sertion/vscode-gitblame/issues/3)
208212
* Fix: Updating dependencies
209213
* Fix: Updated linters means pushing around code
210214

211215
## 4.0.1 (May 13, 2020)
212216
* Bug: Undocumented change to [StatusBarItem api](https://code.visualstudio.com/api/references/vscode-api#StatusBarItem) [#82](https://github.com/Sertion/vscode-gitblame/issues/82) (Thanks to [Mike MacCana](https://github.com/mikemaccana))
213217

214218
## 4.0.0 (May 01, 2020)
215-
* Deprication: Removing all depricated message token
219+
* Deprecation: Removing all deprecated message token
216220
* Feature: It is now able to limit the length of the summary [#81](https://github.com/Sertion/vscode-gitblame/issues/81) (Thanks to [Diab Neiroukh](https://github.com/lazerl0rd))
217221

218222
## 3.2.0 (March 09, 2020)
@@ -230,19 +234,19 @@
230234
* Fix: Updating dependencies
231235

232236
## 3.0.1 (August 02, 2019)
233-
* Bug: Removing depricated token from default value for `gitblame.infoMessageFormat` [#57](https://github.com/Sertion/vscode-gitblame/issues/57) (Thanks to [Kyngo](https://github.com/Kyngo))
237+
* Bug: Removing deprecated token from default value for `gitblame.infoMessageFormat` [#57](https://github.com/Sertion/vscode-gitblame/issues/57) (Thanks to [Kyngo](https://github.com/Kyngo))
234238

235239
## 3.0.0 (July 27, 2019)
236240
* Bug: Fixing rare bug where swapping between different file views didn't update the view
237-
* Deprication: Removing the `.custom` tokens from status bar message
238-
* Deprication: The `.from` token now is identical to `.ago`
239-
* Deprication: Removing the `commit.filename` tokens from status bar message
240-
* Deprication: Removing custom spinner support (`gitblame.progressSpinner`)
241-
* Deprication: Removing log levels (`gitblame.logLevel`). It is replaced by `gitblame.logNonCritical` (defaults to `true`)
241+
* Deprecation: Removing the `.custom` tokens from status bar message
242+
* Deprecation: The `.from` token now is identical to `.ago`
243+
* Deprecation: Removing the `commit.filename` tokens from status bar message
244+
* Deprecation: Removing custom spinner support (`gitblame.progressSpinner`)
245+
* Deprecation: Removing log levels (`gitblame.logLevel`). It is replaced by `gitblame.logNonCritical` (defaults to `true`)
242246
* Feature: Blame cache is now tied to the open document. Closing the document will clear if from the cache
243247
* Feature: Move to the new `@types/vscode` and `vscode-test` packages
244248
* Feature: Move to new build system
245-
* Fix: Removeing or updating dependencies
249+
* Fix: Removing or updating dependencies
246250

247251
The removal of the custom-token allows us to remove our dependency on moment. This lowers the extension bundle size from 850 kb to about 100 kb.
248252

@@ -293,8 +297,8 @@ There is a new setting called `gitblame.pluralWebPathSubstrings`. It is an array
293297
* Feature: We now use `vscode.git` to find your git binary.
294298
* Fix: Change the default info message format to be prefixed by the date instead of the commit hash. It is in ISO 8601 with dashes for separator.
295299
* Fix: Updating Readme to better guide Bitbucket users to the `isWebPathPlural` setting.
296-
* Fix: Removed `internalHashLength` setting. We now alsways use the whole hash.
297-
* Fix: Moved back to using [`fs.watch`](https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener) from [`workspace.FileSystemWatcher`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#workspace.createFileSystemWatcher) after getting reposts that file watching is having issues.
300+
* Fix: Removed `internalHashLength` setting. We now always use the whole hash.
301+
* Fix: Moved back to using [`fs.watch`](https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener) from [`workspace.FileSystemWatcher`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#workspace.createFileSystemWatcher) after getting reports that file watching is having issues.
298302
* Fix: Better handling of ENOENT in git command runner. [#41](https://github.com/Sertion/vscode-gitblame/pull/41) (Thanks to [Yottster](https://github.com/Yottster))
299303
* Fix: Moved to strict TypeScript.
300304
* Fix: Updating dependencies
@@ -305,7 +309,7 @@ There is a new setting called `gitblame.pluralWebPathSubstrings`. It is an array
305309

306310
## 2.4.3 (August 01, 2018)
307311

308-
* Bug: Showing unedited gitblame info template when running *Show quick Info* on unblameable line (Thanks to [BerndErnst](https://github.com/BerndErnst))
312+
* Bug: Showing unedited gitblame info template when running *Show quick Info* on un-blameable line (Thanks to [BerndErnst](https://github.com/BerndErnst))
309313
* Bug: Using a map instead of an object for storing git blame file cache. Now we can blame files named `__proto__` etc.
310314

311315
## 2.4.2 (April 05, 2018)
@@ -326,7 +330,7 @@ There is a new setting called `gitblame.pluralWebPathSubstrings`. It is an array
326330

327331
## 2.3.0 (March 24, 2018)
328332

329-
* Feature: Atempting to auto detect if you use a known git web interface [#15](https://github.com/Sertion/vscode-gitblame/issues/15) (Thanks to [@Fidge123](https://github.com/Fidge123), [@sabrehagen](https://github.com/sabrehagen), [@henvic](https://github.com/henvic), and an extra thanks to [@neerolyte](https://github.com/neerolyte))
333+
* Feature: Attempting to auto detect if you use a known git web interface [#15](https://github.com/Sertion/vscode-gitblame/issues/15) (Thanks to [@Fidge123](https://github.com/Fidge123), [@sabrehagen](https://github.com/sabrehagen), [@henvic](https://github.com/henvic), and an extra thanks to [@neerolyte](https://github.com/neerolyte))
330334
* Feature: Added `gitblame.statusBarPositionPriority` for moving the status bar view [#25](https://github.com/Sertion/vscode-gitblame/issues/25) (Thanks to [@jvoigt](https://github.com/jvoigt))
331335
* Fix: Merging `GitBlame` and `GitBlameController` to `GitBlame`
332336
* Fix: Renaming `GitBlameFile*` to `GitFile*`

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Features:
1010

1111
![Feature Usage](https://raw.githubusercontent.com/Sertion/vscode-gitblame/master/images/preview.png)
1212

13-
Git blame adds git blame information to your vscode compatible view. See information about what commit last changed a line and how long ago it was. Click the message to see more information about the commit. It is possible to edit all of these information messages in the settings. There are multiple tokens avalible. These are described below.
13+
Git blame adds git blame information to your vscode compatible view. See information about what commit last changed a line and how long ago it was. Click the message to see more information about the commit. It is possible to edit all of these information messages in the settings. There are multiple tokens available. These are described below.
1414

1515
Git Blame works very well with WSL but does not work with the web browser based vscode compatible editors.
1616

@@ -105,7 +105,7 @@ Message on the current line when no commit can be found. _No available tokens_.
105105
106106
> Default value: `false`
107107
108-
To enable the inline git blame view. Shows blame information at the end of the current line if avalible.
108+
To enable the inline git blame view. Shows blame information at the end of the current line if available.
109109

110110
### `gitblame.inlineMessageMargin`
111111
> Type: `number`

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "gitblame",
33
"displayName": "Git Blame",
44
"description": "See git blame information in the status bar.",
5-
"version": "10.11.0",
5+
"version": "11.0.0",
66
"publisher": "waderyan",
77
"engines": {
8-
"vscode": "^1.82.0"
8+
"vscode": "^1.82.0",
9+
"node": "^18.15.0"
910
},
1011
"categories": [
1112
"Other"
@@ -61,7 +62,11 @@
6162
"vscode.git"
6263
],
6364
"capabilities": {
64-
"virtualWorkspaces": false
65+
"virtualWorkspaces": false,
66+
"untrustedWorkspaces": {
67+
"supported": false,
68+
"description": "Git Blame (extension) executes command line tools in the workspace"
69+
}
6570
},
6671
"contributes": {
6772
"commands": [
@@ -195,6 +200,11 @@
195200
"default": 2,
196201
"description": "Limit allowed parallel git blame process count"
197202
},
203+
"gitblame.maxLineCount": {
204+
"type": "number",
205+
"default": 16384,
206+
"markdownDescription": "Will skip blaming files with **more** lines than this value"
207+
},
198208
"gitblame.revsFile": {
199209
"type": "array",
200210
"default": [],

src/git/blame.ts

+65-65
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { type FSWatcher, promises, watch } from "node:fs";
22

3-
import type { LineAttatchedCommit } from "./util/stream-parsing.js";
3+
import type { LineAttachedCommit } from "./util/stream-parsing.js";
44

55
import { type Disposable, workspace } from "vscode";
66
import { Logger } from "../util/logger.js";
77
import { getProperty } from "../util/property.js";
88
import { type Blame, File } from "./file.js";
99
import { Queue } from "./queue.js";
10-
import { getGitFolder } from "./util/gitcommand.js";
11-
12-
type Files =
13-
| undefined
14-
| {
15-
file: File | undefined;
16-
store: Promise<Blame | undefined>;
17-
gitRoot: string;
18-
};
10+
import { getGitFolder } from "./util/git-command.js";
1911

2012
export class Blamer {
21-
private readonly files = new Map<string, Promise<Files>>();
13+
private readonly metadata = new WeakMap<
14+
Promise<Blame | undefined>,
15+
| {
16+
file: File;
17+
gitRoot: string;
18+
}
19+
| undefined
20+
>();
21+
private readonly files = new Map<string, Promise<Blame | undefined>>();
2222
private readonly fsWatchers = new Map<string, FSWatcher>();
2323
private readonly blameQueue = new Queue<Blame | undefined>(
2424
getProperty("parallelBlames"),
@@ -28,43 +28,73 @@ export class Blamer {
2828
public constructor() {
2929
this.configChange = workspace.onDidChangeConfiguration((e) => {
3030
if (e.affectsConfiguration("gitblame")) {
31-
this.blameQueue.updateParalell(getProperty("parallelBlames"));
31+
this.blameQueue.updateParallel(getProperty("parallelBlames"));
3232
}
3333
});
3434
}
3535

36-
public async file(fileName: string): Promise<Blame | undefined> {
37-
return this.get(fileName);
36+
public async prepareFile(fileName: string): Promise<void> {
37+
if (this.files.has(fileName)) {
38+
return;
39+
}
40+
41+
let resolve: (blame: Promise<Blame | undefined>) => void = () => {};
42+
this.files.set(
43+
fileName,
44+
new Promise<Blame | undefined>((res) => {
45+
resolve = res;
46+
}),
47+
);
48+
49+
const { file, gitRoot } = await this.create(fileName);
50+
51+
if (file === undefined) {
52+
resolve(Promise.resolve(undefined));
53+
return;
54+
}
55+
56+
this.fsWatchers.set(
57+
file.fileName,
58+
watch(file.fileName, () => {
59+
this.remove(file.fileName);
60+
}),
61+
);
62+
63+
const blame = this.blameQueue.add(() => file.getBlame());
64+
this.metadata.set(blame, { file, gitRoot });
65+
resolve(blame);
3866
}
3967

4068
public async getLine(
4169
fileName: string,
4270
lineNumber: number,
43-
): Promise<LineAttatchedCommit | undefined> {
71+
): Promise<LineAttachedCommit | undefined> {
72+
await this.prepareFile(fileName);
73+
4474
const commitLineNumber = lineNumber + 1;
45-
const blameInfo = await this.get(fileName);
75+
const blameInfo = await this.files.get(fileName);
4676

4777
return blameInfo?.get(commitLineNumber);
4878
}
4979

50-
public async removeFromRepository(gitRepositoryPath: string): Promise<void> {
80+
public removeFromRepository(gitRepositoryPath: string): void {
5181
for (const [fileName, file] of this.files) {
52-
const gitRoot = (await file)?.gitRoot;
53-
if (gitRoot === gitRepositoryPath) {
82+
const metadata = this.metadata.get(file);
83+
if (metadata?.gitRoot === gitRepositoryPath) {
5484
this.remove(fileName);
5585
}
5686
}
5787
}
5888

59-
public async remove(fileName: string): Promise<void> {
60-
(await (await this.files.get(fileName))?.file)?.dispose();
61-
this.fsWatchers.get(fileName)?.close();
62-
this.files.delete(fileName);
63-
const fsWatcher = this.fsWatchers.get(fileName);
64-
if (fsWatcher) {
65-
this.fsWatchers.delete(fileName);
66-
fsWatcher.close();
89+
public remove(fileName: string): void {
90+
const blame = this.files.get(fileName);
91+
if (blame) {
92+
this.metadata.get(blame)?.file?.dispose();
6793
}
94+
95+
this.files.delete(fileName);
96+
this.fsWatchers.get(fileName)?.close();
97+
this.fsWatchers.delete(fileName);
6898
}
6999

70100
public dispose(): void {
@@ -74,59 +104,29 @@ export class Blamer {
74104
this.configChange.dispose();
75105
}
76106

77-
private async get(fileName: string): Promise<Blame | undefined> {
78-
if (this.files.has(fileName)) {
79-
return (await this.files.get(fileName))?.store;
80-
}
81-
82-
const setup = this.create(fileName).then(({ file, gitRoot }): Files => {
83-
if (file) {
84-
this.fsWatchers.set(
85-
fileName,
86-
watch(fileName, () => {
87-
this.remove(fileName);
88-
}),
89-
);
90-
return {
91-
file,
92-
store: this.blameQueue.add(() => file.getBlame()),
93-
gitRoot,
94-
};
95-
}
96-
97-
return {
98-
file,
99-
store: Promise.resolve(undefined),
100-
gitRoot,
101-
};
102-
});
103-
104-
this.files.set(fileName, setup);
105-
106-
return (await setup)?.store;
107-
}
108-
109107
private async create(
110108
fileName: string,
111-
): Promise<{ gitRoot: string; file: File | undefined }> {
109+
): Promise<
110+
{ gitRoot: string; file: File } | { gitRoot: undefined; file: undefined }
111+
> {
112112
try {
113113
await promises.access(fileName);
114114

115-
const gitRoot = getGitFolder(fileName);
116-
if (await gitRoot) {
115+
const gitRoot = await getGitFolder(fileName);
116+
if (gitRoot) {
117117
return {
118-
gitRoot: await gitRoot,
118+
gitRoot: gitRoot,
119119
file: new File(fileName),
120120
};
121121
}
122122
} catch {
123123
// NOOP
124124
}
125125

126-
Logger.info(`Will not blame '${fileName}'. Outside the current workspace.`);
126+
Logger.info(`Will not blame '${fileName}'. Not in a git repository.`);
127127

128128
return {
129-
gitRoot: "",
129+
gitRoot: undefined,
130130
file: undefined,
131131
};
132132
}

0 commit comments

Comments
 (0)