Skip to content

Commit 0a4c24c

Browse files
committed
Fixes #635 - removes periodic refresh of repo node
Refreshing a node triggers all children to be re-rendered Replaces intra-day relative date format with additional time
1 parent 0a35811 commit 0a4c24c

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
99
### Changed
1010

1111
- Changes the sorting of remotes in the _Repositories_ view to sort the default remote first
12+
- Changes relative date formatting of the last fetched date of repositories in the _Repositories_ view to instead use an absolute format and will additionally add the time of day if less than a day has passed. This avoids having to periodically refresh the repository (which causes all of its children to re-render) in order to update the relative time
1213

1314
### Fixed
1415

@@ -17,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1718
- Fixes [#626](https://github.com/eamodio/vscode-gitlens/issues/626) - Branch names with only digits always appear first — thanks to [PR #627](https://github.com/eamodio/vscode-gitlens/pull/627) by Marc Lasson ([@mlasson](https://github.com/mlasson))
1819
- Fixes [#631](https://github.com/eamodio/vscode-gitlens/issues/631) - Remotes fail to show in gui
1920
- Fixes [#633](https://github.com/eamodio/vscode-gitlens/issues/633) - Compare File with Previous Revision doesn't work if path contains '#'
21+
- Fixes [#635](https://github.com/eamodio/vscode-gitlens/issues/635) - Show more commit not working properly
2022
- Fixes an issue where the _Open File_, _Open File on Remote_, and _Copy Remote Url to Clipboard_ commands didn't always work on changed files in the _Repositories_ view
2123
- Fixes an issue where the default remote wasn't used first to provide automatic issue linking
2224

src/views/nodes/repositoryNode.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
RepositoryChangeEvent,
1212
RepositoryFileSystemChangeEvent
1313
} from '../../git/gitService';
14-
import { Dates, debug, Functions, gate, log, Strings } from '../../system';
15-
import { DateStyle } from '../../ui/config';
14+
import { Dates, debug, gate, log, Strings } from '../../system';
1615
import { RepositoriesView } from '../repositoriesView';
1716
import { BranchesNode } from './branchesNode';
1817
import { BranchNode } from './branchNode';
@@ -24,6 +23,8 @@ import { StatusFilesNode } from './statusFilesNode';
2423
import { TagsNode } from './tagsNode';
2524
import { ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
2625

26+
const hasTimeRegex = /[hHm]/;
27+
2728
export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
2829
private _children: ViewNode[] | undefined;
2930
private _lastFetched: number = 0;
@@ -98,7 +99,8 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
9899

99100
const lastFetchedTooltip = this.formatLastFetched({
100101
prefix: `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched on `,
101-
format: Container.config.defaultDateFormat || 'dddd MMMM Do, YYYY h:mm a'
102+
format: Container.config.defaultDateFormat || 'dddd MMMM Do, YYYY',
103+
includeTime: true
102104
});
103105

104106
let description;
@@ -216,9 +218,9 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
216218
protected async subscribe() {
217219
const disposables = [this.repo.onDidChange(this.onRepoChanged, this)];
218220

219-
if (Container.config.defaultDateStyle === DateStyle.Relative) {
220-
disposables.push(Functions.interval(() => void this.updateLastFetched(), 60000));
221-
}
221+
// if (Container.config.defaultDateStyle === DateStyle.Relative) {
222+
// disposables.push(Functions.interval(() => void this.updateLastFetched(), 60000));
223+
// }
222224

223225
if (this.includeWorkingTree) {
224226
disposables.push(this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this), {
@@ -293,29 +295,38 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
293295
}
294296
}
295297

296-
private formatLastFetched(options: { prefix?: string; format?: string } = {}) {
298+
private formatLastFetched(options: { prefix?: string; format?: string; includeTime?: boolean } = {}) {
297299
if (this._lastFetched === 0) return '';
298300

299-
if (options.format === undefined && Container.config.defaultDateStyle === DateStyle.Relative) {
300-
// If less than a day has passed show a relative date
301-
if (Date.now() - this._lastFetched < Dates.MillisecondsPerDay) {
302-
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).fromNow()}`;
303-
}
301+
// if (options.format === undefined && Container.config.defaultDateStyle === DateStyle.Relative) {
302+
// // If less than a day has passed show a relative date
303+
// if (Date.now() - this._lastFetched < Dates.MillisecondsPerDay) {
304+
// return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).fromNow()}`;
305+
// }
306+
// }
307+
308+
let format = options.format || Container.config.defaultDateShortFormat || 'MMM D, YYYY';
309+
if (
310+
(options.includeTime ||
311+
// If less than a day has passed show the time too
312+
(options.includeTime === undefined && Date.now() - this._lastFetched < Dates.MillisecondsPerDay)) &&
313+
// If the time is already included don't do anything
314+
!hasTimeRegex.test(format)
315+
) {
316+
format = `h:mma, ${format}`;
304317
}
305318

306-
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).format(
307-
options.format || Container.config.defaultDateShortFormat || 'MMM D, YYYY'
308-
)}`;
319+
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).format(format)}`;
309320
}
310321

311-
@debug()
312-
private async updateLastFetched() {
313-
const prevLastFetched = this._lastFetched;
314-
this._lastFetched = await this.repo.getLastFetched();
322+
// @debug()
323+
// private async updateLastFetched() {
324+
// const prevLastFetched = this._lastFetched;
325+
// this._lastFetched = await this.repo.getLastFetched();
315326

316-
// If the fetched date hasn't changed and it was over a day ago, kick out
317-
if (this._lastFetched === prevLastFetched && Date.now() - this._lastFetched >= Dates.MillisecondsPerDay) return;
327+
// // If the fetched date hasn't changed and it was over a day ago, kick out
328+
// if (this._lastFetched === prevLastFetched && Date.now() - this._lastFetched >= Dates.MillisecondsPerDay) return;
318329

319-
this.view.triggerNodeChange(this);
320-
}
330+
// this.view.triggerNodeChange(this);
331+
// }
321332
}

0 commit comments

Comments
 (0)