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

Re: [PATCH] submodule: Port resolve_relative_url from shell to C

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jan 13, 2016, 22:03 UTC
Message-ID
<CAPig+cTpghLgRdCCHu6CdM0v4TzytsOFFuE5p9=Z0myZ7+5xLQ@mail.gmail.com>
In-Reply-To
<1452708927-9401-1-git-send-email-sbeller@google.com>
On Wed, Jan 13, 2016 at 1:15 PM, Stefan Beller <sbeller@google.com> wrote:
Show 14 quoted lines
> Later on we want to deprecate the `git submodule init` command and make
> it implicit in other submodule commands. As these other commands are
> written in C already, we'd need the init functionality in C, too.
> The `resolve_relative_url` function is a rather large part of that init
> functionality, so start by porting this function to C.
>
> As I was porting the functionality I noticed some odds with the inputs.
> To fully understand the situation I added some logging to the function
> temporarily to capture all calls to the function throughout the test
> suite. Duplicates have been removed and all unique testing inputs have
> been recorded into t0060.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
No time presently for a proper review, so just a few superficial comments...
Show 13 quoted lines
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> @@ -9,6 +9,193 @@
> +static int resolve_relative_url(int argc, const char **argv, const char *prefix)
> +{
> +       char *remoteurl = NULL;
> +       char *remote = get_default_remote();
> +       const char *up_path = NULL;
> +       char *res;
> +       const char *url;
> +       struct strbuf sb = STRBUF_INIT;
> +
> +       if (argc != 2 && argc != 3)
> +               die("BUG: resolve_relative_url only accepts one or two arguments");

This is diagnosing incorrect arguments, so: s/resolve_relative_url/resolve-relative-url/

Also, I'm not convinced that this deserves a "BUG:" prefix, as this is now a user-accessible command (even though it's plumbing).

Show 25 quoted lines
> +       url = argv[1];
> +       strbuf_addf(&sb, "remote.%s.url", remote);
> +       free(remote);
> +
> +       if (git_config_get_string(sb.buf, &remoteurl))
> +               /* the repository is its own authoritative upstream */
> +               remoteurl = xgetcwd();
> +
> +       if (argc == 3)
> +               up_path = argv[2];
> +
> +       res = relative_url(remoteurl, url, up_path);
> +       printf("%s\n", res);
> +
> +       free(res);
> +       return 0;
> +}
> +
> +static int resolve_relative_url_test(int argc, const char **argv, const char *prefix)
> +{
> +       char *remoteurl, *res;
> +       const char *up_path, *url;
> +
> +       if (argc != 4)
> +               die("BUG: resolve_relative_url only accepts three arguments: <up_path> <remoteurl> <url>");
s/resolve_relative_url/resolve-relative-url/
Ditto observation about "BUG:" prefix.
Show 9 quoted lines
> +       up_path = argv[1];
> +       remoteurl = xstrdup(argv[2]);
> +       url = argv[3];
> +
> +       if (!strcmp(up_path, "(null)"))
> +               up_path = NULL;
> +
> +       res = relative_url(remoteurl, url, up_path);
> +       printf("%s\n", res);
This could be:
     puts(res);
though I don't care strongly.
> +       free(res);
> +       return 0;
> +}
Previous: Stefan BellerNext: Stefan Beller
Message 11 of 12 in “submodule: Port resolve_relative_url from shell to C”
  1. submodule: Port resolve_relative_url from shell to CStefan Beller, Jan 13, 2016
  2. Junio C HamanoJan 13, 2016
  3. Stefan BellerJan 13, 2016
  4. Jens LehmannJan 14, 2016
  5. Stefan BellerJan 14, 2016
  6. Junio C HamanoJan 15, 2016
  7. Stefan BellerJan 15, 2016
  8. Junio C HamanoJan 15, 2016
  9. Johannes SixtJan 14, 2016
  10. Stefan BellerJan 14, 2016
  11. Eric SunshineJan 13, 2016
  12. Stefan BellerJan 13, 2016

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.