Browse Source

Fixes coerced stats type

main
Eric Amodio 1 year ago
parent
commit
f63520bbef
4 changed files with 27 additions and 10 deletions
  1. +9
    -1
      src/git/models/commit.ts
  2. +2
    -5
      src/plus/github/githubGitProvider.ts
  3. +8
    -2
      src/plus/webviews/timeline/timelineWebview.ts
  4. +8
    -2
      src/plus/webviews/timeline/timelineWebviewView.ts

+ 9
- 1
src/git/models/commit.ts View File

@ -364,7 +364,7 @@ export class GitCommit implements GitRevisionReference {
if (stats == null) return options?.empty ?? '';
const { changedFiles, additions, deletions } = stats;
if (changedFiles <= 0 && additions <= 0 && deletions <= 0) return options?.empty ?? '';
if (getChangedFilesCount(changedFiles) <= 0 && additions <= 0 && deletions <= 0) return options?.empty ?? '';
const {
compact = false,
@ -650,6 +650,14 @@ export interface GitCommitStats {
readonly changedFiles: number | { added: number; deleted: number; changed: number };
}
export function getChangedFilesCount(changedFiles: GitCommitStats['changedFiles'] | undefined): number {
if (changedFiles == null) return 0;
return typeof changedFiles === 'number'
? changedFiles
: changedFiles.added + changedFiles.changed + changedFiles.deleted;
}
export interface GitStashCommit extends GitCommit {
readonly refType: GitStashReference['refType'];
readonly stashName: string;

+ 2
- 5
src/plus/github/githubGitProvider.ts View File

@ -41,7 +41,7 @@ import type { GitBlame, GitBlameAuthor, GitBlameLine, GitBlameLines } from '../.
import type { BranchSortOptions } from '../../git/models/branch';
import { getBranchId, GitBranch, sortBranches } from '../../git/models/branch';
import type { GitCommitLine } from '../../git/models/commit';
import { GitCommit, GitCommitIdentity } from '../../git/models/commit';
import { getChangedFilesCount, GitCommit, GitCommitIdentity } from '../../git/models/commit';
import { GitContributor } from '../../git/models/contributor';
import type { GitDiff, GitDiffFilter, GitDiffHunkLine, GitDiffShortStat } from '../../git/models/diff';
import type { GitFile } from '../../git/models/file';
@ -867,10 +867,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
const { stats } = commit;
const changedFiles =
typeof stats.changedFiles === 'number'
? stats.changedFiles
: stats.changedFiles.added + stats.changedFiles.changed + stats.changedFiles.deleted;
const changedFiles = getChangedFilesCount(stats.changedFiles);
return { additions: stats.additions, deletions: stats.deletions, changedFiles: changedFiles };
}

+ 8
- 2
src/plus/webviews/timeline/timelineWebview.ts View File

@ -7,6 +7,7 @@ import { Commands, ContextKeys } from '../../../constants';
import type { Container } from '../../../container';
import { PlusFeatures } from '../../../features';
import { GitUri } from '../../../git/gitUri';
import { getChangedFilesCount } from '../../../git/models/commit';
import type { RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
import { registerCommand } from '../../../system/command';
@ -234,7 +235,10 @@ export class TimelineWebview extends WebviewBase {
}
let queryRequiredCommits = [
...filter(log.commits.values(), c => c.file?.stats == null && c.stats?.changedFiles !== 1),
...filter(
log.commits.values(),
c => c.file?.stats == null && getChangedFilesCount(c.stats?.changedFiles) !== 1,
),
];
if (queryRequiredCommits.length !== 0) {
@ -259,7 +263,9 @@ export class TimelineWebview extends WebviewBase {
const dataset: Commit[] = [];
for (const commit of log.commits.values()) {
const stats = commit.file?.stats ?? (commit.stats?.changedFiles === 1 ? commit.stats : undefined);
const stats =
commit.file?.stats ??
(getChangedFilesCount(commit.stats?.changedFiles) === 1 ? commit.stats : undefined);
dataset.push({
author: commit.author.name === 'You' ? name : commit.author.name,
additions: stats?.additions,

+ 8
- 2
src/plus/webviews/timeline/timelineWebviewView.ts View File

@ -8,6 +8,7 @@ import type { FileSelectedEvent } from '../../../eventBus';
import { PlusFeatures } from '../../../features';
import type { RepositoriesChangeEvent } from '../../../git/gitProviderService';
import { GitUri } from '../../../git/gitUri';
import { getChangedFilesCount } from '../../../git/models/commit';
import type { RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
import { registerCommand } from '../../../system/command';
@ -279,7 +280,10 @@ export class TimelineWebviewView extends WebviewViewBase {
}
let queryRequiredCommits = [
...filter(log.commits.values(), c => c.file?.stats == null && c.stats?.changedFiles !== 1),
...filter(
log.commits.values(),
c => c.file?.stats == null && getChangedFilesCount(c.stats?.changedFiles) !== 1,
),
];
if (queryRequiredCommits.length !== 0) {
@ -304,7 +308,9 @@ export class TimelineWebviewView extends WebviewViewBase {
const dataset: Commit[] = [];
for (const commit of log.commits.values()) {
const stats = commit.file?.stats ?? (commit.stats?.changedFiles === 1 ? commit.stats : undefined);
const stats =
commit.file?.stats ??
(getChangedFilesCount(commit.stats?.changedFiles) === 1 ? commit.stats : undefined);
dataset.push({
author: commit.author.name === 'You' ? name : commit.author.name,
additions: stats?.additions,

Loading…
Cancel
Save