Skip to content

Commit

Permalink
Fixes #607 - adds more uniqueness to view node ids
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jan 4, 2019
1 parent 7ea3489 commit c904f99
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- 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

## [9.3.0] - 2019-01-02
Expand Down
8 changes: 5 additions & 3 deletions src/views/nodes/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export class BranchNode extends ViewRefNode<RepositoriesView> implements Pageabl
}

get id(): string {
return `gitlens:repository(${this.branch.repoPath})${this._root ? ':root:' : ''}:branch(${this.branch.name})${
this.branch.current ? '+current:' : ''
}${this.branch.remote ? '+remote' : ''}${this.branch.starred ? '+starred:' : ''}`;
return `${this._instanceId}:gitlens:repository(${this.branch.repoPath})${this._root ? ':root:' : ''}:branch(${
this.branch.name
})${this.branch.current ? '+current:' : ''}${this.branch.remote ? '+remote' : ''}${
this.branch.starred ? '+starred:' : ''
}`;
}

get current(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/branchOrTagFolderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class BranchOrTagFolderNode extends ViewNode {
}

get id(): string {
return `gitlens:repository(${this.repoPath}):${this.type}-folder(${this.relativePath})`;
return `${this._instanceId}:gitlens:repository(${this.repoPath}):${this.type}-folder(${this.relativePath})`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/branchTrackingStatusNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class BranchTrackingStatusNode extends ViewNode<ViewWithFiles> implements
}

get id(): string {
return `gitlens:repository(${this.status.repoPath}):${this._root ? 'root:' : ''}branch(${
return `${this._instanceId}:gitlens:repository(${this.status.repoPath}):${this._root ? 'root:' : ''}branch(${
this.status.ref
}):status:upstream:(${this.status.upstream}):${this.direction}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/branchesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class BranchesNode extends ViewNode<RepositoriesView> {
}

get id(): string {
return `gitlens:repository(${this.repo.path}):branches`;
return `${this._instanceId}:gitlens:repository(${this.repo.path}):branches`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/remoteNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class RemoteNode extends ViewNode<RepositoriesView> {
}

get id(): string {
return `gitlens:repository(${this.remote.repoPath}):remote(${this.remote.name})`;
return `${this._instanceId}:gitlens:repository(${this.remote.repoPath}):remote(${this.remote.name})`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/remotesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class RemotesNode extends ViewNode<RepositoriesView> {
}

get id(): string {
return `gitlens:repository(${this.repo.path}):remotes`;
return `${this._instanceId}:gitlens:repository(${this.repo.path}):remotes`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
7 changes: 4 additions & 3 deletions src/views/nodes/repositoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
}

get id(): string {
return `gitlens:repository(${this.repo.path})${this.repo.starred ? '+starred:' : ''}`;
return `${this._instanceId}:gitlens:repository(${this.repo.path})${this.repo.starred ? '+starred:' : ''}`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down Expand Up @@ -238,9 +238,10 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
@debug({
args: {
0: (e: RepositoryFileSystemChangeEvent) =>
`{ repository: ${e.repository ? e.repository.name : ''}, uris: [${e.uris
`{ repository: ${e.repository ? e.repository.name : ''}, uris(${e.uris.length}): [${e.uris
.slice(0, 1)
.map(u => u.fsPath)
.join(', ')}] }`
.join(', ')}${e.uris.length > 1 ? ', ...' : ''}] }`
}
})
private onFileSystemChanged(e: RepositoryFileSystemChangeEvent) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/stashNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class StashNode extends ViewRefNode {
}

get id(): string {
return `gitlens:repository(${this.commit.repoPath}):stash(${this.commit.sha})`;
return `${this._instanceId}:gitlens:repository(${this.commit.repoPath}):stash(${this.commit.sha})`;
}

get ref(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/stashesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class StashesNode extends ViewNode {
}

get id(): string {
return `gitlens:repository(${this.repo.path}):stashes`;
return `${this._instanceId}:gitlens:repository(${this.repo.path}):stashes`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/statusFilesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class StatusFilesNode extends ViewNode<RepositoriesView> {
}

get id(): string {
return `gitlens:repository(${this.status.repoPath}):status:files`;
return `${this._instanceId}:gitlens:repository(${this.status.repoPath}):status:files`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/tagNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class TagNode extends ViewRefNode<RepositoriesView> implements PageableVi
}

get id(): string {
return `gitlens:repository(${this.tag.repoPath}):tag(${this.tag.name})`;
return `${this._instanceId}:gitlens:repository(${this.tag.repoPath}):tag(${this.tag.name})`;
}

get label(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/tagsNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TagsNode extends ViewNode<RepositoriesView> {
}

get id(): string {
return `gitlens:repository(${this.repo.path}):tags`;
return `${this._instanceId}:gitlens:repository(${this.repo.path}):tags`;
}

async getChildren(): Promise<ViewNode[]> {
Expand Down
14 changes: 13 additions & 1 deletion src/views/nodes/viewNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ export interface ViewNode {
readonly id?: string;
}

@logName<ViewNode>((c, name) => `${name}${c.id ? `(${c.id})` : ''}`)
let counter = 0;
function getViewNodeInstanceId() {
if (counter === Number.MAX_SAFE_INTEGER) {
counter = 0;
}
counter++;
return counter;
}

@logName<ViewNode>((c, name) => `${name}(${c.id || c._instanceId})`)
export abstract class ViewNode<TView extends View = View> {
protected readonly _instanceId: number;

constructor(
uri: GitUri,
public readonly view: TView,
protected readonly parent?: ViewNode
) {
this._instanceId = getViewNodeInstanceId();
this._uri = uri;
}

Expand Down

0 comments on commit c904f99

Please sign in to comment.