-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
perf(changed-files): limit git and hg commands to specified roots #6732
Changes from 1 commit
33acece
aac709c
8521eb4
dcec626
3647446
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,6 +224,27 @@ test('gets changed files for git', async () => { | |
).toEqual(['file5.txt']); | ||
}); | ||
|
||
test('should only monitor root paths for git', async () => { | ||
writeFiles(DIR, { | ||
'file1.txt': 'file1', | ||
'nested_dir/file2.txt': 'file2', | ||
'nested_dir/second_nested_dir/file3.txt': 'file3', | ||
}); | ||
|
||
run(`${GIT} init`, DIR); | ||
|
||
const roots = ['nested_dir', 'nested_dir/second_nested_dir'].map(filename => | ||
path.resolve(DIR, filename), | ||
); | ||
|
||
const {changedFiles: files} = await getChangedFilesForRoots(roots, {}); | ||
expect( | ||
Array.from(files) | ||
.map(filePath => path.basename(filePath)) | ||
.sort(), | ||
).toEqual(['file2.txt', 'file3.txt']); | ||
}); | ||
|
||
test('gets changed files for hg', async () => { | ||
if (process.env.CI) { | ||
// Circle and Travis have very old version of hg (v2, and current | ||
|
@@ -326,3 +347,31 @@ test('gets changed files for hg', async () => { | |
.sort(), | ||
).toEqual(['file5.txt']); | ||
}); | ||
|
||
test('should only monitor root paths for hg', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should avoid using |
||
if (process.env.CI) { | ||
// Circle and Travis have very old version of hg (v2, and current | ||
// version is v4.2) and its API changed since then and not compatible | ||
// any more. Changing the SCM version on CIs is not trivial, so we'll just | ||
// skip this test and run it only locally. | ||
return; | ||
} | ||
writeFiles(DIR, { | ||
'file1.txt': 'file1', | ||
'nested_dir/file2.txt': 'file2', | ||
'nested_dir/second_nested_dir/file3.txt': 'file3', | ||
}); | ||
|
||
run(`${HG} init`, DIR); | ||
|
||
const roots = ['nested_dir', 'nested_dir/second_nested_dir'].map(filename => | ||
path.resolve(DIR, filename), | ||
); | ||
|
||
const {changedFiles: files} = await getChangedFilesForRoots(roots, {}); | ||
expect( | ||
Array.from(files) | ||
.map(filePath => path.basename(filePath)) | ||
.sort(), | ||
).toEqual(['file2.txt', 'file3.txt']); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,33 +46,44 @@ const findChangedFilesUsingCommand = async ( | |
const adapter: SCMAdapter = { | ||
findChangedFiles: async ( | ||
cwd: string, | ||
roots: Array<Path>, | ||
options?: Options, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the idea that we would keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, ideally with the default behavior being the same as current one (pre this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just pushed the fix. Let me know what you think. Thanks! |
||
): Promise<Array<Path>> => { | ||
const changedSince: ?string = | ||
options && (options.withAncestor ? 'HEAD^' : options.changedSince); | ||
|
||
if (options && options.lastCommit) { | ||
return await findChangedFilesUsingCommand( | ||
['show', '--name-only', '--pretty=%b', 'HEAD'], | ||
['show', '--name-only', '--pretty=%b', 'HEAD'].concat(roots), | ||
cwd, | ||
); | ||
} else if (changedSince) { | ||
const committed = await findChangedFilesUsingCommand( | ||
['log', '--name-only', '--pretty=%b', 'HEAD', `^${changedSince}`], | ||
[ | ||
'log', | ||
'--name-only', | ||
'--pretty=%b', | ||
'HEAD', | ||
`^${changedSince}`, | ||
].concat(roots), | ||
cwd, | ||
); | ||
const staged = await findChangedFilesUsingCommand( | ||
['diff', '--cached', '--name-only'], | ||
['diff', '--cached', '--name-only'].concat(roots), | ||
cwd, | ||
); | ||
const unstaged = await findChangedFilesUsingCommand( | ||
['ls-files', '--other', '--modified', '--exclude-standard'], | ||
['ls-files', '--other', '--modified', '--exclude-standard'].concat( | ||
roots, | ||
), | ||
cwd, | ||
); | ||
return [...committed, ...staged, ...unstaged]; | ||
} else { | ||
return await findChangedFilesUsingCommand( | ||
['ls-files', '--other', '--modified', '--exclude-standard'], | ||
['ls-files', '--other', '--modified', '--exclude-standard'].concat( | ||
roots, | ||
), | ||
cwd, | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like
nested_dir
already includesnested_dir/second_nested_dir
rootThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated / removed redundant root!