Thread (1 message) 1 message, 1 author, 2021-02-20

Re: Re: [PATCH v3] builtin/clone.c: add --reject-shallow option

From: lilinchao@oschina.cn <hidden>
Date: 2021-02-20 11:09:59



--------------
lilinchao@oschina.cn
"lilinchao@oschina.cn" [off-list ref] writes:
quoted
Sorry, you may forget there is a re-read git-config under these lines
Ahhhh, thanks.  You're right that "clone" is "special" in that way
and requires unusual order---I forgot about that.
quoted
quoted
This is only for cloning from a local repository, no?  IOW, path at
this point may even be "git://github.com/git/git/" and checking with
access() does not make sense.

Ah, it is even worse.  get_repo_path() can return NULL, so mkpath()
will crash in such a case.  This must be at least

if (path && !access(mkpath("%s/shallow", path), F_OK))
is_shallow = 1;
...

So, I think the above two hunks are making the code worse.  If we
are to detect and reject cloning from the shallow repository when
going through the transport layer (i.e. "--no-local" or cloning from
"git://github.com/git/git", or "https://github.com/git/git", if it
were a shallow repository), that must be handled separately.
Sorry, I made the question simple. Reject cloning a shallow repository
should apply to all four type transport protocols. There still a bunch of
work to be done.
Sorry, but I didn't realize that this is just a work-in-progress
that shows an early "only local transport is covered" preview.  I
think, modulo that the access(mkpath()) thing should be in the "if
(is_local)" block, the patch covers the case of local transport well
enough.  I think by "four types of transport" you mean ssh://, git://
https:// etc., but they all go through the same transport API, so
hopefully once one of them, say, git://, is covered, that would take
us a long way.
Hi, after some exploration, I found that the following changes
can achieve the goal:
(around at line 1386 in builtin/clone.c)
    /* below part is my changes */
            if (reject_shallow) {
                    if (local_shallow || is_repository_shallow(the_repository)) {
                            die(_("source repository is shallow, reject to clone."));
                    }
            }
    /* end */
            update_remote_refs(refs, mapped_refs, remote_head_points_at,
                               branch_top.buf, reflog_msg.buf, transport,
                               !is_local);

as it shows, using existing method "is_repository_shallow" to detect
whether the repo is shallow or not, before "update_remote_refs"
I made some tests based on this change, and it seems ok.
what do you think about this?

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help