git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Olga Telezhnaya <olyatelezhnaya@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH Outreachy] mru: use double-linked list from list.h
Date: Thu, 28 Sep 2017 16:47:05 -0400	[thread overview]
Message-ID: <20170928204705.7ixxspiflmhsdh7d@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq8tgz13x7.fsf@gitster.mtv.corp.google.com>

On Thu, Sep 28, 2017 at 08:03:00PM +0900, Junio C Hamano wrote:

> > -	for (entry = packed_git_mru.head; entry; entry = entry->next) {
> > +	list_for_each(pos, &packed_git_mru.list) {
> > +		struct mru *entry = list_entry(pos, struct mru, list);
> >  		struct packed_git *p = entry->item;
> >  		off_t offset;
> 
> I was a bit surprised to see a change outside mru.[ch] like this
> one.  The reason why I was surprised was because I expected mru.[ch]
> would offer its own API that encapsulates enumeration like this one
> and this patch would just be reimplementing that API using the list
> API, instead of rewriting the users of mru API to directly access
> the list API.
> 
> Alas, there is no such mru API that lets a mru user to iterate over
> elements, so the original of the above code were using mru's
> implementation detail directly.
> 
> We probably want to invent mru_for_each() that hides the fact that
> mru is implemented in terms of list_head from the users of mru API
> and use it here.

I agree that the caller would be a little shorter with an mru-specific
iterator (e.g., we could probably do the list_entry() part
automatically).

But I also think this patch may be a stepping stone to dropping "struct
mru" entirely, and just pushing a "struct list_head mru" into the
packed_git object itself (or of course any object you like). At which
point we'd just directly use the list iterators anyway.

(One could argue that if that's our end goal, we could go straight
there. But I think this middle state has value, because the individual
steps are easier to verify).

> > @@ -8,18 +10,15 @@
> >   *
> >   *   // Create a list.  Zero-initialization is required.
> >   *   static struct mru cache;
> > - *   mru_append(&cache, item);
> > - *   ...
> > + *   INIT_LIST_HEAD(&cache.list);
> 
> "Zero-initialization is required." is no longer true, it seems, and
> the comment above needs to be updated, right?
> 
> More importantly, this leaks to the user of the API the fact that
> mru is internally implemented in terms of the list API, which is
> not necessary (when we want to update the implementation later, we'd
> need to update all the users again).  Perhaps you'd want
> 
> 	INIT_MRU(cache);
> 
> which is #define'd in this file, perhaps like so:
> 
> 	#define INIT_MRU(mru)	INIT_LIST_HEAD(&((mru).list))

I'd make the same claims here as above (both that I agree your proposed
interface looks nicer, but also that I think we eventually do want to
expose that this is tightly coupled with list.h).

-Peff

  reply	other threads:[~2017-09-28 20:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27 10:18 [PATCH] [Outreachy] cleanup: use list.h in mru.h and mru.c Оля Тележная
2017-09-27 11:30 ` Christian Couder
2017-09-28  8:38   ` [PATCH Outreachy] mru: use double-linked list from list.h Olga Telezhnaya
2017-09-28 11:03     ` Junio C Hamano
2017-09-28 20:47       ` Jeff King [this message]
2017-09-28 21:56         ` Junio C Hamano
2017-09-28 22:19           ` Jeff King
2017-09-28 21:04     ` Jeff King
2017-09-28 22:42     ` Jeff King
2017-09-29  7:18       ` Christian Couder
2017-09-29  7:23         ` Jeff King
2017-09-29 11:50           ` Christian Couder
2017-09-29 16:08             ` Оля Тележная
2017-09-29 20:38               ` Оля Тележная
2017-09-29 23:40                 ` Jeff King
2017-09-30 18:09                   ` Оля Тележная
2017-10-02  8:22                     ` Jeff King
2017-09-29 23:37               ` Jeff King
2017-09-30  0:07                 ` Junio C Hamano
2017-09-30 17:51     ` [PATCH v2 " Olga Telezhnaya
2017-10-02  8:20       ` Jeff King
2017-10-02  9:37         ` Оля Тележная
2017-10-03 10:10           ` Jeff King
2017-11-08  1:44         ` Junio C Hamano
2017-11-08  4:22           ` Jeff King
2017-11-10 11:51             ` Оля Тележная

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170928204705.7ixxspiflmhsdh7d@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=olyatelezhnaya@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).