Live data from Hacker News

Artisanal handcrafted Git repositories

drew.silcock.dev

41–50 of 74 posts

Re: Artisanal handcrafted Git repositories

#42

Neat to see this done by hand! It helps demystify the magic behind git commands. If you like this, I also recommend "Write Yourself a Git", where you build a minimal git implementation using python: https://wyag.thb.lt/

There is also James Coglan's "Building git" book that I just went through and can vouch for its quality.

Re: Artisanal handcrafted Git repositories

#43

My recent horror from some git work was discovering how git sorts its tree objects. The docs just say to sort by C locale (byte-order sorting). Easy. Except git was sometimes rejecting my packfiles as being bogus per its fsck code, saying my trees were misordered. TURNS OUT THERE'S AN UNDOCUMENTED RULE: you need to append an implicit forward slash to directory tree entry names before you sort them. That forward slash…

[deleted]

Re: Artisanal handcrafted Git repositories

#44

My recent horror from some git work was discovering how git sorts its tree objects. The docs just say to sort by C locale (byte-order sorting). Easy. Except git was sometimes rejecting my packfiles as being bogus per its fsck code, saying my trees were misordered. TURNS OUT THERE'S AN UNDOCUMENTED RULE: you need to append an implicit forward slash to directory tree entry names before you sort them. That forward slash…

> directory tree entry names

But... git doesn't really store directories, does it?

Re: Artisanal handcrafted Git repositories

#45

My recent horror from some git work was discovering how git sorts its tree objects. The docs just say to sort by C locale (byte-order sorting). Easy. Except git was sometimes rejecting my packfiles as being bogus per its fsck code, saying my trees were misordered. TURNS OUT THERE'S AN UNDOCUMENTED RULE: you need to append an implicit forward slash to directory tree entry names before you sort them. That forward slash…

> directory tree entry names But... git doesn't really store directories, does it?

I wrote a longer comment saying this (deleted now since I was wrong).

Turns out that Git does somewhat store dirs (in form of trees). See https://git-scm.com/book/en/v2/Git-Internals-Git-Objects (section "Tree Objects").

To understand op's repro look at the last two lines (objects in the tree) in each of their command outputs, not the files shown in the first few lines.

What I think op means is that the `testing` tree pointed in their first example is sorted after `testing.md` even though it's only called `testing` because it's being sorted as `testing/` and `/` is > `.` bytewise.

I'm not at a computer right now but it would be nice to test it with files named `testing.` and `testing0` since they are adjacent bytewise and would show the implicit forward slash more clearly with the tree object sitting between them.

This makes me wonder why Git can't just store an empty tree for empty dirs.

EDIT: did the Gist https://gist.github.com/alvaro-cuesta/bd0234e3e1a66819c7e9e9...

Notice the `git cat-file -p HEAD^{tree}` outputs.

Re: Artisanal handcrafted Git repositories

#46

My recent horror from some git work was discovering how git sorts its tree objects. The docs just say to sort by C locale (byte-order sorting). Easy. Except git was sometimes rejecting my packfiles as being bogus per its fsck code, saying my trees were misordered. TURNS OUT THERE'S AN UNDOCUMENTED RULE: you need to append an implicit forward slash to directory tree entry names before you sort them. That forward slash…

I've had this exact bug happen to me when I implemented my git clone.

The way I found out was that Github kept rejecting my push, because as I later discovered, my git history was invalid precisely due to entries being sorted improperly due to the forward slash requirement. I could have solved this with the real git, but the point was to use my tool exclusively for version control from inception, so I just deleted the .git folder. So, my git history appears to begin near the end of the whole cycle. But I did manage to learn a lot, both about git and about the language I implemented it in.

Re: Artisanal handcrafted Git repositories

#47

My recent horror from some git work was discovering how git sorts its tree objects. The docs just say to sort by C locale (byte-order sorting). Easy. Except git was sometimes rejecting my packfiles as being bogus per its fsck code, saying my trees were misordered. TURNS OUT THERE'S AN UNDOCUMENTED RULE: you need to append an implicit forward slash to directory tree entry names before you sort them. That forward slash…

> directory tree entry names But... git doesn't really store directories, does it?

Yes it does, it just doesn't store empty directories.

Re: Artisanal handcrafted Git repositories

#50
post #38

Git refers to the user-friendly commands as “porcelain” Ahhhhahahaha… “user friendly”. When compared to coding the repo by hand, I guess.

When compared to the "plumbing" commands. If you want to know more about git's plumbing vs porcelain metaphor, this is a good quick overview: https://stackoverflow.com/a/39848551
Post reply on HN