Skip to content

Commit

Permalink
refactor: moveDetection has no windows-specific logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jul 16, 2024
1 parent 1453262 commit fe59143
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/shared/local/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import path from 'node:path';
import { WORKDIR, HEAD } from './localShadowRepo';
import { FILE } from './localShadowRepo';

import { StatusRow } from './types';

// filenames were normalized when read from isogit

export const toFilenames = (rows: StatusRow[]): string[] => rows.map((row) => row[FILE]);
export const isDeleted = (status: StatusRow): boolean => status[WORKDIR] === 0;
export const isAdded = (status: StatusRow): boolean => status[HEAD] === 0 && status[WORKDIR] === 2;
export const ensureWindows = (filepath: string): string => path.win32.normalize(filepath);
2 changes: 1 addition & 1 deletion src/shared/local/localShadowRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class ShadowRepo {
if (!matchingFiles.added.size || !matchingFiles.deleted.size) return;

const movedFilesMarker = Performance.mark('@salesforce/source-tracking', 'localShadowRepo.detectMovedFiles');
const matches = await filenameMatchesToMap(IS_WINDOWS)(this.registry)(this.projectPath)(this.gitDir)(matchingFiles);
const matches = await filenameMatchesToMap(this.registry)(this.projectPath)(this.gitDir)(matchingFiles);

if (matches.deleteOnly.size === 0 && matches.fullMatches.size === 0) return movedFilesMarker?.stop();

Expand Down
9 changes: 3 additions & 6 deletions src/shared/local/moveDetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as fs from 'graceful-fs';
import { Performance } from '@oclif/core/performance';
import { isDefined } from '../guards';
import { uniqueArrayConcat } from '../functions';
import { isDeleted, isAdded, ensureWindows, toFilenames } from './functions';
import { isDeleted, isAdded, toFilenames } from './functions';
import { AddAndDeleteMaps, DetectionFileInfo, DetectionFileInfoWithType, StatusRow, StringMap } from './types';

const JOIN_CHAR = '#__#'; // the __ makes it unlikely to be used in metadata names
Expand All @@ -38,15 +38,12 @@ type StringMapsForMatches = {

/** composed functions to simplified use by the shadowRepo class */
export const filenameMatchesToMap =
(isWindows: boolean) =>
(registry: RegistryAccess) =>
(projectPath: string) =>
(gitDir: string) =>
async ({ added, deleted }: AddedAndDeletedFilenames): Promise<StringMapsForMatches> => {
const resolver = getResolverForFilenames(registry)(
// TODO: use set.union when node 22 is everywhere
isWindows ? uniqueArrayConcat(added, deleted).map(ensureWindows) : uniqueArrayConcat(added, deleted)
);
// TODO: use set.union when node 22 is everywhere
const resolver = getResolverForFilenames(registry)(uniqueArrayConcat(added, deleted));

return compareHashes(
await buildMaps(
Expand Down

0 comments on commit fe59143

Please sign in to comment.