From a7a92d5e2551e7dfb70c8b763cef78e05be30ccc Mon Sep 17 00:00:00 2001 From: Moshe Feuchtwanger Date: Wed, 31 Jan 2024 20:51:33 +0200 Subject: [PATCH 1/2] feat: compare strategy --- README.md | 2 +- package.json | 22 ++++++++++++++++------ src/services/comparer.ts | 10 ++++++---- src/services/configuration.ts | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d6e1fd6..1e393cc 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,6 @@ There are several ways to choose folders to compare: "**/.git" ] ``` -- `compareContent` - boolean - Compares files by content - `diffViewTitle` - One of the options: "name only", "compared path", "full path" - `ignoreFileNameCase` - boolean - Compare files with the same name but different case - `diffLayout` - One of the options: "local <> compared" or "compared <> local" @@ -63,6 +62,7 @@ There are several ways to choose folders to compare: - `ignoreAllWhiteSpaces` - boolean - ignore all white space differences (similar to `diff -w`) - `ignoreEmptyLines` - boolean - ignore differences caused by empty lines (similar to `diff -B`) - `respectGitIgnore` - boolean - include / exclude files based on .gitignore - this option works together with `includeFilter` and `excludeFilter` options. ⚠️ The extension supports the main basic gitignore rules. For instance, it supports negation (`!`), but it doesn't support .gitignore files in subfolders. If there is an important use case that is not supported, please open an issue. +- `compareStrategy` - One of the options: "content", "size", "date"` - The strategy to use while comparing files. Comparing by `content`, `size` or `date` (last modified time). Default is `content`. ***Example*** ```json diff --git a/package.json b/package.json index 4917b39..cccca14 100644 --- a/package.json +++ b/package.json @@ -61,12 +61,6 @@ "default": "", "scope": "resource" }, - "compareFolders.compareContent": { - "type": "boolean", - "default": true, - "description": "Compare content", - "scope": "resource" - }, "compareFolders.ignoreLineEnding": { "type": "boolean", "default": false, @@ -165,6 +159,22 @@ "default": "true", "description": "Show a warning message before deleting files", "scope": "resource" + }, + "compareFolders.compareStrategy": { + "type": "string", + "default": "content", + "enum": [ + "content", + "size", + "date" + ], + "enumDescriptions": [ + "Compare files by content", + "Compare files by size", + "Compare files by date" + ], + "description": "Compare strategy", + "scope": "resource" } } }, diff --git a/src/services/comparer.ts b/src/services/comparer.ts index 82fbc99..7ab98b2 100644 --- a/src/services/comparer.ts +++ b/src/services/comparer.ts @@ -70,7 +70,6 @@ export async function showFile(file: string) { function getOptions() { const { - compareContent, ignoreFileNameCase, ignoreExtension, ignoreWhiteSpaces, @@ -78,8 +77,8 @@ function getOptions() { ignoreEmptyLines, ignoreLineEnding, respectGitIgnore, + compareStrategy, } = getConfiguration( - 'compareContent', 'ignoreFileNameCase', 'ignoreExtension', 'ignoreWhiteSpaces', @@ -87,13 +86,13 @@ function getOptions() { 'ignoreEmptyLines', 'ignoreLineEnding', 'respectGitIgnore', + 'compareStrategy' ); const { excludeFilter, includeFilter } = getIncludeAndExcludePaths(); const filterHandler = respectGitIgnore ? getGitignoreFilter(...pathContext.getPaths()) : undefined; const options: CompareOptions = { - compareContent, excludeFilter, includeFilter, ignoreCase: ignoreFileNameCase, @@ -105,6 +104,9 @@ function getOptions() { filterHandler, compareFileAsync: fileCompareHandlers.lineBasedFileCompare.compareAsync, compareNameHandler: (ignoreExtension && compareName) || undefined, + compareContent: compareStrategy === 'content', + compareSize: compareStrategy === 'size', + compareDate: compareStrategy === 'date', }; return options; } @@ -119,8 +121,8 @@ export async function compareFolders(): Promise { validatePermissions(folder1Path, folder2Path); const showIdentical = getConfiguration('showIdentical'); const options = getOptions(); + const concatenatedOptions: CompareOptions = { - compareContent: true, handlePermissionDenied: true, ...options, }; diff --git a/src/services/configuration.ts b/src/services/configuration.ts index 6271c44..2a5fd96 100644 --- a/src/services/configuration.ts +++ b/src/services/configuration.ts @@ -3,7 +3,6 @@ import { workspace } from 'vscode'; export type DiffViewTitle = 'name only' | 'compared path' | 'full path'; export interface IConfigurations { - compareContent: boolean; excludeFilter: string[] | undefined; includeFilter: string[] | undefined; diffViewTitle: DiffViewTitle; @@ -20,6 +19,7 @@ export interface IConfigurations { ignoreEmptyLines: boolean; ignoreLineEnding: boolean; respectGitIgnore: boolean; + compareStrategy: 'content' | 'size' | 'date'; } type ConfigurationItem = keyof IConfigurations; From 4da038c2ea6808698fa9db25c55dc03115cc3f6d Mon Sep 17 00:00:00 2001 From: Moshe Feuchtwanger Date: Wed, 31 Jan 2024 20:56:38 +0200 Subject: [PATCH 2/2] fix types --- .../includeExcludeFilesGetter.testkit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/suite/includeExcludeFilesGetter/includeExcludeFilesGetter.testkit.ts b/src/test/suite/includeExcludeFilesGetter/includeExcludeFilesGetter.testkit.ts index 28e870b..b3a55aa 100644 --- a/src/test/suite/includeExcludeFilesGetter/includeExcludeFilesGetter.testkit.ts +++ b/src/test/suite/includeExcludeFilesGetter/includeExcludeFilesGetter.testkit.ts @@ -6,7 +6,6 @@ import { pathContext } from '../../../context/path'; import { globalState } from '../../../services/globalState'; const defaultSettings: Partial = { - compareContent: true, excludeFilter: [], includeFilter: [], diffViewTitle: 'name only', @@ -23,6 +22,7 @@ const defaultSettings: Partial = { ignoreEmptyLines: false, ignoreLineEnding: false, respectGitIgnore: false, + compareStrategy: 'content', }; const contextFactory = (): Partial => {