All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: "David Turner" <dturner@twopensource.com>,
	"Ramsay Jones" <ramsay@ramsayjones.plus.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH 05/38] refs: create a base class "ref_store" for files_ref_store
Date: Thu, 9 Jun 2016 16:10:34 +0200	[thread overview]
Message-ID: <575978DA.30608@alum.mit.edu> (raw)
In-Reply-To: <xmqqbn3drkwd.fsf@gitster.mtv.corp.google.com>

On 06/07/2016 07:03 PM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
> 
>> We want ref_stores to be polymorphic, so invent a base class of which
>> files_ref_store is a derived class. For now there is a one-to-one
>> relationship between ref_stores and submodules.
> 
> The mention of "submodules" made me go "Huh?" but thinking about it
> for a second it is clear and obvious.  We often peek into refs in a
> different repository that is a submodule, and we do not mix them with
> our own refs.  Logically that is what a "ref store" is, and one-to-one
> relationship is expected.
> 
>> @@ -1284,3 +1288,90 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
>>  	errno = ELOOP;
>>  	return NULL;
>>  }
>> +
>> +static struct ref_store *main_ref_store = NULL;
>> +
>> +static struct ref_store *submodule_ref_stores = NULL;
> 
> Let's let BSS take care of these initialization.

I like the `= NULL` because it expresses "yes, I care about the initial
values of these variables", which to me is more valuable than saving a
few bytes in the size of the executable. But in fact, GCC does the
obvious optimization: it detects that these variables are being
initialized to zero, and puts them in BSS anyway. I'd be surprised if
other compilers don't do the same. So I'd prefer to leave this as-is, if
it's OK with you.

>> [...]
>>  /*
>> + * Return a pointer to the reference store for the specified
>> + * submodule. For the main repository, use submodule==NULL; such a
>> + * call cannot fail. For a submodule, the submodule must exist and be
>> + * a nonbare repository, otherwise return NULL. Verify that the
>> + * reference store is a files_ref_store, and cast it to that type
>> + * before returning it.
>>   */
>> +static struct files_ref_store *get_files_ref_store(const char *submodule,
>> +						   const char *caller)
>>  {
>> +	struct ref_store *refs = get_ref_store(submodule);
>>  
>> +	return refs ? files_downcast(refs, 1, caller) : NULL;
>>  }
> 
> This comment may be barking up a wrong tree, but the support for
> class inheritance makes me wonder if I can do something along this
> line:
> 
>  * implement a filesystem based ref_store, that is very similar to
>    what you have as files_ref_store, but 
> 
>    - when storing a ref as a loose ref, or when checking if a ref
>      exists as a loose ref, quote them somehow (e.g. a branch
>      "Branch" is not stored as a file "$GIT_DIR/refs/heads/branch"
>      but by using "^" as a single shift marker, i.e. as
>      "$GIT_DIR/refs/heads/^branch");
> 
>    - when enumerating what refs we have as loose refs, unquote what
>      readdir(3) gave us, e.g. seeing "$GIT_DIR/refs/heads/^branch",
>      I say "there is a branch whose name is 'Branch'".
> 
>  * as locking and other 'methods' are likely to be very similar to
>    your files_ref_store, make this new backend as a subclass of it,
>    i.e. create a new class but function pointers to many methods are
>    copied from files ref_store vtable.

That is definitely something we could implement in the future. If I were
going to design an extension like this, I think I'd go straight to
something more expressive; maybe something like URL-encoding. For
example, we might like a system that can record refnames with a Unicode
encoding that is determined by us rather than by the filesystem.

Depending on the details, it might be preferable to implement the new
ref-store as an encoding layer that delegates to an old-fashioned files
backend rather than using inheritance. In fact, you'd only want to do
the translation for the loose storage part, so in the end the
implemention might look something like

    overlay_ref_store(
        encoding_ref_store(loose_ref_store()),
        packed_ref_store())

> Would the strict "when downcasting to 'files', we make sure vtable
> is that of 'files' backend" interfere with such an approach?

True, the simple approach that I use above doesn't generalize to
implementation inheritance. But I'd rather cross that bridge when we
come to it. Implementing an RTTI system in C is a bit ambitious and, I
think, comes with runtime costs.

