Message ID | 20210805071917.29500-3-raykar.ath@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | submodule: convert the rest of 'add' to C | expand |
On 2021-08-05 12:49:11+0530, Atharva Raykar <raykar.ath@gmail.com> wrote: > This part of `sync_submodule()` is doing the same thing that > `compute_submodule_clone_url()` is doing. Let's reuse that helper here. > > Signed-off-by: Atharva Raykar <raykar.ath@gmail.com> > Mentored-by: Christian Couder <christian.couder@gmail.com> > Mentored-by: Shourya Shukla <periperidip@gmail.com> > --- > builtin/submodule--helper.c | 16 +++------------- > 1 file changed, 3 insertions(+), 13 deletions(-) > > diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c > index f4b496bac6..9b676c12f8 100644 > --- a/builtin/submodule--helper.c > +++ b/builtin/submodule--helper.c > @@ -1373,20 +1373,10 @@ static void sync_submodule(const char *path, const char *prefix, > if (sub && sub->url) { > if (starts_with_dot_dot_slash(sub->url) || > starts_with_dot_slash(sub->url)) { > - char *remote_url, *up_path; > - char *remote = get_default_remote(); > - strbuf_addf(&sb, "remote.%s.url", remote); > - > - if (git_config_get_string(sb.buf, &remote_url)) > - remote_url = xgetcwd(); > - > - up_path = get_up_path(path); > - sub_origin_url = relative_url(remote_url, sub->url, up_path); > - super_config_url = relative_url(remote_url, sub->url, NULL); > - > - free(remote); > + char *up_path = get_up_path(path); > + sub_origin_url = compute_submodule_clone_url(sub->url, up_path, 1); > + super_config_url = compute_submodule_clone_url(sub->url, NULL, 1); While previous patch is definitely a refactoring, this patch add small overhead to the system, the new code will query (then free()) git_config_get_string() and/or xgetcwd() one more time in the second compute_submodule_clone_url() I think the abstraction overhead is not that big, though. > free(up_path); > - free(remote_url); > } else { > sub_origin_url = xstrdup(sub->url); > super_config_url = xstrdup(sub->url); > -- > 2.32.0 >
On Fri, Aug 6, 2021 at 2:54 AM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote: > While previous patch is definitely a refactoring, this patch add small > overhead to the system, the new code will query (then free()) > git_config_get_string() and/or xgetcwd() one more time in the second > compute_submodule_clone_url() > > I think the abstraction overhead is not that big, though. Yeah, Junio made basically the same comment. So it would be nice if the commit message could mention we are adding a very small overhead in exchange for code simplification (10 lines removed).
Christian Couder <christian.couder@gmail.com> writes: > On Fri, Aug 6, 2021 at 2:54 AM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote: > >> While previous patch is definitely a refactoring, this patch add small >> overhead to the system, the new code will query (then free()) >> git_config_get_string() and/or xgetcwd() one more time in the second >> compute_submodule_clone_url() >> >> I think the abstraction overhead is not that big, though. > > Yeah, Junio made basically the same comment. So it would be nice if > the commit message could mention we are adding a very small overhead > in exchange for code simplification (10 lines removed). Okay, that makes sense.
Christian Couder <christian.couder@gmail.com> writes: > On Fri, Aug 6, 2021 at 2:54 AM Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote: > >> While previous patch is definitely a refactoring, this patch add small >> overhead to the system, the new code will query (then free()) >> git_config_get_string() and/or xgetcwd() one more time in the second >> compute_submodule_clone_url() >> >> I think the abstraction overhead is not that big, though. > > Yeah, Junio made basically the same comment. So it would be nice if > the commit message could mention we are adding a very small overhead > in exchange for code simplification (10 lines removed). If you guys want to, I wouldn't stop, but my comment was just a thinking-aloud observation, not a suggestion to add to the proposed log message. Thanks.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f4b496bac6..9b676c12f8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1373,20 +1373,10 @@ static void sync_submodule(const char *path, const char *prefix, if (sub && sub->url) { if (starts_with_dot_dot_slash(sub->url) || starts_with_dot_slash(sub->url)) { - char *remote_url, *up_path; - char *remote = get_default_remote(); - strbuf_addf(&sb, "remote.%s.url", remote); - - if (git_config_get_string(sb.buf, &remote_url)) - remote_url = xgetcwd(); - - up_path = get_up_path(path); - sub_origin_url = relative_url(remote_url, sub->url, up_path); - super_config_url = relative_url(remote_url, sub->url, NULL); - - free(remote); + char *up_path = get_up_path(path); + sub_origin_url = compute_submodule_clone_url(sub->url, up_path, 1); + super_config_url = compute_submodule_clone_url(sub->url, NULL, 1); free(up_path); - free(remote_url); } else { sub_origin_url = xstrdup(sub->url); super_config_url = xstrdup(sub->url);
This part of `sync_submodule()` is doing the same thing that `compute_submodule_clone_url()` is doing. Let's reuse that helper here. Signed-off-by: Atharva Raykar <raykar.ath@gmail.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Shourya Shukla <periperidip@gmail.com> --- builtin/submodule--helper.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)