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

Gitea server should not checkout on upload #5600

Closed
zeripath opened this issue Dec 27, 2018 · 5 comments · Fixed by #5702
Closed

Gitea server should not checkout on upload #5600

zeripath opened this issue Dec 27, 2018 · 5 comments · Fixed by #5702
Labels
type/enhancement An improvement of existing functionality

Comments

@zeripath
Copy link
Contributor

  • Gitea version (or commit ref): master

Description

When performing an upload, the UpdateRepoFile function in models/repo_editor.go actually checkout's a copy of the target repository, moves the uploaded files to the correct places, commits and pushes back to the repository.git.

This is very wasteful (and I suspect possibly dangerous, especially on Windows but I don't know). Clearer it would be better to just push (or at least commit) directly to the repository.git

I know of two approaches that are likely to be better:

The most complete appears to be the approach taken in bozaro/git-as-svn which is a Java bridge presenting git repos as SVN. This doesn't checkout a copy of the repo but rather appears to create objects and trees directly in the repository.git by having a deep understanding of the git repository layout thus simulating a commit. It even knows how to manage LFS. I don't quite understand what it's doing but it may be possible to use our current go git libraries to do something similar directly.

A less do it your own way appears to be to use git fast-import. This is a well documented git-core tool for importing data from other software. You simply use the protocol defined in the help file to commit the whole modified files, git will then do the diffs and store the objects. Unfortunately this doesn't appear run any hooks, so it appears that if the object should be in LFS that needs dealing with first. Similarly the post-receive etc hooks would need to be dealt with first/afterwards - although this is likely to be less difficult to deal with.

I will do some more basic testing with git fast-import which I think should be quite easy to pull in. I might also contact the git-as-svn maintainer to see if they can enlighten me more on how their solution works.

@typeless
Copy link
Contributor

A solution is to use shared-clone and sparse-checkout, which is similar to #4921 does.

@zeripath
Copy link
Contributor Author

We checkout elsewhere too? I don't think we should need to do any checking out - The data is all in the repository, just indirectly addressed. I would be very surprised if GitHub were checking out to do merges.

@typeless
Copy link
Contributor

This article https://githubengineering.com/move-fast/ has good insight.

The problem with manipulating the .git too-low-level-ish is that it is much tougher to guarantee the correctness without comprehensive testing and would risk the integrity of the repositories. The best option would be we have that implemented in the upstream git tool and to enjoy their free test suite.
That's a reason why we still do checkouts (or at least partially) besides being quick-and-dirty.

@zeripath
Copy link
Contributor Author

Yeah agreed - I too would be extremely cautious about reimplementing git - however I suspect that we can use some of the plumbing a bit more cleverly to get the best of both worlds. We're already using a go reimplementation of git so it might be that that can help too.

For example the git fast-import plumbing seems like it would be very easy to use - if we are happy we understand what it does.

@lunny lunny added the type/enhancement An improvement of existing functionality label Dec 27, 2018
@zeripath
Copy link
Contributor Author

zeripath commented Jan 2, 2019

OK, fast-import is not available on our current docker. However, you can achieve the same things using the plumbing commands available in git. My comments in #601 (#601 (comment)) present an approach that uses bare-repos and index files.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
3 participants