Re: [GSoC] [PATCH v4 3/8] submodule--helper: remove repeated code in sync_submodule()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/08/21 12:46 pm, Atharva Raykar wrote:
This part of `sync_submodule()` is doing the same thing that
`compute_submodule_clone_url()` is doing. Let's reuse that helper here.


Nice to see more code redundancy being removed. Now that we're using
'compute_submodule_clone_url' in multiple places, I'm starting to
wonder if the name still suits the helper. Yeah, I just started yet
another naming discussion ;-) I guess this one wouldn't be tough though.
It feels to me like 'resolve_relative_url' is a good enough name that
doesn't mislead readers by having 'clone_url' in its name. In case anyone
else has better name suggestions, they are indeed very welcome to suggest
those :-)

Once there's agreement on a particular name, I think the helper function
could be renamed. Possibly in a new patch next to this one.

Note that this change adds a small overhead where we allocate and free
the 'remote' twice, but that is a small price to pay for the higher
level of abstraction we get.

Signed-off-by: Atharva Raykar <raykar.ath@xxxxxxxxx>
Mentored-by: Christian Couder <christian.couder@xxxxxxxxx>
Mentored-by: Shourya Shukla <periperidip@xxxxxxxxx>
---
  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);
  			free(up_path);
-			free(remote_url);
  		} else {
  			sub_origin_url = xstrdup(sub->url);
  			super_config_url = xstrdup(sub->url);



--
Sivaraam



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux