Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

annex: web uploads #25

Open
kousu opened this issue Nov 30, 2022 · 3 comments
Open

annex: web uploads #25

kousu opened this issue Nov 30, 2022 · 3 comments

Comments

@kousu
Copy link
Member

kousu commented Nov 30, 2022

I'm not unclear if Gitea supports uploading from the web into Git LFS. If it does, then we should tweak that UI to make git-annex an option too. Otherwise the "Upload a File" menu might mislead people so that they upload files to .git/objects instead of .git/annex/objects, which isn't the end of the world if it happens once but could be a pain in general.

@kousu
Copy link
Member Author

kousu commented Nov 30, 2022

I did a quick experiment: it seems that if you have git lfs trackd a file extension (i.e. there's a line like *.dcm filter=lfs diff=lfs merge=lfs -text in .gitattributes)

Screenshot 2022-11-29 at 20-26-48 lfs-test

then uploading a matching file

Screenshot_20221129_202851

will cause it to get stored in LFS:

Screenshot 2022-11-29 at 20-29-25 lfs-test

that's better than the UI I would have thought of! But I don't think my implementation in #1 behaves like this; so patch that and get it working.

@kousu kousu changed the title Web annex uploads annex: web uploads Nov 30, 2022
@kousu
Copy link
Member Author

kousu commented Nov 30, 2022

Tracing:

Uploaded files get POSTed to /upload-file, and put in a data/tmp/

Screenshot_20221129_215429

the server sends back a pointer to the temp file (it uses UUIDs)

Screenshot_20221129_215524

the commit goes to POST /_upload/$BRANCH with the file pointers attached

Screenshot_20221129_215533

that ends up calling into this function

https://github.com/neuropoly/gitea/blob/fa43bce541507c8a702723f84764a48db9278506/services/repository/files/upload.go#L52-L159

which goes and digs out the tmp files and has also makes a temporary full working-tree copy of the repo; because it has to, it can't git commit otherwise.

It then calls git check-attr --cached filter -- $filename, which is how it ends up reading .gitattributes:

https://github.com/neuropoly/gitea/blob/fa43bce541507c8a702723f84764a48db9278506/services/repository/files/upload.go#L97-L100

https://github.com/neuropoly/gitea/blob/fa43bce541507c8a702723f84764a48db9278506/modules/git/repo_attribute.go#L46

(git-check-attr produces something like

p115628@joplin:~/src/neurogitea/test/lfs-test$ git check-attr --cached filter -- "lol.nii.gz"
lol.nii.gz: filter: lfs

)

and then that's used to detect if it needs to run this special LFS case:

https://github.com/neuropoly/gitea/blob/fa43bce541507c8a702723f84764a48db9278506/services/repository/files/upload.go#L169-L181

@kousu
Copy link
Member Author

kousu commented Nov 30, 2022

So I think the equivalent annex code would be something like:

if setting.LFS.StartServer && filename2attribute2info[info.upload.Name] != nil && filename2attribute2info[info.upload.Name]["filter"] == "annex" { 
   // in the temporary repo
   system("git config annex.private true")
   system("git annex init")
   system("git annex dead here")
   copy info.upload to repo directory
   system("git add .")
   system("git annex copy --to origin")
   t.CommitTree(opts.LastCommitID, author, committer, treeHash, opts.Message, opts.Signoff)
   t.CommitTree("git-annex", author, committer, treeHash, opts.Message, opts.Signoff)
}

but don't use system() if you can avoid it. Maybe we can call git annex pre-commit or git annex smudge directly to avoid having to run git annex init?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant