git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1 2/7] mv: add documentation for check_dir_in_index()

From
Victoria Dye <vdye@github.com>
Date
Jul 19, 2022, 18:10 UTC
Message-ID
<d5889658-77f5-25ff-7469-3f00a41857da@github.com>
In-Reply-To
<6188fab7-df5e-b3fb-92a2-47039254ac45@github.com>
Victoria Dye wrote:
Show 56 quoted lines
> Shaoxuan Yuan wrote:
>> Using check_dir_in_index without checking if the directory is on-disk
>> could get a false positive for partially sparsified directory.
>>
>> Add a note in the documentation to warn potential user.
>>
>> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
>> ---
>>  builtin/mv.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/builtin/mv.c b/builtin/mv.c
>> index 4729bb1a1a..c8b9069db8 100644
>> --- a/builtin/mv.c
>> +++ b/builtin/mv.c
>> @@ -132,6 +132,11 @@ static int index_range_of_same_dir(const char *src, int length,
>>   * Return 0 if such directory exist (i.e. with any of its contained files not
>>   * marked with CE_SKIP_WORKTREE, the directory would be present in working tree).
>>   * Return 1 otherwise.
>> + *
>> + * Note: *always* check the directory is not on-disk before this function
>> + * (i.e. using lstat());
>> + * otherwise it may return a false positive for a partially sparsified
>> + * directory.
> 
> To me, a comment like this indicates that either the function is not doing
> what it should be doing, or its name doesn't properly describe the
> function's behavior.
> 
> Per the function description:
> 
> 	Check if an out-of-cone directory should be in the index. Imagine
> 	this case that all the files under a directory are marked with
> 	'CE_SKIP_WORKTREE' bit and thus the directory is sparsified.
> 
> But neither the name of the function ('check_dir_in_index') nor the
> function's behavior (hence the comment you're adding here) match that
> description.
> 
> Since this function is intended to verify that a directory 1) exists in the
> index, and 2) is *entirely* sparse, I have two suggestions:
> 
> * Change the description to specify that the non-existence of the directory
>   on disk is an *assumption*, not an opportunity for a "false positive."
>   It's a subtle distinction, but it clarifies that the function should be
>   used only when the caller already knows the directory is empty. For
>   example:
> 
> 	/*
> 	 * Given the path of a directory that does not exist on-disk, check whether the
> 	 * directory contains any entries in the index with the SKIP_WORKTREE flag 
> 	 * enabled.
> 	 *
> 	 * Return 1 if such index entries exist.
> 	 * Return 0 otherwise.
> 	 */

Whoops, I mixed up the return values (I assumed this returned a boolean based on the 'check' in the function name). In that case...

> 
> * 'check_dir_in_index' doesn't reflect the "is not on disk" prerequisite, so
>   the function name can be updated to clarify that (e.g.,
>   'empty_dir_has_sparse_contents')

