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

Re: [GSoC][PATCH 6/8] submodule: port submodule subcommand 'deinit' from shell to C

From
Christian Couder <christian.couder@gmail.com>
Date
Jul 19, 2017, 14:04 UTC
Message-ID
<CAP8UFD07w=57kTazLxrEYUq5jaCDp0B3SJevZM3BBoUhsJUj=w@mail.gmail.com>
In-Reply-To
<20170718204904.3768-7-pc44800@gmail.com>
On Tue, Jul 18, 2017 at 10:49 PM, Prathamesh Chavan <pc44800@gmail.com> wrote:
Show 9 quoted lines
> +static void deinit_submodule(const struct cache_entry *list_item,
> +                            void *cb_data)
> +{
> +       struct deinit_cb *info = cb_data;
> +       const struct submodule *sub;
> +       char *displaypath = NULL;
> +       struct child_process cp_config = CHILD_PROCESS_INIT;
> +       struct strbuf sb_config = STRBUF_INIT;
> +       char *sm_path = xstrdup(list_item->name);

If I understood the previous rounds correctly, list_item->name is duplicated because it is changed below...

Show 26 quoted lines
> +       char *sub_git_dir = xstrfmt("%s/.git", sm_path);
> +       struct stat st;
> +
> +       sub = submodule_from_path(null_sha1, sm_path);
> +
> +       if (!sub || !sub->name)
> +               goto cleanup;
> +
> +       displaypath = get_submodule_displaypath(sm_path, info->prefix);
> +
> +       /* remove the submodule work tree (unless the user already did it) */
> +       if (is_directory(sm_path)) {
> +               /* protect submodules containing a .git directory */
> +               if (is_git_directory(sub_git_dir))
> +                       die(_("Submodule work tree '%s' contains a .git "
> +                             "directory use 'rm -rf' if you really want "
> +                             "to remove it including all of its history"),
> +                             displaypath);
> +
> +               if (!info->force) {
> +                       struct child_process cp_rm = CHILD_PROCESS_INIT;
> +                       cp_rm.git_cmd = 1;
> +                       argv_array_pushl(&cp_rm.args, "rm", "-qn", sm_path,
> +                                        NULL);
> +
> +                       /* list_item->name is changed by cmd_rm() below */

... but it looks like cmd_rm() is not used anymore below, so this comment is outdated and I wonder if duplicated list_item->name is still needed.

Show 19 quoted lines
> +                       if (run_command(&cp_rm))
> +                               die(_("Submodule work tree '%s' contains local "
> +                                     "modifications; use '-f' to discard them"),
> +                                     displaypath);
> +               }
> +
> +               if (!lstat(sm_path, &st)) {
> +                       struct strbuf sb_rm = STRBUF_INIT;
> +                       strbuf_addstr(&sb_rm, sm_path);
> +
> +                       if (!remove_dir_recursively(&sb_rm, 0)) {
> +                               if (!info->quiet)
> +                                       printf(_("Cleared directory '%s'\n"),
> +                                                displaypath);
> +                       } else {
> +                               if (!info->quiet)
> +                                       printf(_("Could not remove submodule work tree '%s'\n"),
> +                                                displaypath);
> +                       }
Nit: maybe this could be:
                       struct strbuf sb_rm = STRBUF_INIT;
                       const char *format;
                       strbuf_addstr(&sb_rm, sm_path);
                       if (!remove_dir_recursively(&sb_rm, 0))
                               format = _("Cleared directory '%s'\n");
                       else
                               format = _("Could not remove submodule
work tree '%s'\n");
                       if (!info->quiet)
                               printf(format, displaypath);
> +                       strbuf_release(&sb_rm);
> +               }
> +       }
Previous: Prathamesh ChavanNext: Prathamesh Chavan
Message 15 of 18 in “Update: Week 9”
  1. Prathamesh ChavanJul 18, 2017
  2. [GSoC][PATCH 1/8] submodule--helper: introduce get_submodule_displaypath()Prathamesh Chavan, Jul 18, 2017
  3. [GSoC][PATCH 2/8] submodule--helper: introduce for_each_submodule_list()Prathamesh Chavan, Jul 18, 2017
  4. [GSoC][PATCH 3/8] submodule: port set_name_rev() from shell to CPrathamesh Chavan, Jul 18, 2017
  5. [GSoC][PATCH 4/8] submodule: port submodule subcommand 'status' from shell to CPrathamesh Chavan, Jul 18, 2017
  6. Stefan BellerJul 18, 2017
  7. Junio C HamanoJul 18, 2017
  8. Stefan BellerJul 18, 2017
  9. Junio C HamanoJul 18, 2017
  10. [GSoC][PATCH 5/8] submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jul 18, 2017
  11. Stefan BellerJul 18, 2017
  12. Prathamesh ChavanJul 20, 2017
  13. Stefan BellerJul 20, 2017
  14. [GSoC][PATCH 6/8] submodule: port submodule subcommand 'deinit' from shell to CPrathamesh Chavan, Jul 18, 2017
  15. Christian CouderJul 19, 2017
  16. [GSoC][PATCH 7/8] diff: change scope of the function count_lines()Prathamesh Chavan, Jul 18, 2017
  17. [GSoC][PATCH 8/8] submodule: port submodule subcommand 'summary' from shell to CPrathamesh Chavan, Jul 18, 2017
  18. Christian CouderJul 19, 2017

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.