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

Re: [PATCH v7 17/31] merge-recursive: add a new hashmap for storing directory renames

From
Stefan Beller <sbeller@google.com>
Date
Feb 3, 2018, 00:26 UTC
Message-ID
<CAGZ79kYcmq9JyD4smH1Vdm5YOFXRXjhYhhHYjNV=Z7mxz2UVGw@mail.gmail.com>
In-Reply-To
<20180130232533.25846-18-newren@gmail.com>
On Tue, Jan 30, 2018 at 3:25 PM, Elijah Newren <newren@gmail.com> wrote:
Show 40 quoted lines
> This just adds dir_rename_entry and the associated functions; code using
> these will be added in subsequent commits.
>
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>  merge-recursive.c | 35 +++++++++++++++++++++++++++++++++++
>  merge-recursive.h |  8 ++++++++
>  2 files changed, 43 insertions(+)
>
> diff --git a/merge-recursive.c b/merge-recursive.c
> index 8ac69e1cbb..3b6d0e3f70 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -49,6 +49,41 @@ static unsigned int path_hash(const char *path)
>         return ignore_case ? strihash(path) : strhash(path);
>  }
>
> +static struct dir_rename_entry *dir_rename_find_entry(struct hashmap *hashmap,
> +                                                     char *dir)
> +{
> +       struct dir_rename_entry key;
> +
> +       if (dir == NULL)
> +               return NULL;
> +       hashmap_entry_init(&key, strhash(dir));
> +       key.dir = dir;
> +       return hashmap_get(hashmap, &key, NULL);
> +}
> +
> +static int dir_rename_cmp(void *unused_cmp_data,
> +                         const struct dir_rename_entry *e1,
> +                         const struct dir_rename_entry *e2,
> +                         const void *unused_keydata)
> +{
> +       return strcmp(e1->dir, e2->dir);
> +}
> +
> +static void dir_rename_init(struct hashmap *map)
> +{
> +       hashmap_init(map, (hashmap_cmp_fn) dir_rename_cmp, NULL, 0);

See 55c965f3a2 (Merge branch 'sb/hashmap-cleanup', 2017-08-11) or rather 201c14e375 (attr.c: drop hashmap_cmp_fn cast, 2017-06-30) for an attempt to keep out the casting in the init, but cast the void->type inside the function.

Show 28 quoted lines
> +static void dir_rename_entry_init(struct dir_rename_entry *entry,
> +                                 char *directory)
> +{
> +       hashmap_entry_init(entry, strhash(directory));
> +       entry->dir = directory;
> +       entry->non_unique_new_dir = 0;
> +       strbuf_init(&entry->new_dir, 0);
> +       string_list_init(&entry->possible_new_dirs, 0);
> +}
> +
>  static void flush_output(struct merge_options *o)
>  {
>         if (o->buffer_output < 2 && o->obuf.len) {
> diff --git a/merge-recursive.h b/merge-recursive.h
> index 80d69d1401..d7f4cc80c1 100644
> --- a/merge-recursive.h
> +++ b/merge-recursive.h
> @@ -29,6 +29,14 @@ struct merge_options {
>         struct string_list df_conflict_file_set;
>  };
>
> +struct dir_rename_entry {
> +       struct hashmap_entry ent; /* must be the first member! */
> +       char *dir;
> +       unsigned non_unique_new_dir:1;
> +       struct strbuf new_dir;
> +       struct string_list possible_new_dirs;
> +};

Could you add comments what these are and if they have any constraints? e.g. is 'dir' the full path from the root of the repo and does it end with a '/' ?

Having a stringlist of potentially new dirs sounds like the algorithm is at least n^2, but how do I know? I'll read on.

This patch only adds static functions, so some compilers may even refuse to compile after this patch (-Werror -Wunused). I am not sure how strict we are there, but as git-bisect still hasn't learned about going only into the first parent to have bisect working on a "per series" level rather than a "per commit" level, it is possible that someone will end up on this commit in the future and it won't compile well. :/

Not sure what to recommend, maybe squash this with the patch that makes use of these functions?

Thanks, Stefan

Previous: Elijah NewrenNext: Elijah Newren
Message 29 of 63 in “Add directory rename detection to git”
  1. 00/31 Add directory rename detection to gitElijah Newren, Jan 30, 2018
  2. Elijah NewrenJan 30, 2018
  3. 24/31 merge-recursive: when comparing files, don't include treesElijah Newren, Jan 30, 2018
  4. 28/31 merge-recursive: fix remaining directory rename + dirty overwrite casesElijah Newren, Jan 30, 2018
  5. Stefan BellerFeb 5, 2018
  6. Elijah NewrenFeb 5, 2018
  7. 05/31 directory rename detection: files/directories in the way of some renamesElijah Newren, Jan 30, 2018
  8. 06/31 directory rename detection: testcases checking which side did the renameElijah Newren, Jan 30, 2018
  9. 10/31 directory rename detection: tests for handling overwriting untracked filesElijah Newren, Jan 30, 2018
  10. 15/31 merge-recursive: make !o->detect_rename codepath more obviousElijah Newren, Jan 30, 2018
  11. Stefan BellerFeb 2, 2018
  12. 14/31 merge-recursive: fix leaks of allocated renames and diff_filepairsElijah Newren, Jan 30, 2018
  13. Stefan BellerFeb 2, 2018
  14. 23/31 merge-recursive: check for file level conflicts then get new nameElijah Newren, Jan 30, 2018
  15. 30/31 merge-recursive: avoid spurious rename/rename conflict from dir renamesElijah Newren, Jan 30, 2018
  16. 16/31 merge-recursive: split out code for determining diff_filepairsElijah Newren, Jan 30, 2018
  17. Stefan BellerFeb 3, 2018
  18. Elijah NewrenFeb 3, 2018
  19. 11/31 directory rename detection: tests for handling overwriting dirty filesElijah Newren, Jan 30, 2018
  20. 22/31 merge-recursive: add computation of collisions due to dir rename & mergingElijah Newren, Jan 30, 2018
  21. 31/31 merge-recursive: ensure we write updates for directory-renamed fileElijah Newren, Jan 30, 2018
  22. Stefan BellerFeb 5, 2018
  23. 20/31 merge-recursive: check for directory level conflictsElijah Newren, Jan 30, 2018
  24. Stefan BellerFeb 5, 2018
  25. Elijah NewrenFeb 5, 2018
  26. 25/31 merge-recursive: apply necessary modifications for directory renamesElijah Newren, Jan 30, 2018
  27. SZEDER GáborFeb 16, 2018
  28. 17/31 merge-recursive: add a new hashmap for storing directory renamesElijah Newren, Jan 30, 2018
  29. Stefan BellerFeb 3, 2018
  30. Elijah NewrenFeb 3, 2018
  31. Johannes SixtFeb 4, 2018
  32. Elijah NewrenFeb 5, 2018
  33. Junio C HamanoFeb 5, 2018
  34. Stefan BellerFeb 5, 2018
  35. Elijah NewrenFeb 5, 2018
  36. 21/31 merge-recursive: add a new hashmap for storing file collisionsElijah Newren, Jan 30, 2018
  37. Stefan BellerFeb 5, 2018
  38. 29/31 directory rename detection: new testcases showcasing a pair of bugsElijah Newren, Jan 30, 2018
  39. 27/31 merge-recursive: fix overwriting dirty files involved in renamesElijah Newren, Jan 30, 2018
  40. Stefan BellerFeb 5, 2018
  41. Elijah NewrenFeb 5, 2018
  42. 03/31 directory rename detection: testcases to avoid taking detection too farElijah Newren, Jan 30, 2018
  43. 01/31 directory rename detection: basic testcasesElijah Newren, Jan 30, 2018
  44. 04/31 directory rename detection: partially renamed directory testcase/discussionElijah Newren, Jan 30, 2018
  45. 19/31 merge-recursive: add get_directory_renames()Elijah Newren, Jan 30, 2018
  46. Stefan BellerFeb 3, 2018
  47. Elijah NewrenFeb 3, 2018
  48. Elijah NewrenFeb 4, 2018
  49. Eric SunshineFeb 4, 2018
  50. Eric SunshineFeb 4, 2018
  51. Stefan BellerFeb 5, 2018
  52. 18/31 merge-recursive: make a helper function for cleanup for handle_renamesElijah Newren, Jan 30, 2018
  53. Stefan BellerFeb 3, 2018
  54. 02/31 directory rename detection: directory splitting testcasesElijah Newren, Jan 30, 2018
  55. 13/31 merge-recursive: introduce new functions to handle rename logicElijah Newren, Jan 30, 2018
  56. Stefan BellerFeb 2, 2018
  57. 12/31 merge-recursive: move the get_renames() functionElijah Newren, Jan 30, 2018
  58. Stefan BellerFeb 2, 2018
  59. 09/31 directory rename detection: miscellaneous testcases to complete coverageElijah Newren, Jan 30, 2018
  60. 08/31 directory rename detection: testcases exploring possibly suboptimal mergesElijah Newren, Jan 30, 2018
  61. 26/31 merge-recursive: avoid clobbering untracked files with directory renamesElijah Newren, Jan 30, 2018
  62. 07/31 directory rename detection: more involved edge/corner testcasesElijah Newren, Jan 30, 2018
  63. Stefan BellerFeb 5, 2018

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.