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

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

From
Christian Couder <christian.couder@gmail.com>
Date
Jun 27, 2017, 07:18 UTC
Message-ID
<CAP8UFD1mdgtHWt0CD32O=jXPkGLBiba-41DUchT4WT7CheH4bA@mail.gmail.com>
In-Reply-To
<20170626231108.23640-6-pc44800@gmail.com>
On Tue, Jun 27, 2017 at 1:11 AM, Prathamesh Chavan <pc44800@gmail.com> wrote:
Show 14 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);
> +       char *sub_git_dir = xstrfmt("%s/.git", sm_path);
> +
> +       sub = submodule_from_path(null_sha1, sm_path);
> +
> +       if (!sub->name)

In the previous patch "!sub" is used before "!sub->url", so we might want to check "!sub" here too.

Show 22 quoted lines
> +               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)) {
> +               struct child_process cp = CHILD_PROCESS_INIT;
> +
> +               /* 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 */

It looks like cmd_rm() is not used anymore below, so this comment could go and the sm_path variable might not be needed any more.

Show 7 quoted lines
> +                       if (run_command(&cp_rm))
> +                               die(_("Submodule work tree '%s' contains local "
> +                                     "modifications; use '-f' to discard them"),
> +                                     displaypath);
> +               }
> +
> +               cp.use_shell = 1;
Do we really need a shell here?
Show 13 quoted lines
> +               argv_array_pushl(&cp.args, "rm", "-rf", sm_path, NULL);
> +               if (!run_command(&cp)) {
> +                       if (!info->quiet)
> +                               printf(_("Cleared directory '%s'\n"),
> +                                        displaypath);
> +               } else {
> +                       if (!info->quiet)
> +                               printf(_("Could not remove submodule work tree '%s'\n"),
> +                                        displaypath);
> +               }
> +       }
> +
> +       if (mkdir(sm_path, 0700))

Are you sure about the 0700 mode? Shouldn't this depend on the shared repository settings?

> +               die(_("could not create empty submodule directory %s"),
> +                     displaypath);
Previous: Prathamesh ChavanNext: Prathamesh Chavan
Message 7 of 28 in “[GSoC] Update: Week 6”
  1. Prathamesh ChavanJun 26, 2017
  2. [GSoC][PATCH 1/6 v2] submodule--helper: introduce for_each_submodule_listPrathamesh Chavan, Jun 26, 2017
  3. [GSoC][PATCH 2/6 v2] submodule: port subcommand foreach from shell to CPrathamesh Chavan, Jun 26, 2017
  4. Christian CouderJun 27, 2017
  5. [GSoC][PATCH 3/6 v2] submodule: port set_name_rev from shell to CPrathamesh Chavan, Jun 26, 2017
  6. [GSoC][PATCH 6/6 v2] submodule: port submodule subcommand 'deinit' from shell to CPrathamesh Chavan, Jun 26, 2017
  7. Christian CouderJun 27, 2017
  8. [GSoC][PATCH 4/6 v2] submodule: port submodule subcommand statusPrathamesh Chavan, Jun 26, 2017
  9. [GSoC][PATCH 5/6 v2] submodule: port submodule subcommand sync from shell to CPrathamesh Chavan, Jun 26, 2017
  10. Christian CouderJun 27, 2017
  11. Junio C HamanoJun 28, 2017
  12. Prathamesh ChavanJun 29, 2017
  13. [GSoC][PATCH 1/5 v3] submodule--helper: introduce get_submodule_displaypath()Prathamesh Chavan, Jun 30, 2017
  14. [GSoC][PATCH 5/5 v3] submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jun 30, 2017
  15. Stefan BellerJun 30, 2017
  16. Junio C HamanoJun 30, 2017
  17. [GSoC][PATCH 2/5 v3] submodule--helper: introduce for_each_submodule_list()Prathamesh Chavan, Jun 30, 2017
  18. [GSoC][PATCH 4/5 v3] submodule: port submodule subcommand 'status' from shell to CPrathamesh Chavan, Jun 30, 2017
  19. Junio C HamanoJun 30, 2017
  20. [GSoC][PATCH 3/5 v3] submodule: port set_name_rev() from shell to CPrathamesh Chavan, Jun 30, 2017
  21. Junio C HamanoJun 30, 2017
  22. Junio C HamanoJun 30, 2017
  23. [GSoC][PATCH 1/5 v4] submodule--helper: introduce get_submodule_displaypath()Prathamesh Chavan, Jul 13, 2017
  24. [GSoC][PATCH 2/5 v4] submodule--helper: introduce for_each_submodule_list()Prathamesh Chavan, Jul 13, 2017
  25. [GSoC][PATCH 3/5 v4] submodule: port set_name_rev() from shell to CPrathamesh Chavan, Jul 13, 2017
  26. [GSoC][PATCH 4/5 v4] submodule: port submodule subcommand 'status' from shell to CPrathamesh Chavan, Jul 13, 2017
  27. Stefan BellerJul 13, 2017
  28. [GSoC][PATCH 5/5 v4] submodule: port submodule subcommand 'sync' from shell to CPrathamesh Chavan, Jul 13, 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.