Skip to content

Commit 85f704a

Browse files
committed
Avoids remapping compares to shas on validation
1 parent c67b974 commit 85f704a

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/uris/deepLinks/deepLinkService.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,33 @@ export class DeepLinkService implements Disposable {
183183
return undefined;
184184
}
185185

186-
private async getShasForComparison(
186+
private async getRefsForComparison(
187187
targetId: string,
188188
secondaryTargetId: string,
189189
): Promise<[string, string] | undefined> {
190+
const ref1 = (await this.validateComparisonRef(targetId)) ? targetId : undefined;
191+
if (ref1 == null) return undefined;
192+
const ref2 = (await this.validateComparisonRef(secondaryTargetId)) ? secondaryTargetId : undefined;
193+
if (ref2 == null) return undefined;
194+
return [ref1, ref2];
195+
}
196+
197+
private async validateComparisonRef(ref: string) {
190198
// try treating each id as a commit sha first, then a branch if that fails, then a tag if that fails.
191199
// Note: a blank target id will be treated as 'Working Tree' and will resolve to a blank Sha.
192-
const sha1 =
193-
targetId === ''
194-
? targetId
195-
: (await this.getShaForCommit(targetId)) ??
196-
(await this.getShaForBranch(targetId)) ??
197-
(await this.getShaForTag(targetId));
198-
if (sha1 == null) return undefined;
199-
const sha2 =
200-
secondaryTargetId === ''
201-
? secondaryTargetId
202-
: (await this.getShaForCommit(secondaryTargetId)) ??
203-
(await this.getShaForBranch(secondaryTargetId)) ??
204-
(await this.getShaForTag(secondaryTargetId));
205-
if (sha2 == null) return undefined;
206-
return [sha1, sha2];
200+
201+
if (ref === '') return true;
202+
203+
if (isSha(ref)) return (await this.getShaForCommit(ref)) != null;
204+
205+
const normalized = ref.toLocaleLowerCase();
206+
if (!normalized.startsWith('refs/tags/') && !normalized.startsWith('tags/')) {
207+
const branch = await this.getShaForBranch(ref);
208+
if (branch != null) return true;
209+
}
210+
211+
const tag = await this.getShaForTag(ref);
212+
return tag != null;
207213
}
208214

209215
private async getShasForTargets(): Promise<string | string[] | undefined> {
@@ -223,7 +229,7 @@ export class DeepLinkService implements Disposable {
223229

224230
if (targetType === DeepLinkType.Comparison) {
225231
if (secondaryTargetId == null) return undefined;
226-
return this.getShasForComparison(targetId, secondaryTargetId);
232+
return this.getRefsForComparison(targetId, secondaryTargetId);
227233
}
228234

229235
return undefined;

0 commit comments

Comments
 (0)