Thread (22 messages) 22 messages, 3 authors, 2017-07-13

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

From: Christian Couder <hidden>
Date: 2017-06-27 07:18:44

On Tue, Jun 27, 2017 at 1:11 AM, Prathamesh Chavan [off-list ref] wrote:
quoted hunk ↗ jump to hunk
+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.
quoted hunk ↗ jump to hunk
+               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.
quoted hunk ↗ jump to hunk
+                       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?
quoted hunk ↗ jump to hunk
+               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);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help