Repository navigation
Description
If you missed my team update from last week, I made some progress on large assets on Friday. I have functioning git-media filters for dealing with large assets. This is how it works in a nut shell:
- When you
git adda file, Git passes them through a "clean" filter.git-mediacleans large files by replacing them with meta data pointing to the file. - When Git checks out a file to the working directory, it runs them through a "smudge" filter. Files are untouched unless it detects large asset meta data.
I want to get some comments on the metadata as early as possible. Once meta data is committed, we can't easily change it. I'm taking cues from @schacon's git-media and assman projects. I want a format that is ascii friendly (works fine with plain Git), but easily parsed. Currently it's simply a JSON file with one or more # comment lines. This format needs to be something easily parsed so that every interface to GitHub understands how to read or write the real file as needed.
# This is a placeholder for large media....
{"media_type": "application/vnd.github.large-asset", "size": 123, "md5": "....", "sha1": "..."}
Assman only records the SHA. Though when talking to @nickh about Subversion integration, he mentioned MD5. This seems to be a good place to get any meta data or signatures that we need. Unfortunately, the filters only work through STDIN data. They have no idea what the file name or type is.
I'm currently writing this in Go. It's really easy to cross compile static binaries for every major platform, (even Windows). The git media stuff should be easy to port to c if needed though. I would just need a patient c buddy.
/cc @github/mac @github/windows @github/importexport @arrbee @peff
Please let me know if I missed someone or you don't want to be spammed by this stuff. Or better yet, join the @github/large-assets team :) We can create a large-assets-integration team too.
Activity
peff commentedon Oct 2, 2013
As you said, we need to be careful with the metadata because it's going to be hard to change later. I think in general you want to put as little as possible into the git object, and keep it to things that describe the content itself.
Anything else that might change is going to cause changes in the path at the git level, which is going to make false positives during traversals (e.g., "git log -- large-asset" will mention commits that change only the metadata, not the content itself).
To that end, what is the purpose of the
media_typefield? I can kind of see it as a magic token to show that this is being handled by git-media. On the other hand, that is not a function of the content itself, but rather how we are handling it (and that is specified elsewhere in the .gitattributes file).If it's purely a token to say "this is a placeholder", I think it's probably OK, because it should never change. If it is used for more (like deciding that this is a GitHub asset), then it's probably a bad thing. You would want the metadata to be system-independent, so that if people switch large media asset providers, they do not need to change anything inside the git history (i.e., in an ideal world we want to create an open standard for this metadata, not just something for our own product).
The size is redundant with the sha1, but it is a function of the content, and I can see it being useful for the client side making decisions about whether to fetch the object. Ditto for the md5, which is redundant but potentially useful for interfacing with other systems. The downside is that we have to carry it around forever, even if md5 eventually becomes irrelevant.
I think using a format like JSON is a good thing, as it's readable but leaves room for extensibility if we need it. However, there are many ways of representing the same content in JSON (e.g., placement of whitespace and newlines, quoting, etc). You might want to specify a canonical representation for the JSON so that we do not have two implementations generating semantically-equivalent but syntactically-different metadata (which would again cause false positives to git's tree-diff).
technoweenie commentedon Oct 2, 2013
The media type identifies the object as meta data for a Git large asset. Using an agnostic media type is an excellent idea. I do plan to have a fully open spec at least for all this. I can see the galactus repo (it will be renamed of course) being OSS too.
I only added md5 because I think our SVN system needs it. If not, I'll gladly drop it. The really nice thing about JSON is you can ignore or even add fields. I did plan on writing a custom JSON encoder for it. I was wanting something with alphabetical fields and pretty spacing:
{ "md5": "....", "media_type": "application/vnd.git.large-asset", "sha1": "...", "size": 123 }I may be one of the 0.5% that loves comma-first style :)
{ "md5": "...." , "media_type": "application/vnd.git.large-asset" , "sha1": "..." , "size": 123 }peff commentedon Oct 2, 2013
Also note that filters can get the file's path by using
%fon their command line. But it is probably not a good idea to put that information into the metadata, as it is not a property of the content (so if you renamed the file, you would want git to represent that as a pure movement of the content sha1 within the git tree).technoweenie commentedon Oct 2, 2013
Interesting. Would it be worth it to parse file types? Imagine being able to get width/height dimensions on images, for example. I'll hold off until there's a solid use case though.
arrbee commentedon Oct 2, 2013
I like it! To me, it seems okay for the metadata placeholder to keep redundant signatures of the file so long as each item is stable and has a known purpose. To that extent,
size,sha1, andmd5seem like a useful base set of stable signature data.I have a bad idea that I want to at least bring up just because I'm curious what folks think.
One other stable piece of metadata that seems like it could be really useful would be the detected type of the file data (equivalent to the output of the
filecommand, such asJPEG image data, JFIF standard 1.01orPDF document, version 1.2). At least for a given revision of/usr/share/file/magicthis should be stable and would be useful in making decisions about retrieving and handling the file data.I know it's a bad idea, at the very least because it would make implementation of the
cleanfilter significantly less portable, but I felt like I should at least bring it up because it would be useful in writing retrieval and caching rules (as opposed to implied type from filenames which is not stable).arrbee commentedon Oct 2, 2013
Sorry, I missed that update while I was writing my last comment. As an alternative to the output of
file, there is the output of a fixed version ofidentifywhich could be stripped down to something likeJPEG 128x128 8-bit sRGB.I think the use case is if someone wants to say "I'm working on my game and I need all the GIF and JPEG files because I need to apply textures to the models, but I don't need the TIFF and PSD files because I won't be working updates to the art assets."
technoweenie commentedon Oct 2, 2013
@arrbee: I thought about that too. I don't think Go has something for this, and I would really like this to be portable on Windows. We could get a lot of that from the filename extension too. Obviously we'd need to convert duplicate extensions like "jpg" and "jpeg" to something canonical ("image/jpeg", if we're going for mime types).
One possible issue with filename extensions is that we won't have 100% support in v1. If we added support for a new format, all existing files would be missing that metadata. Perhaps not the end of the world.
I want to get the basics up and running, and see if we can get some sweet Render action without this meta data. Render should be able to use a URL like "https://pdf-thumbnail-thingy.github.com/SHA" to embed a PDF thumbnail based on the filename.
peff commentedon Oct 2, 2013
File mime-types or other metadata (like image size) may be useful to a client in deciding whether they want a file. And they are properties of the content itself, which is good. But they also open a small can of worms in terms of implementations. Different systems may have different types for a given file, or may not understand its type at all (and therefore do not fill in width/height fields). What I'm worried about is two devs on the project with different systems whose clean filters produce
"file_type": "image/gif", "width": 640, "height": 480and"file_type: "application/octet-stream"respectively. The metadata ping-pongs back and forth between their commits, and it looks like every commit touches the file (even though it is just noise caused by an inconsistentcleanfilter). If they haven't touched the file, git shouldn't need to re-run the filter, but it often happens anyway (because the mtime on the file is updated for some reason, or because the index and file timestamps are the same, so git runs the clean filter to double-check that it's not a racy index).The absolute simplest thing you can put in the metadata is a single line with just the 40-byte sha1 hash. That's a sufficient and generic UUID for any asset system to look up the entry. And then all of this extra information could be stored and provided by the asset system itself. In other words, instead of the client saying "Oh, it has size 123, I should fetch it", it could collect the list of sha1s it has media-pointers for, then request (and probably cache) the index from the asset server. And then based on the information in the index (including size, file type, and other metadata), decide which assets to fetch.
It is slightly more complex, but it makes the git portion dead-simple, and extending the metadata later becomes easy without worrying about changing the git history.
technoweenie commentedon Oct 2, 2013
Rick Olson
arrbee commentedon Oct 2, 2013
I think that any use of file type data would have to rely on embedded logic that was not dependent on system. Also, the logic would have to written in a way so that extra data inserted into a metadata blob on another system was preserved untouched by an older version of Galactus that was incapable of producing the same metadata.
However, without an embeddable type detection library, I think this is pretty much a non-starter.
I ❤️ the idea that the extra type information could be available to the smudge filter even if it isn't embedded in the metadata blob. Obviously there will be a secondary conversation with a large asset server so that gives the opportunity to introduce whatever additional logic is needed to cover some of these more complex use cases.
Additionally, another approach to the use case I mentioned would be to only set up the smudge filters for the asset extensions and/or paths that you need to have expanded. In the case I mentioned, it would probably be easy for a user to only smudge the large assets they need for texturing in the game based on path or file extension. That is probably a better approach anyhow, because it is more likely that the directory name would be the indicator of desired behavior as opposed to the file extension (at least for any serious game development workflow).
spraints commentedon Oct 2, 2013
The SVN bridge uses size and md5. That said, I really like the simplicity of just storing the sha1 of the raw asset. Having md5 and/or size available from the asset server works, or slumlord could calculate and store that data itself. So I'm 👍 on storing the sha in the repo.
technoweenie commentedon Oct 2, 2013
I thought about this on the drive to and from lunch, and really like @peff's proposal. Store just the SHA in Git, with meta data on the server.
@spraints: I think we can calculate the MD5 on the server. It should be much easier for you to get this meta data through an API instead of reading in the file contents to calculate it yourself. Course, maybe with the way the protocol works, it doesn't even matter? Let me know if it doesn't save you any time.
@arrbee: I'm thinking about storing as much meta data as I can on the server. Hell, I might store a row for every reference.
I want the git-media setup to be as easy as possible. Maybe it starts up with a default configuration that's easily configurable through .gitattributes. I'm not too concerned with this until I have a working prototype though.
spraints commentedon Oct 2, 2013
There are a couple of places where slumlord uses the MD5 but doesn't need the full blob content. So yeah, if it's easy to do on the server, it would help.
technoweenie commentedon Oct 7, 2013
I've now cut the large assets meta data to just a SHA, with a fake shebang header for identification.
Now the entire file that gets stored in Git looks like:
Here's the ruby parse code for it.
peff commentedon Oct 9, 2013
Hmm. I'm torn on including the fake shebang and warning. On the one hand, it provides a token that both humans and computers may later use to figure out what the hell the content means. But on the other, it is a problem if we ever want to change it, as it affects the git-visible sha1.
aroben commentedon Oct 9, 2013
Maybe something super simple like this would be enough?
technoweenie commentedon Oct 9, 2013
Me too. It's a problem if our git media tool's output differs from other implementations. Ideally two tools would generate the exact same clean blob.
I really like how discoverable it is. But realistically, confused people would probably ask their team about it. Or, they'd throw their laptop out the window and go outside (nothing a fake shebang and warning content can truly solve).
Now if we just use a SHA, there is a chance that anything matching a 40 character hex code could be mistaken for a large asset. Not sure that's worth worrying about.
For context, this is the current warning:
schacon/git-media only wrote the sha, and github/assman writes a similar warning.
aroben commentedon Oct 9, 2013
FYI both those sentences are run-ons. Probably not something we want to encode in git SHAs forever.
peff commentedon Oct 9, 2013
We should only be running git-media if the path is pointed to by
.gitattributes, though. So the chance of false positives is not that high. I do like the idea of having some token to make it more robust (and possibly point the user in the right direction), but it's balanced against being stuck with the content forever.arrbee commentedon Oct 9, 2013
I think the idea of having a recognizable token beyond just the SHA seems like a good idea. It will make it easier to diagnose when a user has cloned a repository with media but not set up media support. It does seem like a good idea to keep it relatively minimal. What if we just leave off the warning:
That seems very "detectable" and will point a savvy user towards git media support.
The only other thing I could imagine wanting is some sort of explicit version numbering so that if we do have to make a breaking change down the line, a smart tool could detect it. I know that that would cause bad things to happen by changing all the SHAs in the repo, but it seems that maybe we should allow for that to happen during the pre-release period.
technoweenie commentedon Oct 9, 2013
@arrbee: Back to the "multiple tools" thing. I really want this to be an open spec, so the chances that "git media" is the only implementation is basically zero. But then, it is a fake shebang. So who cares, right?
I like the "media:" prefix idea too.
@aroben: Doh. Hopefully I can save face by pointing out I mostly copied those from somewhere? No? Shit.
@peff: Keep in mind we'll be "smudging" these assets on GitHub.com too. We'd have to parse the
.gitattributesto decide what files to display from the large assets cloud. Course I guess that's my problem and not yours :) I was just going to punt on it completely and assume anything matching whatever format we come up with is a possible large asset.I think I'm coming around to @peff's POV here. I see a recurring pattern here :)
peff commentedon Oct 9, 2013
Even though it's a fake shebang, I think it's unnecessarily confusing when another non-git-media implementation has to write something that looks like a fake shebang. I'd much rather something like
# git media, or is there another word that is even more implementation agnostic (likeexternalor something)?While I do like the look of
media: 1234abcd..., I do think it's worth thinking about extensibility. It's not something we ever want to have to change, but in the worst case, it would be nice to do so in a way that old versions of the software can treat sensibly. I suppose you can change it tomedia2if you ever have to break compatibility, but somehow the#-lines seem nicer syntactically to me.Regarding
gitattributes, I had assumed you would be using them to undo any smudges on the server. In some cases where you are fetching the object anyway, you could see the media-header and know to fetch the asset. But there may also be cases where you want to know which objects have media assets, but without opening each individual blob. One complication, though, is that you sometimes get a reference to a blob without the surrounding context. In that case, we have no way of looking up the.gitattribute, as it is based on the path within the tree at which the blob is found.So in that sense,
gitattributesare really quite horrible for this, because they are a function of the path, whereas the assetization (if that's not a word, I'm inventing it right now) of the content is a function of the blob. So we probably are better off to have some token in the blob to help us do the right thing in those ambiguous cases, even though we ultimately want to handle.gitattributes, too, since that is how clients will hook into git.Yuck. Doing this underneath the git layer would really be much cleaner, but is a bit more complicated in the implementation. I think we can use this as a stepping stone and a proving ground for the idea, and then think about later doing something that's more tightly integrated with git.
technoweenie commentedon Oct 9, 2013
Another place we can't solely rely on
gitattributes: Removing an extension or path fromgitattributeswon't magically rewrite the old content back to the git odb.I don't think
externalis descriptive enough. Maybe it doesn't matter though, the blob itself shouldn't care where it's stored. Just that it's not in the git odb.technoweenie commentedon Oct 14, 2013
Okay I'm going with:
Basically, everything @peff says :)
All we care about is the content. The only thing needed in the git odb is an identifier. SHA works well enough for that. The 'external' comment is just a hint that this object is stored somewhere else. It's up to the client or git config to specify that. This keeps the git blobs future-proof against major git-media changes or alternate implementations.
Thanks again for the comments, everyone.
Merge pull request #1 from github/rename-again
Merge pull request #1 from thpang67/thpang67-patch-1
t/t-batch-*retries-ratelimit.sh: test retry counts
t: check batch API retries after 429s when cloning