'git ls-remote' to limit the number of returned lines

We can use the command git ls-remoteto get the list of commits of this git repository, for example. discussion

This command takes quite a while for a repo that has a large list of commits / tags - we are looking for a parameter and / or any other command for it to limit the number of returned lines, for example. just read the first 3 lines in the returned list.

How can we do this?

ps

My google search and our site search helps a little.

+4
source share
1 answer

git ls-remote :

int cmd_ls_remote(int argc, const char **argv, const char *prefix)
{
   ...

    transport = transport_get(remote, NULL);
    if (uploadpack != NULL)
        transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);

/* Get all refs from the remote */
    ref = transport_get_remote_refs(transport);
    if (transport_disconnect(transport))
        return 1;

    if (!dest && !quiet)
        fprintf(stderr, "From %s\n", *remote->url);

/* Filter the list of all refs */
    for ( ; ref; ref = ref->next) {
        if (!check_ref_type(ref, flags))
            continue;
        if (!tail_match(pattern, ref->name))
            continue;
        if (show_symref_target && ref->symref)
            printf("ref: %s\t%s\n", ref->symref, ref->name);
        printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
        status = 0; /* we found something */
    }
    return status;
}

UPDATE

, git , , refs/heads/branchname (, curl).

, HTTP, , . "", Git - ; HTTP GET, git .

...

, , , , , git, , git ls-remote ( , transport_get_remote_refs()). , , , .

-

...

, git send-pack receive-pack. send-pack receive-pack .

...

git-receive-pack .

...

fetch-pack upload-pack. fetch-pack, upload-pack .

...

fetch-pack , upload-pack - this:... , receive-pack, (.. refs + some ).

...

+6

Source: https://habr.com/ru/post/1682023/


All Articles