git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:14 UTC

Re: [GSoC PATCH v2 6/7] builtin/repack: add safety guards for --drop-filtered

From
Siddharth Asthana <siddharthasthana31@gmail.com>
Date
Aug 4, 2026, 21:13 UTC
Message-ID
<a81fc1be-914e-4045-87a0-cee88257fad5@gmail.com>
In-Reply-To
<20260730174153.9949-7-r.siddharth.shrimali@gmail.com>
On 30/07/26 23:11, Siddharth Shrimali wrote:
Show 11 quoted lines
> --drop-filtered removes local promisor blobs. That is only safe when the
> repository is not mid-operation and when the blobs are not actively in
> use, so add two guards, both skipped for bare repositories which have
> neither a worktree nor an index.
> 
> First, refuse to run while a merge, rebase, am, cherry-pick, revert, or
> bisect is in progress. During these operations the working tree and
> index are in an intermediate state, and rewriting packs and deleting
> objects underneath a half-finished operation is unsafe.
> 
> Second, refuse to drop a blob that the current index references. Such a
Index guard looks good to me. Same idea as on the RFC.

Thanks. Siddharth

Show 130 quoted lines
> blob is needed by the working tree, so dropping it would only cause the
> next command that touches the worktree to lazy-fetch it straight back,
> reclaiming nothing. The offending path is reported so the user can see
> why the drop was refused.
> 
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Siddharth Asthana <siddharthasthana31@gmail.com>
> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
> ---
>   builtin/repack.c                | 47 +++++++++++++++++++++++++++++++++
>   t/t7706-repack-drop-filtered.sh | 36 +++++++++++++++++++++++++
>   2 files changed, 83 insertions(+)
> 
> diff --git a/builtin/repack.c b/builtin/repack.c
> index 9a15ab1f2a..2339bcaac4 100644
> --- a/builtin/repack.c
> +++ b/builtin/repack.c
> @@ -17,6 +17,8 @@
>   #include "list-objects-filter-options.h"
>   #include "oidset.h"
>   #include "hex.h"
> +#include "wt-status.h"
> +#include "read-cache-ll.h"
>   
>   #define ALL_INTO_ONE 1
>   #define LOOSEN_UNREACHABLE 2
> @@ -309,6 +311,28 @@ int cmd_repack(int argc,
>   		if (!repo_has_promisor_remote(repo))
>   			die(_("--drop-filtered requires a promisor remote"));
>   
> +		/*
> +		 * refuse to drop objects while another operation is in
> +		 * progress. the working tree and index are in an
> +		 * intermediate state, and rewriting packs in a half-finished
> +		 * merge/rebase/cherry-pick/revert/bisect is unsafe
> +		 * bare repositories have no such state, so the check
> +		 * is skipped there
> +		 */
> +		if (!is_bare_repository(repo)) {
> +			struct wt_status_state state = { 0 };
> +
> +			wt_status_get_state(repo, &state, 0);
> +			if (state.merge_in_progress || state.revert_in_progress ||
> +			    state.rebase_in_progress ||state.bisect_in_progress ||
> +			    state.cherry_pick_in_progress ||state.am_in_progress||
> +			    state.rebase_interactive_in_progress) {
> +				wt_status_state_free_buffers(&state);
> +				die(_("--drop-filtered cannot be used while another operation is in progress"));
> +			}
> +			wt_status_state_free_buffers(&state);
> +		}
> +
>   		write_bitmaps = 0;
>   
>   		/*
> @@ -324,6 +348,29 @@ int cmd_repack(int argc,
>   		if (ret)
>   			goto cleanup;
>   
> +		/*
> +		 * refuse to drop blobs that the current index references.
> +		 * dropping such a blob would cause the very next command
> +		 * that touches the worktree to lazy-fetch it straight back, so
> +		 * the drop would reclaim nothing. bare repositories have no
> +		 * index, so the check is skipped there.
> +		 */
> +		if (!is_bare_repository(repo) && oidset_size(&drop_oids)) {
> +			struct index_state *istate = repo->index;
> +			unsigned int i;
> +
> +			if (repo_read_index(repo) < 0)
> +				die(_("could not read the index"));
> +
> +			for (i = 0; i < istate->cache_nr; i++) {
> +				const struct cache_entry *ce = istate->cache[i];
> +
> +				if (oidset_contains(&drop_oids, &ce->oid))
> +					die(_("cannot drop '%s' (%s): it is referenced by the current index"),
> +						ce->name, oid_to_hex(&ce->oid));
> +			}
> +		}
> +
>   		if (dry_run) {
>   			struct oidset_iter iter;
>   			const struct object_id *oid;
> diff --git a/t/t7706-repack-drop-filtered.sh b/t/t7706-repack-drop-filtered.sh
> index b3e493e851..dabed97541 100755
> --- a/t/t7706-repack-drop-filtered.sh
> +++ b/t/t7706-repack-drop-filtered.sh
> @@ -140,4 +140,40 @@ test_expect_success '--drop-filtered removes the promisor blob locally' '
>   	grep -q "$SMALL" present
>   '
>   
> +test_expect_success '--drop-filtered refuses when a merge is in progress' '
> +	test_when_finished "git -C repo merge --abort || :" &&
> +
> +	# creat a conflicting merge so wt_status reports it
> +	git -C repo checkout -B mergebase base &&
> +	echo one >repo/conflict.txt &&
> +	git -C repo add conflict.txt &&
> +	git -C repo commit -m one &&
> +
> +	git -C repo checkout -B mergeother base &&
> +	echo two >repo/conflict.txt &&
> +	git -C repo add conflict.txt &&
> +	git -C repo commit -m two &&
> +
> +	test_must_fail git -C repo merge mergebase &&
> +
> +	test_must_fail git -C repo -c repack.writeBitmaps=false \
> +		repack --drop-filtered --filter=blob:limit=1k --dry-run -a 2>err &&
> +	test_grep "in progress" err
> +'
> +
> +
> +test_expect_success '--drop-filtered refuses to drop an index-referenced blob' '
> +	# create a large blob, add it to the index and make it a promisor object
> +	# so the index references it and enumeration picks it up
> +	test-tool genrandom idx 4096 >repo/tracked-big.bin &&
> +	git -C repo add tracked-big.bin &&
> +	OID=$(git -C repo rev-parse :tracked-big.bin) &&
> +	printf "%s\n" "$OID" | pack_as_from_promisor >/dev/null &&
> +	delete_object repo "$OID" &&
> +
> +	test_must_fail git -C repo -c repack.writeBitmaps=false \
> +		repack --drop-filtered --filter=blob:limit=1k --dry-run -a 2>err &&
> +	test_grep "referenced by the current index" err
> +'
> +
>   test_done
Previous: Siddharth AsthanaNext: Siddharth Shrimali
Message 34 of 76 in “repack: add --drop-filtered to reclaim space in partial clones”
  1. 0/7 repack: add --drop-filtered to reclaim space in partial clonesSiddharth Shrimali, Jul 16, 2026
  2. 1/7 builtin/repack.c: add --drop-filtered and --dry-run optionsSiddharth Shrimali, Jul 16, 2026
  3. 2/7 list-objects-filter: add list_objects_filter__filter_oidset()Siddharth Shrimali, Jul 16, 2026
  4. 3/7 repack-promisor: allow excluding objects from the rebuilt promisor packSiddharth Shrimali, Jul 16, 2026
  5. 4/7 builtin/repack: enumerate promisor blobs for --drop-filteredSiddharth Shrimali, Jul 16, 2026
  6. 5/7 t7706: test --drop-filtered enumeration and validationSiddharth Shrimali, Jul 16, 2026
  7. 6/7 builtin/repack: actually drop filtered promisor blobsSiddharth Shrimali, Jul 16, 2026
  8. 7/7 repack-promisor: record dropped objects in a drop logSiddharth Shrimali, Jul 16, 2026
  9. Junio C HamanoJul 16, 2026
  10. Siddharth ShrimaliJul 17, 2026
  11. Christian CouderJul 18, 2026
  12. Siddharth ShrimaliJul 20, 2026
  13. Siddharth AsthanaJul 23, 2026
  14. Siddharth AsthanaJul 23, 2026
  15. Siddharth AsthanaJul 23, 2026
  16. Siddharth AsthanaJul 23, 2026
  17. Siddharth ShrimaliJul 25, 2026
  18. Siddharth ShrimaliJul 25, 2026
  19. Siddharth ShrimaliJul 25, 2026
  20. 0/7 repack: add --drop-filtered to reclaim space in partial clonesSiddharth Shrimali, Jul 30, 2026
  21. 1/7 builtin/repack.c: add --drop-filtered and --dry-run optionsSiddharth Shrimali, Jul 30, 2026
  22. 2/7 list-objects-filter: add list_objects_filter__filter_oidset()Siddharth Shrimali, Jul 30, 2026
  23. 3/7 repack-promisor: allow excluding objects from the rebuilt promisor packSiddharth Shrimali, Jul 30, 2026
  24. 4/7 builtin/repack: enumerate promisor blobs for --drop-filteredSiddharth Shrimali, Jul 30, 2026
  25. 5/7 builtin/repack: actually drop filtered promisor blobsSiddharth Shrimali, Jul 30, 2026
  26. 6/7 builtin/repack: add safety guards for --drop-filteredSiddharth Shrimali, Jul 30, 2026
  27. 7/7 Documentation/git-repack: document --drop-filtered and --dry-runSiddharth Shrimali, Jul 30, 2026
  28. Junio C HamanoJul 31, 2026
  29. Siddharth ShrimaliAug 1, 2026
  30. Junio C HamanoAug 2, 2026
  31. Siddharth ShrimaliAug 2, 2026
  32. Siddharth AsthanaAug 4, 2026
  33. Siddharth AsthanaAug 4, 2026
  34. Siddharth AsthanaAug 4, 2026
  35. 0/7 repack: add --drop-filtered to reclaim space in partial clonesSiddharth Shrimali, Aug 6, 2026
  36. 1/7 builtin/repack.c: add --drop-filtered and --dry-run optionsSiddharth Shrimali, Aug 6, 2026
  37. 2/7 list-objects-filter: add list_objects_filter__filter_oidset()Siddharth Shrimali, Aug 6, 2026
  38. 3/7 repack-promisor: allow excluding objects from the rebuilt promisor packSiddharth Shrimali, Aug 6, 2026
  39. 4/7 builtin/repack: enumerate promisor blobs for --drop-filteredSiddharth Shrimali, Aug 6, 2026
  40. 5/7 builtin/repack: actually drop filtered promisor blobsSiddharth Shrimali, Aug 6, 2026
  41. 6/7 builtin/repack: add guards for --drop-filteredSiddharth Shrimali, Aug 6, 2026
  42. 7/7 Documentation/git-repack: document --drop-filtered and --dry-runSiddharth Shrimali, Aug 6, 2026
  43. Junio C HamanoAug 6, 2026
  44. Junio C HamanoAug 6, 2026
  45. Siddharth ShrimaliAug 7, 2026
  46. Junio C HamanoAug 7, 2026
  47. Siddharth ShrimaliAug 8, 2026
  48. 0/7 repack: add --drop-filtered to reclaim space in partial clonesSiddharth Shrimali, Aug 10, 2026
  49. 1/7 builtin/repack.c: add --drop-filtered and --dry-run optionsSiddharth Shrimali, Aug 10, 2026
  50. 2/7 list-objects-filter: add list_objects_filter__filter_oidset()Siddharth Shrimali, Aug 10, 2026
  51. 3/7 repack-promisor: allow excluding objects from the rebuilt promisor packSiddharth Shrimali, Aug 10, 2026
  52. 4/7 builtin/repack: enumerate promisor blobs for --drop-filteredSiddharth Shrimali, Aug 10, 2026
  53. 5/7 builtin/repack: actually drop filtered promisor blobsSiddharth Shrimali, Aug 10, 2026
  54. 6/7 builtin/repack: add guards for --drop-filteredSiddharth Shrimali, Aug 10, 2026
  55. 7/7 Documentation/git-repack: document --drop-filtered and --dry-runSiddharth Shrimali, Aug 10, 2026
  56. Junio C HamanoAug 11, 2026
  57. Siddharth ShrimaliAug 12, 2026
  58. Christian CouderAug 12, 2026
  59. Christian CouderAug 12, 2026
  60. Christian CouderAug 12, 2026
  61. Christian CouderAug 12, 2026
  62. Junio C HamanoAug 12, 2026
  63. Siddharth ShrimaliAug 12, 2026
  64. Siddharth ShrimaliAug 12, 2026
  65. 0/6 repack: add --drop-filtered to reclaim space in partial clonesSiddharth Shrimali, Aug 13, 2026
  66. 1/6 builtin/repack: add --drop-filtered and --dry-run optionsSiddharth Shrimali, Aug 13, 2026
  67. 2/6 list-objects-filter: add list_objects_filter__filter_oidset()Siddharth Shrimali, Aug 13, 2026
  68. 3/6 repack-promisor: allow excluding objects from the rebuilt promisor packSiddharth Shrimali, Aug 13, 2026
  69. 4/6 builtin/repack: enumerate promisor blobs for --drop-filteredSiddharth Shrimali, Aug 13, 2026
  70. 5/6 builtin/repack: actually drop filtered promisor blobsSiddharth Shrimali, Aug 13, 2026
  71. 6/6 builtin/repack: add guards for --drop-filteredSiddharth Shrimali, Aug 13, 2026
  72. Christian CouderAug 14, 2026
  73. Junio C HamanoAug 14, 2026
  74. Siddharth ShrimaliAug 14, 2026
  75. Samuel BronsonSep 3, 2026
  76. Siddharth ShrimaliSep 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.