Skip to content

Commit bb6bce0

Browse files
committed
Improves remote parsing w/ provider integrations
Refs: #2803 (reply in thread)
1 parent e02d0c8 commit bb6bce0

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

CHANGELOG.md

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

1111
- Changes _Compact Graph Column Layout_ context menu command to _Use Compact Graph Column_ for better clarity
1212
- Changes _Default Graph Column Layout_ context menu command to _Use Expanded Graph Column_ for better clarity
13+
- Improves remote parsing for better integration support for some edge cases
1314

1415
## [14.1.1] - 2023-07-18
1516

src/git/models/remote.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,21 @@ export class GitRemote<TProvider extends RemoteProvider | undefined = RemoteProv
5454
);
5555
}
5656

57+
get domain() {
58+
return this.provider?.domain ?? this._domain;
59+
}
60+
61+
get path() {
62+
return this.provider?.path ?? this._path;
63+
}
64+
5765
constructor(
5866
public readonly repoPath: string,
5967
public readonly id: string,
6068
public readonly name: string,
6169
public readonly scheme: string,
62-
public readonly domain: string,
63-
public readonly path: string,
70+
private readonly _domain: string,
71+
private readonly _path: string,
6472
public readonly provider: TProvider,
6573
public readonly urls: { type: GitRemoteType; url: string }[],
6674
) {}

src/git/parsers/remoteParser.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export class GitRemoteParser {
1717
): GitRemote[] | undefined {
1818
if (!data) return undefined;
1919

20-
const remotes: GitRemote[] = [];
21-
const groups = Object.create(null) as Record<string, GitRemote | undefined>;
20+
const remotes = new Map<string, GitRemote>();
2221

2322
let name;
2423
let url;
@@ -28,7 +27,6 @@ export class GitRemoteParser {
2827
let domain;
2928
let path;
3029

31-
let uniqueness;
3230
let remote: GitRemote | undefined;
3331

3432
let match;
@@ -38,37 +36,50 @@ export class GitRemoteParser {
3836

3937
[, name, url, type] = match;
4038

39+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
40+
name = ` ${name}`.substr(1);
4141
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
4242
url = ` ${url}`.substr(1);
43+
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
44+
type = ` ${type}`.substr(1);
4345

4446
[scheme, domain, path] = parseGitRemoteUrl(url);
4547

46-
uniqueness = `${domain ? `${domain}/` : ''}${path}`;
47-
remote = groups[uniqueness];
48-
if (remote === undefined) {
48+
remote = remotes.get(name);
49+
if (remote == null) {
50+
remote = new GitRemote(
51+
repoPath,
52+
`${domain ? `${domain}/` : ''}${path}`,
53+
name,
54+
scheme,
55+
domain,
56+
path,
57+
remoteProviderMatcher(url, domain, path),
58+
[{ url: url, type: type as GitRemoteType }],
59+
);
60+
remotes.set(name, remote);
61+
} else {
62+
remote.urls.push({ url: url, type: type as GitRemoteType });
63+
if (remote.provider != null && type !== 'push') continue;
64+
4965
const provider = remoteProviderMatcher(url, domain, path);
66+
if (provider == null) continue;
5067

5168
remote = new GitRemote(
5269
repoPath,
53-
uniqueness,
54-
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
55-
` ${name}`.substr(1),
70+
`${domain ? `${domain}/` : ''}${path}`,
71+
name,
5672
scheme,
57-
provider !== undefined ? provider.domain : domain,
58-
provider !== undefined ? provider.path : path,
73+
domain,
74+
path,
5975
provider,
60-
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
61-
[{ url: url, type: ` ${type}`.substr(1) as GitRemoteType }],
76+
remote.urls,
6277
);
63-
remotes.push(remote);
64-
groups[uniqueness] = remote;
65-
} else {
66-
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
67-
remote.urls.push({ url: url, type: ` ${type}`.substr(1) as GitRemoteType });
78+
remotes.set(name, remote);
6879
}
6980
} while (true);
7081

71-
return remotes;
82+
return [...remotes.values()];
7283
}
7384
}
7485

0 commit comments

Comments
 (0)