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

Re: [PATCH v3 1/1] refspec: add support for negative refspecs

From
Jacob Keller <jacob.keller@gmail.com>
Date
Sep 30, 2020, 20:49 UTC
Message-ID
<CA+P7+xpDoqspwEG_PABvP33FL-+mo6zXvWxf5FKOiSrydXjBKQ@mail.gmail.com>
In-Reply-To
<nycvar.QRO.7.76.6.2009301428580.50@tvgsbejvaqbjf.bet>

On Wed, Sep 30, 2020 at 5:36 AM Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

Show 81 quoted lines
>
> Hi Jake,
>
> On Fri, 25 Sep 2020, Jacob Keller wrote:
>
> > diff --git a/remote.c b/remote.c
> > index eafc14cbe759..26a127142344 100644
> > --- a/remote.c
> > +++ b/remote.c
> > @@ -682,6 +682,91 @@ static int match_name_with_pattern(const char *key, const char *name,
> >       return ret;
> >  }
> >
> > +static int refspec_match(const struct refspec_item *refspec,
> > +                      const char *name)
> > +{
> > +     if (refspec->pattern)
> > +             return match_name_with_pattern(refspec->src, name, NULL, NULL);
> > +
> > +     return !strcmp(refspec->src, name);
> > +}
> > +
> > +static int omit_name_by_refspec(const char *name, struct refspec *rs)
> > +{
> > +     int i;
> > +
> > +     for (i = 0; i < rs->nr; i++) {
> > +             if (rs->items[i].negative && refspec_match(&rs->items[i], name))
> > +                     return 1;
> > +     }
> > +     return 0;
> > +}
> > +
> > +struct ref *apply_negative_refspecs(struct ref *ref_map, struct refspec *rs)
> > +{
> > +     struct ref **tail;
> > +
> > +     for (tail = &ref_map; *tail; ) {
> > +             struct ref *ref = *tail;
> > +
> > +             if (omit_name_by_refspec(ref->name, rs)) {
> > +                     *tail = ref->next;
> > +                     free(ref->peer_ref);
> > +                     free(ref);
> > +             } else
> > +                     tail = &ref->next;
> > +     }
> > +
> > +     return ref_map;
> > +}
> > +
> > +static int query_matches_negative_refspec(struct refspec *rs, struct refspec_item *query)
> > +{
> > +     int i, matched_negative = 0;
> > +     int find_src = !query->src;
> > +     struct string_list reversed = STRING_LIST_INIT_NODUP;
> > +     const char *needle = find_src ? query->dst : query->src;
> > +
> > +     /*
> > +      * Check whether the queried ref matches any negative refpsec. If so,
> > +      * then we should ultimately treat this as not matching the query at
> > +      * all.
> > +      *
> > +      * Note that negative refspecs always match the source, but the query
> > +      * item uses the destination. To handle this, we apply pattern
> > +      * refspecs in reverse to figure out if the query source matches any
> > +      * of the negative refspecs.
> > +      */
> > +     for (i = 0; i < rs->nr; i++) {
> > +             struct refspec_item *refspec = &rs->items[i];
> > +             char *expn_name;
> > +
> > +             if (refspec->negative)
> > +                     continue;
> > +
> > +             /* Note the reversal of src and dst */
> > +             if (refspec->pattern) {
> > +                     const char *key = refspec->dst ?: refspec->src;
>
> Would you mind fixing this? This keeps getting reverted...
>
Ack.... I swore I fixed this... I'm not sure what happened on my end here.
Previous: Johannes SchindelinNext: Junio C Hamano
Message 5 of 7 in “implement negative refspecs”
  1. 0/1 implement negative refspecsJacob Keller, Sep 25, 2020
  2. 1/1 refspec: add support for negative refspecsJacob Keller, Sep 25, 2020
  3. Junio C HamanoSep 29, 2020
  4. Johannes SchindelinSep 30, 2020
  5. Jacob KellerSep 30, 2020
  6. Junio C HamanoSep 30, 2020
  7. Jacob KellerSep 30, 2020

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.