Skip to content

Commit df0a30d

Browse files
committed
Adds recognition for Skybbles // L5474's contribution
Tweaks shorten logic to only allow >=5 chars & always append any suffix
1 parent 6a5e001 commit df0a30d

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1515

1616
- Fixes [#606](https://github.com/eamodio/vscode-gitlens/issues/606) - ID for xxx is already registered?!
1717
- Fixes [#607](https://github.com/eamodio/vscode-gitlens/issues/607) - Open file in Remote Doesn't URL encode
18+
- Fixes [#608](https://github.com/eamodio/vscode-gitlens/issues/608) - Add an option to change the abbreviated commit SHA length — thanks to [PR #611](https://github.com/eamodio/vscode-gitlens/pull/611) by Skybbles // L5474 ([@Luxray5474](https://github.com/Luxray5474))
1819
- Fixes [#613](https://github.com/eamodio/vscode-gitlens/issues/613) - Change Copy Remote URL to Clipboard to always copy a permalink (e.g. revision link)
1920

2021
## [9.3.0] - 2019-01-02

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
841841
### Advanced Settings [#](#advanced-settings- 'Advanced Settings')
842842

843843
| Name | Description |
844-
| ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------|
845-
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of the abbreviated commit SHA (a.k.a. commit ID). Default is 7.
844+
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
845+
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of abbreviated commit ids (shas) |
846846
| `gitlens.advanced.blame.customArguments` | Specifies additional arguments to pass to the `git blame` command |
847847
| `gitlens.advanced.blame.delayAfterEdit` | Specifies the time (in milliseconds) to wait before re-blaming an unsaved document after an edit. Use 0 to specify an infinite wait |
848848
| `gitlens.advanced.blame.sizeThresholdAfterEdit` | Specifies the maximum document size (in lines) allowed to be re-blamed after an edit while still unsaved. Use 0 to specify no maximum |
@@ -919,6 +919,7 @@ A big thanks to the people that have contributed to this project:
919919
- Zack Schuster ([@zackschuster](https://github.com/zackschuster)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zackschuster)
920920
- sgtwilko ([@sgtwilko](https://github.com/sgtwilko)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=sgtwilko)
921921
- SpaceEEC ([@SpaceEEC](https://github.com/SpaceEEC)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=SpaceEEC)
922+
- Skybbles // L5474 ([@Luxray5474](https://github.com/Luxray5474)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Luxray5474)
922923
- Alexey Vasyukov ([@notmedia](https://github.com/notmedia)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=notmedia)
923924
- Zyck ([@qzyse2017](https://github.com/qzyse2017)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=qzyse2017)
924925

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@
15861586
"gitlens.advanced.abbreviatedShaLength": {
15871587
"type": "number",
15881588
"default": "7",
1589-
"markdownDescription": "Specifies the length of the abbreviated commit SHA (a.k.a. commit ID). Default is 7.",
1589+
"markdownDescription": "Specifies the length of abbreviated commit ids (shas)",
15901590
"scope": "window"
15911591
},
15921592
"gitlens.advanced.blame.customArguments": {

src/git/git.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export class Git {
223223
static deletedOrMissingSha = '0000000000000000000000000000000000000000-';
224224
static shaLikeRegex = /(^[0-9a-f]{40}([\^@~:]\S*)?$)|(^[0]{40}(:|-)$)/;
225225
static shaRegex = /(^[0-9a-f]{40}$)|(^[0]{40}(:|-)$)/;
226+
static shaShortenRegex = /^(.*?)([\^@~:].*)?$/;
226227
static stagedUncommittedRegex = /^[0]{40}([\^@~]\S*)?:$/;
227228
static stagedUncommittedSha = '0000000000000000000000000000000000000000:';
228229
static uncommittedRegex = /^[0]{40}(?:[\^@~:]\S*)?:?$/;
@@ -281,13 +282,20 @@ export class Git {
281282
return strings.uncommitted;
282283
}
283284

284-
const index = ref.indexOf('^');
285-
if (index > 5) {
286-
// Only grab a max of 5 chars for the suffix
287-
const suffix = ref.substring(index).substring(0, 5);
288-
return `${ref.substring(0, Container.config.advanced.abbreviatedShaLength - suffix.length)}${suffix}`;
285+
// Don't allow shas to be shortened to less than 5 characters
286+
const len = Math.max(5, Container.config.advanced.abbreviatedShaLength);
287+
288+
// If we have a suffix, append it
289+
const match = Git.shaShortenRegex.exec(ref);
290+
if (match != null) {
291+
const [, rev, suffix] = match;
292+
293+
if (suffix != null) {
294+
return `${rev.substr(0, len)}${suffix}`;
295+
}
289296
}
290-
return ref.substring(0, Container.config.advanced.abbreviatedShaLength);
297+
298+
return ref.substr(0, len);
291299
}
292300

293301
static splitPath(fileName: string, repoPath: string | undefined, extract: boolean = true): [string, string] {

0 commit comments

Comments
 (0)