Преглед изворни кода

Fixes file history on the web

Moves scm git uri creation to local git provider
Removes relative path usages from GitUri
Adds commit.findFile overload for a uri
main
Eric Amodio пре 3 година
родитељ
комит
c49cb274c9
9 измењених фајлова са 56 додато и 57 уклоњено
  1. +29
    -16
      src/env/node/git/localGitProvider.ts
  2. +2
    -2
      src/git/gitProviderService.ts
  3. +4
    -24
      src/git/gitUri.ts
  4. +5
    -3
      src/git/models/commit.ts
  5. +6
    -3
      src/git/models/file.ts
  6. +1
    -1
      src/hovers/hovers.ts
  7. +4
    -4
      src/premium/github/githubGitProvider.ts
  8. +3
    -3
      src/views/nodes/fileHistoryNode.ts
  9. +2
    -1
      src/views/nodes/lineHistoryNode.ts

+ 29
- 16
src/env/node/git/localGitProvider.ts Прегледај датотеку

@ -525,7 +525,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
// Short-circuit if the path is relative
if (typeof pathOrUri === 'string' && !isAbsolute(pathOrUri)) {
return Uri.joinPath(base, pathOrUri);
return Uri.joinPath(base, normalizePath(pathOrUri));
}
const relativePath = this.getRelativePath(pathOrUri, base);
@ -549,7 +549,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
return undefined;
}
if (GitRevision.isUncommittedStaged(ref)) return GitUri.git(path, repoPath);
if (GitRevision.isUncommittedStaged(ref)) return this.getScmGitUri(path, repoPath);
return this.getRevisionUri(repoPath, path, ref);
}
@ -588,7 +588,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
getRevisionUri(repoPath: string, path: string, ref: string): Uri {
if (GitRevision.isUncommitted(ref)) {
return GitRevision.isUncommittedStaged(ref)
? GitUri.git(path, repoPath)
? this.getScmGitUri(path, repoPath)
: this.getAbsoluteUri(path, repoPath);
}
@ -613,20 +613,20 @@ export class LocalGitProvider implements GitProvider, Disposable {
@log()
async getWorkingUri(repoPath: string, uri: Uri) {
let fileName = GitUri.relativeTo(uri, repoPath);
let relativePath = this.getRelativePath(uri, repoPath);
let data;
let ref;
do {
data = await this.git.ls_files(repoPath, fileName);
data = await this.git.ls_files(repoPath, relativePath);
if (data != null) {
fileName = splitSingle(data, '\n')[0];
relativePath = splitSingle(data, '\n')[0];
break;
}
// TODO: Add caching
// Get the most recent commit for this file name
ref = await this.git.log__file_recent(repoPath, fileName, {
ref = await this.git.log__file_recent(repoPath, relativePath, {
ordering: this.container.config.advanced.commitOrdering,
similarityThreshold: this.container.config.advanced.similarityThreshold,
});
@ -642,14 +642,14 @@ export class LocalGitProvider implements GitProvider, Disposable {
});
if (data == null || data.length === 0) break;
const [foundRef, foundFile, foundStatus] = GitLogParser.parseSimpleRenamed(data, fileName);
const [foundRef, foundFile, foundStatus] = GitLogParser.parseSimpleRenamed(data, relativePath);
if (foundStatus === 'D' && foundFile != null) return undefined;
if (foundRef == null || foundFile == null) break;
fileName = foundFile;
relativePath = foundFile;
} while (true);
uri = this.getAbsoluteUri(fileName, repoPath);
uri = this.getAbsoluteUri(relativePath, repoPath);
return (await fsExists(uri.fsPath)) ? uri : undefined;
}
@ -2716,8 +2716,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
filters = ['A'];
}
const fileName = GitUri.relativeTo(uri, repoPath);
let data = await this.git.log__file(repoPath, fileName, ref, {
const relativePath = this.getRelativePath(uri, repoPath);
let data = await this.git.log__file(repoPath, relativePath, ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: filters,
@ -2740,18 +2740,18 @@ export class LocalGitProvider implements GitProvider, Disposable {
// startLine: editorLine != null ? editorLine + 1 : undefined
});
if (data == null || data.length === 0) {
return GitUri.fromFile(file ?? fileName, repoPath, nextRef);
return GitUri.fromFile(file ?? relativePath, repoPath, nextRef);
}
const [nextRenamedRef, renamedFile] = GitLogParser.parseSimpleRenamed(data, file ?? fileName);
const [nextRenamedRef, renamedFile] = GitLogParser.parseSimpleRenamed(data, file ?? relativePath);
return GitUri.fromFile(
renamedFile ?? file ?? fileName,
renamedFile ?? file ?? relativePath,
repoPath,
nextRenamedRef ?? nextRef ?? GitRevision.deletedOrMissing,
);
}
return GitUri.fromFile(file ?? fileName, repoPath, nextRef);
return GitUri.fromFile(file ?? relativePath, repoPath, nextRef);
}
@log()
@ -3646,6 +3646,19 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
private getScmGitUri(path: string, repoPath: string): Uri {
const uri = this.getAbsoluteUri(path, repoPath);
return Uri.from({
scheme: Schemes.Git,
path: uri.path,
query: JSON.stringify({
// Ensure we use the fsPath here, otherwise the url won't open properly
path: uri.fsPath,
ref: '~',
}),
});
}
@log()
async getOpenScmRepositories(): Promise<ScmRepository[]> {
const cc = Logger.getCorrelationContext();

+ 2
- 2
src/git/gitProviderService.ts Прегледај датотеку

@ -25,7 +25,7 @@ import { groupByFilterMap, groupByMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
import { count, filter, first, flatMap, map } from '../system/iterable';
import { dirname, getBestPath, getScheme, isAbsolute, maybeUri } from '../system/path';
import { dirname, getBestPath, getScheme, isAbsolute, maybeUri, normalizePath } from '../system/path';
import { cancellable, isPromise, PromiseCancelledError } from '../system/promise';
import { VisitedPathsTrie } from '../system/trie';
import { GitProvider, GitProviderDescriptor, GitProviderId, PagedResult, ScmRepository } from './gitProvider';
@ -632,7 +632,7 @@ export class GitProviderService implements Disposable {
// Short-circuit if the base is already a Uri and the path is relative
if (typeof base !== 'string' && typeof pathOrUri === 'string' && !isAbsolute(pathOrUri)) {
return Uri.joinPath(base, pathOrUri);
return Uri.joinPath(base, normalizePath(pathOrUri));
}
const { provider } = this.getProvider(base);

+ 4
- 24
src/git/gitUri.ts Прегледај датотеку

@ -7,7 +7,7 @@ import { Logger } from '../logger';
import { GitHubAuthorityMetadata } from '../premium/remotehub';
import { debug } from '../system/decorators/log';
import { memoize } from '../system/decorators/memoize';
import { basename, dirname, isAbsolute, normalizePath, relative } from '../system/path';
import { basename, dirname, normalizePath, relative } from '../system/path';
import { CharCode, truncateLeft, truncateMiddle } from '../system/string';
import { RevisionUriData } from './gitProvider';
import { GitFile, GitRevision } from './models';
@ -344,7 +344,9 @@ export class GitUri extends (Uri as any as UriEx) {
static getDirectory(fileName: string, relativeTo?: string): string {
let directory: string | undefined = dirname(fileName);
directory = relativeTo != null ? GitUri.relativeTo(directory, relativeTo) : normalizePath(directory);
directory = relativeTo
? Container.instance.git.getRelativePath(directory, relativeTo)
: normalizePath(directory);
return directory == null || directory.length === 0 || directory === '.' ? '' : directory;
}
@ -420,28 +422,6 @@ export class GitUri extends (Uri as any as UriEx) {
return `${directory}${file}`;
}
static relativeTo(fileNameOrUri: string | Uri, relativeTo: string | undefined): string {
const fileName = fileNameOrUri instanceof Uri ? fileNameOrUri.fsPath : fileNameOrUri;
const relativePath =
relativeTo == null || relativeTo.length === 0 || !isAbsolute(fileName)
? fileName
: relative(relativeTo, fileName);
return normalizePath(relativePath);
}
static git(path: string, repoPath?: string): Uri {
const uri = Container.instance.git.getAbsoluteUri(path, repoPath);
return Uri.from({
scheme: Schemes.Git,
path: uri.path,
query: JSON.stringify({
// Ensure we use the fsPath here, otherwise the url won't open properly
path: uri.fsPath,
ref: '~',
}),
});
}
static toKey(fileName: string): string;
static toKey(uri: Uri): string;
static toKey(fileNameOrUri: string | Uri): string;

+ 5
- 3
src/git/models/commit.ts Прегледај датотеку

@ -261,14 +261,16 @@ export class GitCommit implements GitRevisionReference {
this._stats = { ...this._stats, changedFiles: changedFiles, additions: additions, deletions: deletions };
}
async findFile(path: string): Promise<GitFileChange | undefined> {
async findFile(path: string): Promise<GitFileChange | undefined>;
async findFile(uri: Uri): Promise<GitFileChange | undefined>;
async findFile(pathOrUri: string | Uri): Promise<GitFileChange | undefined> {
if (this._files == null) {
await this.ensureFullDetails();
if (this._files == null) return undefined;
}
path = this.container.git.getRelativePath(path, this.repoPath);
return this._files.find(f => f.path === path);
const relativePath = this.container.git.getRelativePath(pathOrUri, this.repoPath);
return this._files.find(f => f.path === relativePath);
}
formatDate(format?: string | null) {

+ 6
- 3
src/git/models/file.ts Прегледај датотеку

@ -2,6 +2,7 @@ import { Uri } from 'vscode';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { memoize } from '../../system/decorators/memoize';
import { normalizePath } from '../../system/path';
import { pad, pluralize } from '../../system/string';
import { GitUri } from '../gitUri';
import { GitCommit } from './commit';
@ -83,13 +84,15 @@ export namespace GitFile {
}
export function getOriginalRelativePath(file: GitFile, relativeTo?: string): string {
if (file.originalPath == null || file.originalPath.length === 0) return '';
if (!file.originalPath) return '';
return GitUri.relativeTo(file.originalPath, relativeTo);
return relativeTo
? Container.instance.git.getRelativePath(file.originalPath, relativeTo)
: normalizePath(file.originalPath);
}
export function getRelativePath(file: GitFile, relativeTo?: string): string {
return GitUri.relativeTo(file.path, relativeTo);
return relativeTo ? Container.instance.git.getRelativePath(file.path, relativeTo) : normalizePath(file.path);
}
const statusIconsMap = {

+ 1
- 1
src/hovers/hovers.ts Прегледај датотеку

@ -156,7 +156,7 @@ export namespace Hovers {
previous = '_Working Tree_';
current = '_Unsaved_';
} else {
const file = await fromCommit.findFile(uri.fsPath);
const file = await fromCommit.findFile(uri);
if (file == null) return undefined;
message = `[$(compare-changes)](${DiffWithCommand.getMarkdownCommandArgs({

+ 4
- 4
src/premium/github/githubGitProvider.ts Прегледај датотеку

@ -195,7 +195,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
}
if (typeof pathOrUri === 'string' && !maybeUri(pathOrUri) && !isAbsolute(pathOrUri)) {
return Uri.joinPath(base, pathOrUri);
return Uri.joinPath(base, normalizePath(pathOrUri));
}
const relativePath = this.getRelativePath(pathOrUri, base);
@ -238,8 +238,8 @@ export class GitHubGitProvider implements GitProvider, Disposable {
}
}
relativePath = relative(base.path.slice(1), pathOrUri.path.slice(1));
return normalizePath(relativePath);
relativePath = normalizePath(relative(base.path.slice(1), pathOrUri.path.slice(1)));
return relativePath;
}
getRevisionUri(repoPath: string, path: string, ref: string): Uri {
@ -1038,7 +1038,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
const commit = await this.getCommitForFile(repoPath, uri, { ref: ref });
if (commit == null) return undefined;
return commit.findFile(this.getRelativePath(uri, repoPath));
return commit.findFile(uri);
}
async getLastFetchedTimestamp(_repoPath: string): Promise<number | undefined> {

+ 3
- 3
src/views/nodes/fileHistoryNode.ts Прегледај датотеку

@ -15,7 +15,7 @@ import { gate } from '../../system/decorators/gate';
import { debug } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
import { filterMap, flatMap, map, uniqueBy } from '../../system/iterable';
import { basename, joinPaths } from '../../system/path';
import { basename, getBestPath, joinPaths } from '../../system/path';
import { FileHistoryView } from '../fileHistoryView';
import { CommitNode } from './commitNode';
import { LoadMoreNode, MessageNode } from './common';
@ -157,7 +157,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl
get label() {
// Check if this is a base folder
if (this.folder && this.uri.fileName === '') {
return `${basename(this.uri.fsPath)}${
return `${basename(this.uri.path)}${
this.uri.sha
? ` ${this.uri.sha === GitRevision.deletedOrMissing ? this.uri.shortSha : `(${this.uri.shortSha})`}`
: ''
@ -248,7 +248,7 @@ export class FileHistoryNode extends SubscribeableViewNode impl
@memoize()
private getPathOrGlob() {
return this.folder ? joinPaths(this.uri.fsPath, '*') : this.uri.fsPath;
return this.folder ? joinPaths(getBestPath(this.uri), '*') : getBestPath(this.uri);
}
get hasMore() {

+ 2
- 1
src/views/nodes/lineHistoryNode.ts Прегледај датотеку

@ -16,6 +16,7 @@ import { gate } from '../../system/decorators/gate';
import { debug } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
import { filterMap } from '../../system/iterable';
import { getBestPath } from '../../system/path';
import { FileHistoryView } from '../fileHistoryView';
import { LineHistoryView } from '../lineHistoryView';
import { LoadMoreNode, MessageNode } from './common';
@ -250,7 +251,7 @@ export class LineHistoryNode
private _log: GitLog | undefined;
private async getLog(selection?: Selection) {
if (this._log == null) {
this._log = await this.view.container.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, {
this._log = await this.view.container.git.getLogForFile(this.uri.repoPath, getBestPath(this.uri), {
all: false,
limit: this.limit ?? this.view.config.pageItemLimit,
range: selection ?? this.selection,

||||||
x
 
000:0
Loading…
Откажи
Сачувај