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

Fix #732: Add LFS objects to base repository on merging #7082

Merged
merged 19 commits into from
Jun 22, 2019

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented May 29, 2019

This PR Fixes #732.

It first disables the standard git-lfs filters including the missing process, (filter.lfs.process, filter.lfs.clean, filter.lfs.smudge, filter.lfs.required.)

Then just before merging it walks the merging history ensuring that all files in the history to be merged, that are <1k, and match LFS pointer files - actually representing lfs objects in the content store are then added to the base repositories lfs objects.

This PR attempts to Fix #732 (Yes this bug is that old) whereby trying to merge a pull request containing LFS objects fails. This is substantially better than simply ignoring the missed filter.lfs.process which is an alternative fix as that technique likely leads to the loss of lfs objects on forked repo deletion.

The current implementation just routes the requests to the internal url for the gitea server - however this may not work if Gitea is running over a unix pipe and therefore likely requires more thought.

It does however provide a fix.

cmd/serv.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 29, 2019
@codecov-io
Copy link

codecov-io commented May 29, 2019

Codecov Report

Merging #7082 into master will increase coverage by 0.19%.
The diff coverage is 51.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7082      +/-   ##
==========================================
+ Coverage   41.53%   41.73%   +0.19%     
==========================================
  Files         449      451       +2     
  Lines       61344    61531     +187     
==========================================
+ Hits        25478    25678     +200     
+ Misses      32511    32471      -40     
- Partials     3355     3382      +27
Impacted Files Coverage Δ
routers/api/v1/repo/pull.go 37.39% <0%> (ø) ⬆️
routers/repo/pull.go 31.05% <0%> (ø) ⬆️
modules/pull/merge.go 39.35% <39.35%> (ø)
models/pull.go 50.47% <50%> (+1.74%) ⬆️
modules/pull/lfs.go 71.16% <71.16%> (ø)
models/repo.go 48.63% <0%> (+0.27%) ⬆️
models/access.go 68.15% <0%> (+1.27%) ⬆️
models/notification.go 74.19% <0%> (+2.15%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e8a616...f396505. Read the comment docs.

@lafriks lafriks added this to the 1.9.0 milestone May 30, 2019
@zeripath zeripath changed the title Route LFS calls through to gitea on merging Fix #732: Add LFS objects to base repository on merging May 31, 2019
cmd/serv.go Outdated Show resolved Hide resolved
modules/merge/merge.go Outdated Show resolved Hide resolved
zeripath added 3 commits May 31, 2019 16:18
This switches from relying on having git-lfs installed on the server,
(and in fact .gitattributes being correctly installed.) Instead on merge
we walk the merge history and ensure that all lfs objects pointed to in
the history are added to the base repository.
@zeripath zeripath force-pushed the route-lfs-internally-fix-#732 branch from 4ae0753 to 02a0c26 Compare May 31, 2019 15:19
modules/merge/merge.go Outdated Show resolved Hide resolved
@zeripath zeripath mentioned this pull request Jun 1, 2019
7 tasks
@zeripath
Copy link
Contributor Author

zeripath commented Jun 1, 2019

I've expanded git_test to include showing that on merging a fork the lfs objects remain available.

@zeripath
Copy link
Contributor Author

zeripath commented Jun 1, 2019

I've also expanded the git_test to delete the repository before checking if the lfs objects are available in the merged repository.

modules/merge/lfs.go Outdated Show resolved Hide resolved
@@ -0,0 +1,226 @@
// Copyright 2019 The Gitea Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about use modules/pull but not modules/merge so that we could move more pull related codes to this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we could just rename this when that's done but if you prefer I can do that now.

A few of the pipelines used in the lfs code are reusable, e.g. in #7199 - so may be some of those should be moved to git (or migrated to go-git code over time.)

zeripath added 2 commits June 15, 2019 17:48
We need to read the file plus the terminal newline that cat-file sends -
hence 1024 + 1.
@codecov-io
Copy link

codecov-io commented Jun 17, 2019

Codecov Report

Merging #7082 into master will increase coverage by 0.2%.
The diff coverage is 51.68%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #7082     +/-   ##
=========================================
+ Coverage   40.98%   41.18%   +0.2%     
=========================================
  Files         462      464      +2     
  Lines       62584    62771    +187     
=========================================
+ Hits        25648    25852    +204     
+ Misses      33574    33530     -44     
- Partials     3362     3389     +27
Impacted Files Coverage Δ
routers/api/v1/repo/pull.go 37.39% <0%> (ø) ⬆️
routers/repo/pull.go 31.05% <0%> (ø) ⬆️
modules/pull/merge.go 39.35% <39.35%> (ø)
models/pull.go 50.47% <50%> (+1.74%) ⬆️
modules/pull/lfs.go 71.16% <71.16%> (ø)
models/repo.go 48.63% <0%> (+0.27%) ⬆️
routers/repo/view.go 43.25% <0%> (+1.01%) ⬆️
models/access.go 68.15% <0%> (+1.27%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d145955...47f4d39. Read the comment docs.

Copy link
Member

@sapk sapk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't tested this but tests seems to cover the cases. Trusted LGTM.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 21, 2019
}

func doRevListObjects(revListWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath, headSHA, baseSHA string, errChan chan<- error) {
defer wg.Done()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

defer func() {
  wg.Done()
  revListWriter.Close()
}()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm AFAIU defers run in spite of panics. If wg.Done() panics then revListWriter will not close if we do this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not that that particularly matters as the panic will be unrecovered in the goroutine and thus bring down gitea)

@lunny
Copy link
Member

lunny commented Jun 21, 2019

Otherwise LGTM

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 21, 2019
@zeripath zeripath merged commit baefea3 into go-gitea:master Jun 22, 2019
@zeripath zeripath deleted the route-lfs-internally-fix-#732 branch June 22, 2019 17:35
jeffliu27 pushed a commit to jeffliu27/gitea that referenced this pull request Jul 18, 2019
…itea#7082)

On merge we walk the merge history and ensure that all lfs objects pointed to in
the history are added to the base repository. This switches from relying on having git-lfs installed on the server, (and in fact .gitattributes being correctly installed.)
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LFS: Error 500 when merging pull request
6 participants