...there are two options. Either you can use a more "boolean-y" name (like the one I suggest above) and flip the return values (where "1" means "the empty dir has sparse contents"), or change the name to something that explicitly *doesn't* imply boolean. I'm personally in favor of the former (I'm really struggling to come up with a descriptive, non-boolean name for this function), but I'm fine with either if you can come up with a good function name.

Show 5 quoted lines
> 
>>   */
>>  static int check_dir_in_index(const char *name)
>>  {
> 
Previous: Victoria DyeNext: Shaoxuan Yuan
Message 10 of 61 in “mv: from in-cone to out-of-cone”
  1. 0/7 mv: from in-cone to out-of-coneShaoxuan Yuan, Jul 19, 2022
  2. 1/7 t7002: add tests for moving from in-cone to out-of-coneShaoxuan Yuan, Jul 19, 2022
  3. Ævar Arnfjörð BjarmasonJul 19, 2022
  4. Derrick StoleeJul 19, 2022
  5. Junio C HamanoJul 19, 2022
  6. 2/7 mv: add documentation for check_dir_in_index()Shaoxuan Yuan, Jul 19, 2022
  7. Derrick StoleeJul 19, 2022
  8. Shaoxuan YuanJul 21, 2022
  9. Victoria DyeJul 19, 2022
  10. Victoria DyeJul 19, 2022
  11. Shaoxuan YuanJul 21, 2022
  12. 3/7 mv: free the *with_slash in check_dir_in_index()Shaoxuan Yuan, Jul 19, 2022
  13. Derrick StoleeJul 19, 2022
  14. 5/7 mv: remove BOTH from enum update_modeShaoxuan Yuan, Jul 19, 2022
  15. Derrick StoleeJul 19, 2022
  16. 4/7 mv: check if <destination> is a SKIP_WORKTREE_DIRShaoxuan Yuan, Jul 19, 2022
  17. Derrick StoleeJul 19, 2022
  18. Shaoxuan YuanJul 21, 2022
  19. Derrick StoleeJul 22, 2022
  20. Junio C HamanoJul 22, 2022
  21. 6/7 mv: from in-cone to out-of-coneShaoxuan Yuan, Jul 19, 2022
  22. Derrick StoleeJul 19, 2022
  23. Shaoxuan YuanAug 3, 2022
  24. Derrick StoleeAug 3, 2022
  25. Shaoxuan YuanAug 4, 2022
  26. 7/7 mv: check overwrite for in-to-out moveShaoxuan Yuan, Jul 19, 2022
  27. Derrick StoleeJul 19, 2022
  28. Derrick StoleeJul 19, 2022
  29. 0/9 mv: from in-cone to out-of-coneShaoxuan Yuan, Aug 5, 2022
  30. 1/9 t7002: add tests for moving from in-cone to out-of-coneShaoxuan Yuan, Aug 5, 2022
  31. Victoria DyeAug 9, 2022
  32. Shaoxuan YuanAug 9, 2022
  33. Shaoxuan YuanAug 9, 2022
  34. Shaoxuan YuanAug 9, 2022
  35. 2/9 mv: rename check_dir_in_index() to empty_dir_has_sparse_contents()Shaoxuan Yuan, Aug 5, 2022
  36. 3/9 mv: free the *with_slash in check_dir_in_index()Shaoxuan Yuan, Aug 5, 2022
  37. Victoria DyeAug 8, 2022
  38. Shaoxuan YuanAug 9, 2022
  39. 4/9 mv: check if <destination> is a SKIP_WORKTREE_DIRShaoxuan Yuan, Aug 5, 2022
  40. Victoria DyeAug 8, 2022
  41. Victoria DyeAug 9, 2022
  42. Shaoxuan YuanAug 9, 2022
  43. 5/9 mv: remove BOTH from enum update_modeShaoxuan Yuan, Aug 5, 2022
  44. 6/9 mv: from in-cone to out-of-coneShaoxuan Yuan, Aug 5, 2022
  45. Victoria DyeAug 9, 2022
  46. Shaoxuan YuanAug 9, 2022
  47. 7/9 mv: cleanup empty WORKING_DIRECTORYShaoxuan Yuan, Aug 5, 2022
  48. 8/9 advice.h: add advise_on_moving_dirty_path()Shaoxuan Yuan, Aug 5, 2022
  49. 9/9 mv: check overwrite for in-to-out moveShaoxuan Yuan, Aug 5, 2022
  50. Victoria DyeAug 8, 2022
  51. 0/9 mv: from in-cone to out-of-coneShaoxuan Yuan, Aug 9, 2022
  52. 1/9 t7002: add tests for moving from in-cone to out-of-coneShaoxuan Yuan, Aug 9, 2022
  53. 2/9 mv: rename check_dir_in_index() to empty_dir_has_sparse_contents()Shaoxuan Yuan, Aug 9, 2022
  54. 3/9 mv: free the with_slash in check_dir_in_index()Shaoxuan Yuan, Aug 9, 2022
  55. 5/9 mv: remove BOTH from enum update_modeShaoxuan Yuan, Aug 9, 2022
  56. 6/9 mv: from in-cone to out-of-coneShaoxuan Yuan, Aug 9, 2022
  57. 7/9 mv: cleanup empty WORKING_DIRECTORYShaoxuan Yuan, Aug 9, 2022
  58. 8/9 advice.h: add advise_on_moving_dirty_path()Shaoxuan Yuan, Aug 9, 2022
  59. 9/9 mv: check overwrite for in-to-out moveShaoxuan Yuan, Aug 9, 2022
  60. 4/9 mv: check if <destination> is a SKIP_WORKTREE_DIRShaoxuan Yuan, Aug 9, 2022
  61. Victoria DyeAug 16, 2022

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.