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

[git lfs] web interface displays lfs metadata instead of real file #7209

Closed
2 of 7 tasks
schmittlauch opened this issue Jun 14, 2019 · 6 comments
Closed
2 of 7 tasks

Comments

@schmittlauch
Copy link
Contributor

  • Gitea version (or commit ref): 1.8.2
  • Git version: 1.12.5
  • Operating system: Linux (openSUSE)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No, reason: cannot even push a git lfs repo:
batch response: Repository or object not found: https://try.gitea.io/schmittlauch/lfs_test.git/info/lfs/objects/batch                                                                        
Check that it exists and that you have proper access to it
  • Not relevant
  • Log gist:

Description

For repositories containing files stored in git lfs buckets, the gitea web interface does not display the actual file but only the intermediate metadata file of git lfs.

Screenshots

Screenshot_20190615_015713

@zeripath
Copy link
Contributor

First of all LFS is not available on try.gitea.io. That's why the push fails there.

@zeripath
Copy link
Contributor

Ok so assuming that your Gitea is actually running as an LFS server. This should not be happening.

Let's look at view.go the rendering of a file is handled:

gitea/routers/repo/view.go

Lines 207 to 216 in 76e8eec

func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
ctx.Data["IsViewFile"] = true
blob := entry.Blob()
dataRc, err := blob.DataAsync()
if err != nil {
ctx.ServerError("DataAsync", err)
return
}
defer dataRc.Close()

Where it opens a blob and then reads some of it in to a buffer checking if it's a text file:

gitea/routers/repo/view.go

Lines 226 to 230 in 76e8eec

buf := make([]byte, 1024)
n, _ := dataRc.Read(buf)
buf = buf[:n]
isTextFile := base.IsTextFile(buf)

If it's a text file and LFS is enabled it will try to see if it matches an LFS file:

gitea/routers/repo/view.go

Lines 234 to 248 in 76e8eec

//Check for LFS meta file
if isTextFile && setting.LFS.StartServer {
meta := lfs.IsPointerFile(&buf)
if meta != nil {
meta, err = ctx.Repo.Repository.GetLFSMetaObjectByOid(meta.Oid)
if err != nil && err != models.ErrLFSObjectNotExist {
ctx.ServerError("GetLFSMetaObject", err)
return
}
}
if meta != nil {
ctx.Data["IsLFSFile"] = true
isLFSFile = true
// OK read the lfs object

And then will switch to use that LFS files contents. So you should never see the LFS pointer once it has matched.

@zeripath
Copy link
Contributor

GetLFSMetaObjectByOid looks like:

gitea/models/lfs.go

Lines 89 to 105 in 76e8eec

// GetLFSMetaObjectByOid selects a LFSMetaObject entry from database by its OID.
// It may return ErrLFSObjectNotExist or a database error. If the error is nil,
// the returned pointer is a valid LFSMetaObject.
func (repo *Repository) GetLFSMetaObjectByOid(oid string) (*LFSMetaObject, error) {
if len(oid) == 0 {
return nil, ErrLFSObjectNotExist
}
m := &LFSMetaObject{Oid: oid, RepositoryID: repo.ID}
has, err := x.Get(m)
if err != nil {
return nil, err
} else if !has {
return nil, ErrLFSObjectNotExist
}
return m, nil
}

@zeripath
Copy link
Contributor

Ok now we have the code context we can try to work out what's going wrong.

Clearly your file above is a text file that appears to be an LFS pointer file.

So that leaves 2 possibilities:

  • You don't have LFS started on your Gitea.
  • The GetLFSMetaObjectByOid fails because the LFS file is not associated with that repository.

So are you sure you've pushed your LFS file to Gitea?

How did you get your LFS file into this repository? Was it through a merge from a fork? There's a corollary issue to #732 whereby if you can merge prs with LFS files, those LFS files will not be associated with the base repository. This will be finally fixed by #7082.

My WIP pr #7199 will add some LFS management features to the repository settings - allowing you to search a repository for missing LFS files.

@schmittlauch
Copy link
Contributor Author

Ok so assuming that your Gitea is actually running as an LFS server. This should not be happening.

I ran into an interesting edge case: First of all, git lfs was not enabled on my gitea instance. Sorry, my bad, i wasn't aware of the necessity of manually enabling it.
I got no error message while pushing though, so I had no real reason to assume thinks not working.
The reason for that is my special setup: I added my gitea repo as a 2nd url to an existing remote (gitlab). git lfs already had pushed the files once for this remote, but only to the storage available under the 1st url. So the lfs files never reached my gitea repo, neither giving gitea the chance to resolve the pointer files nor returning an error message.

Closing this as I'm not sure whether gitea can do anything about this, it's probably more of a git lfs bug/ quirk.

@zeripath
Copy link
Contributor

Yeah unfortunately there's no way for Gitea to divine where you stored your LFS files as far as I understand it. I don't think it's ever sent across with a push.

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants