Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compare strategy #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
"default": "",
"scope": "resource"
},
"compareFolders.compareContent": {
"type": "boolean",
"default": true,
"description": "Compare content",
"scope": "resource"
},
"compareFolders.ignoreLineEnding": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -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"
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions src/services/comparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,29 @@ export async function showFile(file: string) {

function getOptions() {
const {
compareContent,
ignoreFileNameCase,
ignoreExtension,
ignoreWhiteSpaces,
ignoreAllWhiteSpaces,
ignoreEmptyLines,
ignoreLineEnding,
respectGitIgnore,
compareStrategy,
} = getConfiguration(
'compareContent',
'ignoreFileNameCase',
'ignoreExtension',
'ignoreWhiteSpaces',
'ignoreAllWhiteSpaces',
'ignoreEmptyLines',
'ignoreLineEnding',
'respectGitIgnore',
'compareStrategy'
);

const { excludeFilter, includeFilter } = getIncludeAndExcludePaths();
const filterHandler = respectGitIgnore ? getGitignoreFilter(...pathContext.getPaths()) : undefined;

const options: CompareOptions = {
compareContent,
excludeFilter,
includeFilter,
ignoreCase: ignoreFileNameCase,
Expand All @@ -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;
}
Expand All @@ -119,8 +121,8 @@ export async function compareFolders(): Promise<CompareResult> {
validatePermissions(folder1Path, folder2Path);
const showIdentical = getConfiguration('showIdentical');
const options = getOptions();

const concatenatedOptions: CompareOptions = {
compareContent: true,
handlePermissionDenied: true,
...options,
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +19,7 @@ export interface IConfigurations {
ignoreEmptyLines: boolean;
ignoreLineEnding: boolean;
respectGitIgnore: boolean;
compareStrategy: 'content' | 'size' | 'date';
}

type ConfigurationItem = keyof IConfigurations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { pathContext } from '../../../context/path';
import { globalState } from '../../../services/globalState';

const defaultSettings: Partial<IConfigurations> = {
compareContent: true,
excludeFilter: [],
includeFilter: [],
diffViewTitle: 'name only',
Expand All @@ -23,6 +22,7 @@ const defaultSettings: Partial<IConfigurations> = {
ignoreEmptyLines: false,
ignoreLineEnding: false,
respectGitIgnore: false,
compareStrategy: 'content',
};

const contextFactory = (): Partial<ExtensionContext> => {
Expand Down