Skip to content

Commit

Permalink
Adds recognition for Skybbles // L5474's contribution
Browse files Browse the repository at this point in the history
Tweaks shorten logic to only allow >=5 chars & always append any suffix
  • Loading branch information
eamodio committed Jan 8, 2019
1 parent 6a5e001 commit df0a30d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- Fixes [#606](https://github.com/eamodio/vscode-gitlens/issues/606) - ID for xxx is already registered?!
- Fixes [#607](https://github.com/eamodio/vscode-gitlens/issues/607) - Open file in Remote Doesn't URL encode
- 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))
- 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)

## [9.3.0] - 2019-01-02
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,8 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
### Advanced Settings [#](#advanced-settings- 'Advanced Settings')

| Name | Description |
| ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------|
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of the abbreviated commit SHA (a.k.a. commit ID). Default is 7.
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of abbreviated commit ids (shas) |
| `gitlens.advanced.blame.customArguments` | Specifies additional arguments to pass to the `git blame` command |
| `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 |
| `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 |
Expand Down Expand Up @@ -919,6 +919,7 @@ A big thanks to the people that have contributed to this project:
- Zack Schuster ([@zackschuster](https://github.com/zackschuster)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zackschuster)
- sgtwilko ([@sgtwilko](https://github.com/sgtwilko)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=sgtwilko)
- SpaceEEC ([@SpaceEEC](https://github.com/SpaceEEC)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=SpaceEEC)
- Skybbles // L5474 ([@Luxray5474](https://github.com/Luxray5474)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Luxray5474)
- Alexey Vasyukov ([@notmedia](https://github.com/notmedia)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=notmedia)
- Zyck ([@qzyse2017](https://github.com/qzyse2017)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=qzyse2017)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@
"gitlens.advanced.abbreviatedShaLength": {
"type": "number",
"default": "7",
"markdownDescription": "Specifies the length of the abbreviated commit SHA (a.k.a. commit ID). Default is 7.",
"markdownDescription": "Specifies the length of abbreviated commit ids (shas)",
"scope": "window"
},
"gitlens.advanced.blame.customArguments": {
Expand Down
20 changes: 14 additions & 6 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class Git {
static deletedOrMissingSha = '0000000000000000000000000000000000000000-';
static shaLikeRegex = /(^[0-9a-f]{40}([\^@~:]\S*)?$)|(^[0]{40}(:|-)$)/;
static shaRegex = /(^[0-9a-f]{40}$)|(^[0]{40}(:|-)$)/;
static shaShortenRegex = /^(.*?)([\^@~:].*)?$/;
static stagedUncommittedRegex = /^[0]{40}([\^@~]\S*)?:$/;
static stagedUncommittedSha = '0000000000000000000000000000000000000000:';
static uncommittedRegex = /^[0]{40}(?:[\^@~:]\S*)?:?$/;
Expand Down Expand Up @@ -281,13 +282,20 @@ export class Git {
return strings.uncommitted;
}

const index = ref.indexOf('^');
if (index > 5) {
// Only grab a max of 5 chars for the suffix
const suffix = ref.substring(index).substring(0, 5);
return `${ref.substring(0, Container.config.advanced.abbreviatedShaLength - suffix.length)}${suffix}`;
// Don't allow shas to be shortened to less than 5 characters
const len = Math.max(5, Container.config.advanced.abbreviatedShaLength);

// If we have a suffix, append it
const match = Git.shaShortenRegex.exec(ref);
if (match != null) {
const [, rev, suffix] = match;

if (suffix != null) {
return `${rev.substr(0, len)}${suffix}`;
}
}
return ref.substring(0, Container.config.advanced.abbreviatedShaLength);

return ref.substr(0, len);
}

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

0 comments on commit df0a30d

Please sign in to comment.