Michael

  reply	other threads:[~2016-06-09 14:10 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 21:03 [PATCH 00/38] Virtualization of the refs API Michael Haggerty
2016-06-03 21:03 ` [PATCH 01/38] resolve_gitlink_ref(): eliminate temporary variable Michael Haggerty
2016-06-03 21:03 ` [PATCH 02/38] rename_ref_available(): add docstring Michael Haggerty
2016-06-07 18:10   ` Junio C Hamano
2016-06-09 13:09     ` Michael Haggerty
2016-06-09 15:08       ` Junio C Hamano
2016-06-03 21:03 ` [PATCH 03/38] refs: rename struct ref_cache to files_ref_store Michael Haggerty
2016-06-03 21:03 ` [PATCH 04/38] refs: add a backend method structure Michael Haggerty
2016-06-03 21:03 ` [PATCH 05/38] refs: create a base class "ref_store" for files_ref_store Michael Haggerty
2016-06-07 16:31   ` Junio C Hamano
2016-06-09 21:54     ` René Scharfe
2016-06-07 17:03   ` Junio C Hamano
2016-06-09 14:10     ` Michael Haggerty [this message]
2016-06-09 16:14       ` Junio C Hamano
2016-06-10  6:18         ` Michael Haggerty
2016-06-10 15:53           ` Junio C Hamano
2016-06-10  8:08   ` Eric Sunshine
2016-06-10 12:02     ` Michael Haggerty
2016-06-03 21:03 ` [PATCH 06/38] add_packed_ref(): add a files_ref_store argument Michael Haggerty
2016-06-03 21:03 ` [PATCH 07/38] get_packed_ref(): " Michael Haggerty
2016-06-03 21:03 ` [PATCH 08/38] resolve_missing_loose_ref(): " Michael Haggerty
2016-06-03 21:03 ` [PATCH 09/38] {lock,commit,rollback}_packed_refs(): add files_ref_store arguments Michael Haggerty
2016-06-03 21:03 ` [PATCH 10/38] refs: add a transaction_commit() method Michael Haggerty
2016-06-03 21:03 ` [PATCH 11/38] refs: reorder definitions Michael Haggerty
2016-06-03 21:03 ` [PATCH 12/38] resolve_packed_ref(): rename function from resolve_missing_loose_ref() Michael Haggerty
2016-06-03 21:03 ` [PATCH 13/38] resolve_gitlink_packed_ref(): remove function Michael Haggerty
2016-06-03 21:03 ` [PATCH 14/38] read_raw_ref(): take a (struct ref_store *) argument Michael Haggerty
2016-06-03 21:03 ` [PATCH 15/38] resolve_ref_recursively(): new function Michael Haggerty
2016-06-03 21:03 ` [PATCH 16/38] resolve_gitlink_ref(): implement using resolve_ref_recursively() Michael Haggerty
2016-06-07 17:19   ` Junio C Hamano
2016-06-14  5:03   ` Eric Sunshine
2016-06-16  4:03     ` Michael Haggerty
2016-06-03 21:03 ` [PATCH 17/38] resolve_gitlink_ref(): avoid memory allocation in many cases Michael Haggerty
2016-06-07 17:29   ` Junio C Hamano
2016-06-09 14:37     ` Michael Haggerty
2016-06-03 21:03 ` [PATCH 18/38] resolve_gitlink_ref(): rename path parameter to submodule Michael Haggerty
2016-06-03 21:03 ` [PATCH 19/38] refs: make read_raw_ref() virtual Michael Haggerty
2016-06-03 21:03 ` [PATCH 20/38] refs: make verify_refname_available() virtual Michael Haggerty
2016-06-03 21:03 ` [PATCH 21/38] refs: make pack_refs() virtual Michael Haggerty
2016-06-07 17:35   ` Junio C Hamano
2016-06-09 14:46     ` Michael Haggerty
2016-06-03 21:03 ` [PATCH 22/38] refs: make create_symref() virtual Michael Haggerty
2016-06-03 21:03 ` [PATCH 23/38] refs: make peel_ref() virtual Michael Haggerty
2016-06-07 17:36   ` Junio C Hamano
2016-06-09 15:05     ` Michael Haggerty
2016-06-03 21:03 ` [PATCH 24/38] repack_without_refs(): add a files_ref_store argument Michael Haggerty
2016-06-03 21:04 ` [PATCH 25/38] lock_raw_ref(): " Michael Haggerty
2016-06-03 21:04 ` [PATCH 26/38] commit_ref_update(): " Michael Haggerty
2016-06-03 21:04 ` [PATCH 27/38] lock_ref_for_update(): " Michael Haggerty
2016-06-03 21:04 ` [PATCH 28/38] lock_ref_sha1_basic(): " Michael Haggerty
2016-06-03 21:04 ` [PATCH 29/38] split_symref_update(): " Michael Haggerty
2016-06-03 21:04 ` [PATCH 30/38] files_ref_iterator_begin(): take a ref_store argument Michael Haggerty
2016-06-03 21:04 ` [PATCH 31/38] refs: add method iterator_begin Michael Haggerty
2016-06-03 21:04 ` [PATCH 32/38] refs: add methods for reflog Michael Haggerty
2016-06-03 21:04 ` [PATCH 33/38] refs: add method for initial ref transaction commit Michael Haggerty
2016-06-03 21:04 ` [PATCH 34/38] refs: add method for delete_refs Michael Haggerty
2016-06-07 17:43   ` Junio C Hamano
2016-06-09 15:14     ` Michael Haggerty
2016-06-03 21:04 ` [PATCH 35/38] refs: add methods to init refs db Michael Haggerty
2016-06-03 21:04 ` [PATCH 36/38] refs: add method to rename refs Michael Haggerty
2016-06-03 21:04 ` [PATCH 37/38] refs: make lock generic Michael Haggerty
2016-06-07 17:50   ` Junio C Hamano
2016-06-09 15:21     ` Michael Haggerty
2016-06-09 15:53     ` Michael Haggerty
2016-06-03 21:04 ` [PATCH 38/38] refs: implement iteration over only per-worktree refs Michael Haggerty
2016-07-10 15:09 ` [PATCH 00/38] Virtualization of the refs API Duy Nguyen
2016-07-13 15:26   ` Michael Haggerty

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

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

  git send-email \
    --in-reply-to=575978DA.30608@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sunshine@sunshineco.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.