Browse Source

Adds relative date markers to history in explorers

main
Eric Amodio 6 years ago
parent
commit
c2ca69d267
13 changed files with 119 additions and 16 deletions
  1. +2
    -0
      src/git/git.ts
  2. +3
    -0
      src/git/models/logCommit.ts
  3. +4
    -0
      src/git/models/stashCommit.ts
  4. +6
    -0
      src/git/parsers/logParser.ts
  5. +6
    -0
      src/git/parsers/stashParser.ts
  6. +2
    -0
      src/quickpicks/repoStatusQuickPick.ts
  7. +8
    -4
      src/views/nodes/branchNode.ts
  8. +8
    -3
      src/views/nodes/fileHistoryNode.ts
  9. +53
    -0
      src/views/nodes/helpers.ts
  10. +13
    -4
      src/views/nodes/lineHistoryNode.ts
  11. +1
    -0
      src/views/nodes/statusFilesNode.ts
  12. +10
    -3
      src/views/nodes/statusUpstreamNode.ts
  13. +3
    -2
      src/views/nodes/tagNode.ts

+ 2
- 0
src/git/git.ts View File

@ -25,6 +25,7 @@ const logFormat = [
`${lb}a${rb} %aN`, // author
`${lb}e${rb} %aE`, // email
`${lb}d${rb} %at`, // date
`${lb}c${rb} %ct`, // committed date
`${lb}p${rb} %P`, // parents
`${lb}s${rb}`,
`%B`, // summary
@ -38,6 +39,7 @@ const stashFormat = [
`${lb}${sl}f${rb}`,
`${lb}r${rb} %H`, // ref
`${lb}d${rb} %at`, // date
`${lb}c${rb} %ct`, // committed date
`${lb}l${rb} %gd`, // reflog-selector
`${lb}s${rb}`,
`%B`, // summary

+ 3
- 0
src/git/models/logCommit.ts View File

@ -17,6 +17,7 @@ export class GitLogCommit extends GitCommit {
author: string,
email: string | undefined,
date: Date,
public readonly committedDate: Date,
message: string,
fileName: string,
public readonly files: GitFile[],
@ -168,6 +169,7 @@ export class GitLogCommit extends GitCommit {
author?: string;
email?: string;
date?: Date;
committedDate?: Date;
message?: string;
originalFileName?: string | null;
previousFileName?: string | null;
@ -182,6 +184,7 @@ export class GitLogCommit extends GitCommit {
changes.author || this.author,
changes.email || this.email,
changes.date || this.date,
changes.committedDate || this.committedDate,
changes.message || this.message,
changes.fileName || this.fileName,
this.getChangedValue(changes.files, this.files) || [],

+ 4
- 0
src/git/models/stashCommit.ts View File

@ -10,6 +10,7 @@ export class GitStashCommit extends GitLogCommit {
repoPath: string,
sha: string,
date: Date,
committedDate: Date,
message: string,
fileName: string,
files: GitFile[],
@ -25,6 +26,7 @@ export class GitStashCommit extends GitLogCommit {
'You',
undefined,
date,
committedDate,
message,
fileName,
files,
@ -44,6 +46,7 @@ export class GitStashCommit extends GitLogCommit {
sha?: string | null;
fileName?: string;
date?: Date;
committedDate?: Date;
message?: string;
originalFileName?: string | null;
previousFileName?: string | null;
@ -57,6 +60,7 @@ export class GitStashCommit extends GitLogCommit {
this.repoPath,
this.getChangedValue(changes.sha, this.sha)!,
changes.date || this.date,
changes.committedDate || this.committedDate,
changes.message || this.message,
changes.fileName || this.fileName,
this.getChangedValue(changes.files, this.files) || [],

+ 6
- 0
src/git/parsers/logParser.ts View File

@ -9,6 +9,7 @@ interface LogEntry {
author?: string;
date?: string;
committedDate?: string;
email?: string;
parentShas?: string[];
@ -98,6 +99,10 @@ export class GitLogParser {
entry.date = line.substring(4);
break;
case 99: // 'c': // committer-date
entry.committedDate = line.substring(4);
break;
case 112: // 'p': // parents
entry.parentShas = line.substring(4).split(' ');
break;
@ -283,6 +288,7 @@ export class GitLogParser {
entry.author!,
entry.email,
new Date((entry.date! as any) * 1000),
new Date((entry.committedDate! as any) * 1000),
entry.summary === undefined ? '' : entry.summary,
relativeFileName,
entry.files || [],

+ 6
- 0
src/git/parsers/stashParser.ts View File

@ -6,6 +6,7 @@ import { GitCommitType, GitFile, GitFileStatus, GitLogParser, GitStash, GitStash
interface StashEntry {
ref?: string;
date?: string;
committedDate?: string;
fileNames?: string;
files?: GitFile[];
summary?: string;
@ -54,6 +55,10 @@ export class GitStashParser {
entry.date = line.substring(4);
break;
case 99: // 'c': // committer-date
entry.committedDate = line.substring(4);
break;
case 108: // 'l': // reflog-selector
entry.stashName = line.substring(4);
break;
@ -140,6 +145,7 @@ export class GitStashParser {
repoPath,
entry.ref!,
new Date((entry.date! as any) * 1000),
new Date((entry.committedDate! as any) * 1000),
entry.summary === undefined ? '' : entry.summary,
entry.fileNames!,
entry.files || []

+ 2
- 0
src/quickpicks/repoStatusQuickPick.ts View File

@ -58,6 +58,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
'You',
undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
@ -75,6 +76,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
'You',
undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],

+ 8
- 4
src/views/nodes/branchNode.ts View File

@ -9,6 +9,7 @@ import { RepositoriesExplorer } from '../repositoriesExplorer';
import { CommitNode } from './commitNode';
import { MessageNode, ShowMoreNode } from './common';
import { ExplorerNode, ExplorerRefNode, PageableExplorerNode, ResourceType } from './explorerNode';
import { insertDateMarkers } from './helpers';
export class BranchNode extends ExplorerRefNode implements PageableExplorerNode {
readonly supportsPaging: boolean = true;
@ -70,10 +71,13 @@ export class BranchNode extends ExplorerRefNode implements PageableExplorerNode
return branches.join(', ');
};
const children: (CommitNode | ShowMoreNode)[] = [
...Iterables.map(
log.commits.values(),
c => new CommitNode(c, this, this.explorer, this.branch, getBranchTips)
const children = [
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitNode(c, this, this.explorer, this.branch, getBranchTips)
),
this
)
];

+ 8
- 3
src/views/nodes/fileHistoryNode.ts View File

@ -16,6 +16,7 @@ import { FileHistoryExplorer } from '../fileHistoryExplorer';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { MessageNode } from './common';
import { ExplorerNode, ResourceType, SubscribeableExplorerNode } from './explorerNode';
import { insertDateMarkers } from './helpers';
export class FileHistoryNode extends SubscribeableExplorerNode<FileHistoryExplorer> {
constructor(uri: GitUri, parent: ExplorerNode, explorer: FileHistoryExplorer) {
@ -55,6 +56,7 @@ export class FileHistoryNode extends SubscribeableExplorerNode
'You',
user !== undefined ? user.email : undefined,
new Date(),
new Date(),
'',
status.fileName,
[status],
@ -69,9 +71,12 @@ export class FileHistoryNode extends SubscribeableExplorerNode
const log = await Container.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, { ref: this.uri.sha });
if (log !== undefined) {
children.push(
...Iterables.map(
log.commits.values(),
c => new CommitFileNode(c.files[0], c, this, this.explorer, displayAs)
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitFileNode(c.files[0], c, this, this.explorer, displayAs)
),
this
)
);
}

+ 53
- 0
src/views/nodes/helpers.ts View File

@ -0,0 +1,53 @@
'use strict';
import { GitLogCommit } from '../../git/gitService';
import { MessageNode } from './common';
import { ExplorerNode } from './explorerNode';
const markers: [number, string][] = [
[0, 'Less than a week ago'],
[7, 'Over a week ago'],
[30, 'Over a month ago'],
[90, 'Over 3 months ago']
];
export function* insertDateMarkers(
iterable: Iterable<ExplorerNode & { commit: GitLogCommit }>,
parent: ExplorerNode,
skip?: number
): Iterable<ExplorerNode> {
let index = skip || 0;
let time = undefined;
const now = Date.now();
for (const node of iterable) {
if (index < markers.length) {
let [daysAgo, marker] = markers[index];
if (time === undefined) {
const date = new Date(now);
time = date.setDate(date.getDate() - daysAgo);
}
const date = new Date(node.commit.committedDate.setUTCHours(0, 0, 0, 0)).getTime();
if (date <= time) {
while (index < markers.length - 1) {
[daysAgo] = markers[index + 1];
const nextDate = new Date(now);
const nextTime = nextDate.setDate(nextDate.getDate() - daysAgo);
if (date > nextTime) break;
index++;
time = undefined;
[, marker] = markers[index];
}
yield new MessageNode(parent, marker);
index++;
time = undefined;
}
}
yield node;
}
}

+ 13
- 4
src/views/nodes/lineHistoryNode.ts View File

@ -15,6 +15,7 @@ import { LineHistoryExplorer } from '../lineHistoryExplorer';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { MessageNode } from './common';
import { ExplorerNode, ResourceType, SubscribeableExplorerNode } from './explorerNode';
import { insertDateMarkers } from './helpers';
export class LineHistoryNode extends SubscribeableExplorerNode<LineHistoryExplorer> {
constructor(
@ -39,16 +40,22 @@ export class LineHistoryNode extends SubscribeableExplorerNode
});
if (log !== undefined) {
children.push(
...Iterables.filterMap(
log.commits.values(),
c => new CommitFileNode(c.files[0], c, this, this.explorer, displayAs, this.selection)
...insertDateMarkers(
Iterables.filterMap(
log.commits.values(),
c => new CommitFileNode(c.files[0], c, this, this.explorer, displayAs, this.selection)
),
this
)
);
}
const blame = await Container.git.getBlameForLine(this.uri, this.selection.active.line);
if (blame !== undefined) {
const first = children[0] as CommitFileNode | undefined;
let first = children[0] as CommitFileNode | undefined;
if (first !== undefined && !(first instanceof CommitFileNode)) {
first = children[1] as CommitFileNode | undefined;
}
if (first === undefined || first.commit.sha !== blame.commit.sha) {
const file: GitFile = {
@ -67,6 +74,8 @@ export class LineHistoryNode extends SubscribeableExplorerNode
'You',
blame.commit.email,
blame.commit.date,
// TODO: Add committed date to blame?
blame.commit.date,
blame.commit.message,
blame.commit.fileName,
[file],

+ 1
- 0
src/views/nodes/statusFilesNode.ts View File

@ -165,6 +165,7 @@ export class StatusFilesNode extends ExplorerNode {
'You',
undefined,
date || new Date(),
date || new Date(),
'',
file.fileName,
[file],

+ 10
- 3
src/views/nodes/statusUpstreamNode.ts View File

@ -7,6 +7,7 @@ import { RepositoriesExplorer } from '../repositoriesExplorer';
import { CommitNode } from './commitNode';
import { ShowMoreNode } from './common';
import { ExplorerNode, PageableExplorerNode, ResourceType } from './explorerNode';
import { insertDateMarkers } from './helpers';
export class StatusUpstreamNode extends ExplorerNode implements PageableExplorerNode {
readonly supportsPaging: boolean = true;
@ -37,7 +38,7 @@ export class StatusUpstreamNode extends ExplorerNode implements PageableExplorer
});
if (log === undefined) return [];
let children: (CommitNode | ShowMoreNode)[];
let children;
if (ahead) {
// Since the last commit when we are looking 'ahead' can have no previous (because of the range given) -- look it up
const commits = [...log.commits.values()];
@ -49,10 +50,16 @@ export class StatusUpstreamNode extends ExplorerNode implements PageableExplorer
}
}
children = commits.map(c => new CommitNode(c, this, this.explorer));
children = [...insertDateMarkers(commits.map(c => new CommitNode(c, this, this.explorer)), this, 1)];
}
else {
children = [...Iterables.map(log.commits.values(), c => new CommitNode(c, this, this.explorer))];
children = [
...insertDateMarkers(
Iterables.map(log.commits.values(), c => new CommitNode(c, this, this.explorer)),
this,
1
)
];
}
if (log.truncated) {

+ 3
- 2
src/views/nodes/tagNode.ts View File

@ -8,6 +8,7 @@ import { RepositoriesExplorer } from '../repositoriesExplorer';
import { CommitNode } from './commitNode';
import { MessageNode, ShowMoreNode } from './common';
import { ExplorerNode, ExplorerRefNode, PageableExplorerNode, ResourceType } from './explorerNode';
import { insertDateMarkers } from './helpers';
export class TagNode extends ExplorerRefNode implements PageableExplorerNode {
readonly supportsPaging: boolean = true;
@ -43,8 +44,8 @@ export class TagNode extends ExplorerRefNode implements PageableExplorerNode {
});
if (log === undefined) return [new MessageNode(this, 'No commits yet')];
const children: (CommitNode | ShowMoreNode)[] = [
...Iterables.map(log.commits.values(), c => new CommitNode(c, this, this.explorer))
const children = [
...insertDateMarkers(Iterables.map(log.commits.values(), c => new CommitNode(c, this, this.explorer)), this)
];
if (log.truncated) {

Loading…
Cancel
Save