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

Re: [PATCH v2 00/10] Use a structure for object IDs.

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Mar 11, 2015, 16:08 UTC
Message-ID
<5500689A.5090101@alum.mit.edu>
In-Reply-To
<1425770645-628957-1-git-send-email-sandals@crustytoothpaste.net>
On 03/08/2015 12:23 AM, brian m. carlson wrote:
Show 26 quoted lines
> This is a patch series to convert some of the relevant uses of unsigned
> char [20] to struct object_id.
> 
> The goal of this series to improve type-checking in the codebase and to
> make it easier to move to a different hash function if the project
> decides to do that.  This series does not convert all of the codebase,
> but only parts.  I've dropped some of the patches from earlier (which no
> longer apply) and added others.
> 
> Certain parts of the code have to be converted before others to keep the
> patch sizes small, maintainable, and bisectable, so functions and
> structures that are used across the codebase (e.g. struct object) will
> be converted later.  Conversion has been done in a somewhat haphazard
> manner by converting modules with leaf functions and less commonly used
> structs first.
> 
> Since part of the goal is to ease a move to a different hash function if
> the project decides to do that, I've adopted Michael Haggerty's
> suggestion of using variables named "oid", naming the structure member
> "sha1", and using GIT_SHA1_RAWSZ and GIT_SHA1_HEXSZ as the constants.
> 
> I've been holding on to this series for a long time in hopes of
> converting more of the code before submitting, but realized that this
> deprived others of the ability to use the new structure and required me
> to rebase extremely frequently.
> [...]
I've added CC to several people who commented on v1.
I think this is a really interesting project and I hope that it works out.

In my opinion, the biggest risk (aside from the sheer amount of work required) is the issue that was brought up on the mailing list when you submitted v1 [1]: Converting an arbitrary (unsigned char *) to a (struct object_id *) is not allowed, because the alignment requirements of the latter might be stricter than those of the former. This means that if, for example, we are reading some data from disk or from the network, and we expect the 20 bytes starting with byte number 17 to be a SHA-1 in binary format, we used to be able to do

    unsigned char *sha1 = buf + 17;

and use sha1 like any other SHA-1, without the need for any copying. But we can't do the analogous

    struct object_id *oid = (struct object_id *)(buf + 17);

because the alignment is not necessarily correct. So in a pure "struct object_id" world, I think we would be forced to change such code to

    struct object_id oid;
    hashcpy(oid.sha1, buf + 17);

This uses additional memory and introduces copying overhead. Also, the lifetime of oid might exceed the scope of a function, so oid might have to be allocated on the heap and later freed. This adds more computational overhead, more memory overhead, and more programming effort to get it all right.

So as much as I like the idea of wrapping SHA-1s in objects, I think it would be a good idea to first make sure that we can all agree on a plan for dealing with situations like this. I can think of the following possibilities:

1. Maybe code that needs to handle SHA-1s with screwy alignment does not
exist, or maybe it does the copying anyway. I haven't actually checked.
2. Maybe somebody can prove that
       struct object_id *oid = (struct object_id *)(buf + 17);
   somehow *is* allowed by the C standard, or at least that it is
sufficiently portable for our purposes.
3. We accept the additional runtime costs and development effort for the
extra copies. To accept this approach, we would need some idea of which
areas of the code will be affected, and some estimate of how much
additional memory it would cost.
4. We continue to support working with SHA-1s declared to be (unsigned
char *) in some performance-critical code, even as we migrate most other
code to using SHA-1s embedded within a (struct object_id). This will
cost some duplication of code. To accept this approach, we would need an
idea of *how much* code duplication would be needed. E.g., how many
functions will need both (unsigned char *) versions and (struct
object_id *) versions?
5. We only make the change opportunistically. Whenever we find a
function that needs to work with non-struct-aligned SHA-1s, we leave the
function as-is rather than converting it or creating a second version
that works with object_id objects. This approach would leave the
codebase somewhat schizophrenic.

I'm not trying to dissuade you from this project, but I think that for your project to have a chance of success, we need an answer to this question. So let's confront it now rather than after you have invested lots more time and/or gotten patches merged.

Michael
[1] http://thread.gmane.org/gmane.comp.version-control.git/248054
-- 
Michael Haggerty
mhagger@alum.mit.edu
Previous: Kyle J. McKayNext: Junio C Hamano
Message 20 of 36 in “Use a structure for object IDs.”
  1. 00/10 Use a structure for object IDs.brian m. carlson, Mar 7, 2015
  2. 01/10 Define a structure for object IDs.brian m. carlson, Mar 7, 2015
  3. 02/10 Define utility functions for object IDs.brian m. carlson, Mar 7, 2015
  4. Duy NguyenMar 8, 2015
  5. brian m. carlsonMar 8, 2015
  6. Michael HaggertyMar 11, 2015
  7. 03/10 bisect.c: convert leaf functions to use struct object_idbrian m. carlson, Mar 7, 2015
  8. 04/10 archive.c: convert to use struct object_idbrian m. carlson, Mar 7, 2015
  9. Michael HaggertyMar 11, 2015
  10. brian m. carlsonMar 11, 2015
  11. 05/10 zip: use GIT_SHA1_HEXSZ for trailersbrian m. carlson, Mar 7, 2015
  12. 06/10 bulk-checkin.c: convert to use struct object_idbrian m. carlson, Mar 7, 2015
  13. 07/10 diff: convert struct combine_diff_path to object_idbrian m. carlson, Mar 7, 2015
  14. 08/10 commit: convert parts to struct object_idbrian m. carlson, Mar 7, 2015
  15. Michael HaggertyMar 11, 2015
  16. 09/10 patch-id: convert to use struct object_idbrian m. carlson, Mar 7, 2015
  17. 10/10 apply: convert threeway_stage to object_idbrian m. carlson, Mar 7, 2015
  18. Junio C HamanoMar 8, 2015
  19. Kyle J. McKayMar 11, 2015
  20. Michael HaggertyMar 11, 2015
  21. Junio C HamanoMar 11, 2015
  22. brian m. carlsonMar 13, 2015
  23. brian m. carlsonMar 11, 2015
  24. Junio C HamanoMar 12, 2015
  25. brian m. carlsonMar 12, 2015
  26. Michael HaggertyMar 12, 2015
  27. brian m. carlsonMar 12, 2015
  28. Duy NguyenMar 12, 2015
  29. Junio C HamanoMar 12, 2015
  30. Junio C HamanoMar 12, 2015
  31. Duy NguyenMar 13, 2015
  32. Junio C HamanoMar 13, 2015
  33. Duy NguyenMar 14, 2015
  34. Junio C HamanoMar 14, 2015
  35. Duy NguyenMar 15, 2015
  36. Junio C HamanoMar 15, 2015

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.