git-lfs/lfs
Chris Darroch 4ff03089e0 commands,lfs,t: scan refs by tree when pruning
In commit d2221dcecacc6a2ad38ffd2e429fca18805cb4ea of PR #2851
the "git lfs prune" command was changed to respect the
"lfs.fetchexclude" configuration option such that objects would
always be pruned if they were referenced by files whose paths
matched one of the patterns in the configuration option (unless
they were referenced by an unpushed commit).

However, this filter is applied using the GitScanner.ScanRef()
method, which indirectly utilizes the internal scanRefsToChan()
function, and that function only visits unique OIDs a single
time each, even if they are referenced by multiple tree entries
(i.e., if there are multiple files with the same content).

This means that if an LFS object appears in both a file that
matches a pattern from "lfs.fetchexclude" and in a file that
does not match, the object may be pruned if the file path seen
during the scan is the matching one regardless of whether the
non-matching file would otherwise have its object retained.

To resolve this we change the pruneTaskGetRetainedAtRef()
function to use the GitScanner.ScanTree() method instead of
ScanRef(), because ScanTree() visits all file paths in each
commit.  We need to pass our callback to the ScanTree() method
so that we can save all non-matching files' OIDs into our list
of OIDs to be retained; therefore we need to add a callback
argument to ScanTree() in the same manner as is done for
ScanRef() and various other GitScanner methods.

We also introduce additional checks in our "prune all excluded
paths" test to ensure that we always retain objects when they
appear in a commit to be retained and at least one of the files
referencing that object ID does not match the "lfs.fetchexclude"
filter.
2022-04-27 20:25:13 -07:00
..
attribute.go avoid extra message format parsing where possible 2022-01-29 22:32:58 -08:00
config_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
config.go Set package version to v3 2021-09-02 20:41:08 +00:00
diff_index_scanner.go make additional message strings translatable 2022-01-29 22:36:19 -08:00
extension.go subprocess: report errors when finding executables 2022-04-19 09:45:20 -07:00
gitfilter_clean.go Set package version to v3 2021-09-02 20:41:08 +00:00
gitfilter_smudge.go make additional message strings translatable 2022-01-29 22:36:19 -08:00
gitfilter.go commands,git,lfs: rename left/right RefUpdate vars 2022-02-06 21:32:27 -08:00
gitscanner_catfilebatch.go lfs: make strings translatable 2022-01-18 17:05:02 +00:00
gitscanner_catfilebatchcheck.go use backticks around commands in messages 2022-01-29 22:35:10 -08:00
gitscanner_catfilebatchcheckscanner_test.go lfs: teach gitscanner how to emit lockable files that aren't lfs objects 2017-02-16 16:52:40 -07:00
gitscanner_index.go Set package version to v3 2021-09-02 20:41:08 +00:00
gitscanner_log.go lfs,t: use prune exclude filter on previous SHAs 2022-04-26 10:16:07 -07:00
gitscanner_pointerscanner_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
gitscanner_refs.go lfs/gitscanner*.go: update scan function comments 2022-02-06 21:32:27 -08:00
gitscanner_remotes.go Set package version to v3 2021-09-02 20:41:08 +00:00
gitscanner_tree.go use backticks around commands in messages 2022-01-29 22:35:10 -08:00
gitscanner.go commands,lfs,t: scan refs by tree when pruning 2022-04-27 20:25:13 -07:00
hook.go lfs: don't write hooks when they haven't changed 2022-04-11 15:47:32 +00:00
lfs_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
lfs.go Set package version to v3 2021-09-02 20:41:08 +00:00
pointer_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
pointer.go make additional message strings translatable 2022-01-29 22:36:19 -08:00
scanner_git_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
scanner_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
scanner.go Set package version to v3 2021-09-02 20:41:08 +00:00
util_generic.go Update formatting for Go 1.17 2021-08-17 20:24:58 +02:00
util_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
util.go make additional message strings translatable 2022-01-29 22:36:19 -08:00