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

Re: [PATCH 6/7] read-cache: refuse to create index referring to external objects

From
Duy Nguyen <pclouds@gmail.com>
Date
Jan 25, 2013, 02:00 UTC
Message-ID
<CACsJy8C3tLOHCK4Qc--W630do0M=xLKSMoYUxxv2_GDaUXaRww@mail.gmail.com>
In-Reply-To
<7vpq0ubdec.fsf@alter.siamese.dyndns.org>
On Fri, Jan 25, 2013 at 2:15 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  read-cache.c | 20 ++++++++++++++++++++
>>  1 file changed, 20 insertions(+)
>>
>> diff --git a/read-cache.c b/read-cache.c
>> index fda78bc..4579215 100644
>> --- a/read-cache.c
>> +++ b/read-cache.c
>> @@ -1720,6 +1720,26 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
>>                             ce->name + common, ce_namelen(ce) - common);
>>       }
>>
>> +     if (object_database_contaminated) {
>> +             struct object_info oi;
>> +             switch (ce->ce_mode) {
>> +             case S_IFGITLINK:
>> +                     break;
>> +             case S_IFDIR:
>> +                     if (sha1_object_info_extended(ce->sha1, &oi) != OBJ_TREE ||
>
> This case should never happen.  Do we store any tree object in the
> index in the first place?

No it was copy/paste mistake (from cache-tree.c, before I deleted it and added check_sha1_file_for_external_source in 3/7)

Show 22 quoted lines
>> +                         (oi.alt && oi.alt->external))
>> +                             die("cannot create index referring to an external tree %s",
>> +                                 sha1_to_hex(ce->sha1));
>> +                     break;
>> +             default:
>> +                     if (sha1_object_info_extended(ce->sha1, &oi) != OBJ_BLOB ||
>> +                                 (oi.alt && oi.alt->external))
>> +                             die("cannot create index referring to an external blob %s",
>> +                                 sha1_to_hex(ce->sha1));
>> +                     break;
>> +             }
>> +     }
>> +
>>       result = ce_write(c, fd, ondisk, size);
>>       free(ondisk);
>>       return result;
>
> I think the check you want to add is to the cache-tree code; before
> writing the new index out, if you suspect you might have called
> cache_tree_update() before, invalidate any hierarchy that is
> recorded to produce a tree object that refers to an object that is
> only available through external object store.

cache-tree is covered by check_sha1_file_for_external_source() when it actually writes a tree (dry-run mode goes through unchecked). Even when cache-tree is not involved, I do not want the index to point to an non-existing SHA-1 ("git diff --cached" may fail next time, for example).

Show 10 quoted lines
> As to the logic to check if a object is something that we should
> refuse to create a new dependent, I think you should not butcher
> sha1_object_info_extended(), and instead add a new call that checks
> if a given SHA-1 yields an object if you ignore alternate object
> databases that are marked as "external", whose signature may
> resemble:
>
>         int has_sha1_file_proper(const unsigned char *sha1);
>
> or something.
Agreed.
Show 16 quoted lines
> This is a tangent, but in addition, you may want to add an even
> narrower variant that checks the same but ignoring _all_ alternate
> object databases, "external" or not:
>
>         int has_sha1_file_local(const unsigned char *sha1);
>
> That may be useful if we want to later make the alternate safer to
> use; instead of letting the codepath to create an object ask
> has_sha1_file() to see if it already exists and refrain from writing
> a new copy, we switch to ask has_sha1_file_locally() and even if an
> alternate object database we borrow from has it, we keep our own
> copy in our repository.
>
> Not tested beyond syntax, but rebasing something like this patch on
> top of your "mark external sources" change may take us closer to
> that.
Thanks, will incorporate in the reroll.
-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 21 in “sha1_file: keep track of where an SHA-1 object comes from”
  1. 1/7 sha1_file: keep track of where an SHA-1 object comes fromNguyễn Thái Ngọc Duy, Jan 24, 2013
  2. 2/7 sha1_file: separate alt object db from own repos and submodules'sNguyễn Thái Ngọc Duy, Jan 24, 2013
  3. 3/7 sha1_file: refuse to write commits referring to external objectsNguyễn Thái Ngọc Duy, Jan 24, 2013
  4. 4/7 sha1_file: refuse to write trees referring to external objectsNguyễn Thái Ngọc Duy, Jan 24, 2013
  5. 5/7 sha1_file: refuse to write tags referring to external objectsNguyễn Thái Ngọc Duy, Jan 24, 2013
  6. 6/7 read-cache: refuse to create index referring to external objectsNguyễn Thái Ngọc Duy, Jan 24, 2013
  7. Junio C HamanoJan 24, 2013
  8. Duy NguyenJan 25, 2013
  9. Junio C HamanoJan 25, 2013
  10. Duy NguyenJan 28, 2013
  11. Junio C HamanoJan 28, 2013
  12. Duy NguyenJan 28, 2013
  13. Junio C HamanoJan 28, 2013
  14. Duy NguyenJan 28, 2013
  15. Junio C HamanoJan 28, 2013
  16. Duy NguyenJan 28, 2013
  17. 7/7 refs: do not update ref(log) referring to external objectsNguyễn Thái Ngọc Duy, Jan 24, 2013
  18. Junio C HamanoJan 24, 2013
  19. Duy NguyenJan 25, 2013
  20. Junio C HamanoJan 25, 2013
  21. Duy NguyenJan 25, 2013

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.