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 lock api #2938

Merged
merged 30 commits into from
Nov 28, 2017
Merged

Git LFS lock api #2938

merged 30 commits into from
Nov 28, 2017

Conversation

sapk
Copy link
Member

@sapk sapk commented Nov 20, 2017

Resolve #2725

@lunny lunny added the type/enhancement An improvement of existing functionality label Nov 20, 2017
@lunny lunny added this to the 1.x.x milestone Nov 20, 2017
@lafriks lafriks added the pr/wip This PR is not ready for review label Nov 20, 2017
@sapk sapk force-pushed the git-lfs-lock-api branch 2 times, most recently from 9458fea to 744a07e Compare November 21, 2017 22:05
@codecov-io
Copy link

codecov-io commented Nov 22, 2017

Codecov Report

Merging #2938 into master will increase coverage by 0.3%.
The diff coverage is 56.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #2938     +/-   ##
=========================================
+ Coverage   32.73%   33.03%   +0.3%     
=========================================
  Files         267      269      +2     
  Lines       39189    39483    +294     
=========================================
+ Hits        12828    13044    +216     
- Misses      24539    24593     +54     
- Partials     1822     1846     +24
Impacted Files Coverage Δ
routers/routes/routes.go 86.99% <100%> (+0.64%) ⬆️
models/models.go 49.33% <100%> (+0.22%) ⬆️
modules/lfs/locks.go 47.59% <47.59%> (ø)
models/lfs_lock.go 69.76% <69.76%> (ø)
models/error.go 30.98% <73.33%> (+2.04%) ⬆️
models/repo_indexer.go 49% <0%> (-2.98%) ⬇️
modules/indexer/repo.go 60.86% <0%> (-2.61%) ⬇️
models/repo.go 38% <0%> (+0.18%) ⬆️
... 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 6ad4990...a987dda. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 22, 2017
@sapk sapk changed the title [WIP] Git LFS lock api Git LFS lock api Nov 22, 2017
@sapk
Copy link
Member Author

sapk commented Nov 22, 2017

It is ready for review.

@lunny lunny removed the pr/wip This PR is not ready for review label Nov 22, 2017
@lunny lunny modified the milestones: 1.x.x, 1.4.0 Nov 22, 2017
@@ -0,0 +1,173 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

... 2017 The Gitea ... ?

package models

import (
api "code.gitea.io/sdk/gitea"
Copy link
Member

Choose a reason for hiding this comment

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

wrong order

"time"
)

// LFSLock represents a git lfs lfock of repository.
Copy link
Member

Choose a reason for hiding this comment

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

lfock -> lock

Owner *User `xorm:"-"`
Path string
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"INDEX"`
Copy link
Member

Choose a reason for hiding this comment

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

Use created is enough, then line 28 -> 30 and line 36 could be removed.

Copy link
Member Author

@sapk sapk Nov 23, 2017

Choose a reason for hiding this comment

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

I base myself on other models like :

s.CreatedUnix = time.Now().Unix()

After review more of those, I might be needed adding xorm:"INDEX created" on created like :
CreatedUnix int64 `xorm:"INDEX created"`

After adding that, does I need ?
t.Created = time.Unix(t.CreatedUnix, 0).Local()

I will totally follow you on xorm since you will know more about it and maybe (in another PR) we should clean other models with such pattern.


// IsLFSLockExist returns true if lock with given path already exists.
func IsLFSLockExist(repoID int64, path string) (bool, error) {
return x.Get(&LFSLock{RepoID: repoID, Path: path}) //TODO Define if path should needed to be lower for windows compat ?
Copy link
Member

Choose a reason for hiding this comment

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

maybe store a lower column?

if err != nil {
return nil, err
} else if isExist {
l, err := GetLFSLock(lock.RepoID, lock.Path)
Copy link
Member

Choose a reason for hiding this comment

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

IsLFSLockExist has been invoked on GetLFSLock.

Copy link
Member Author

Choose a reason for hiding this comment

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

@lunny To be sure, I would better use directly GetLFSLock and check if !IsErrLFSLockNotExist(err) ?

// GetLFSLockByRepoID returns a list of locks of repository.
func GetLFSLockByRepoID(repoID int64) (locks []*LFSLock, err error) {
err = x.Where("repo_id = ?", repoID).Find(&locks)
return locks, err
Copy link
Member

Choose a reason for hiding this comment

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

return

RepoID int64 `xorm:"INDEX"`
Owner *User `xorm:"-"`
OwnerID int64 `xorm:"INDEX"`
Path string `xorm:"TEXT"`
Copy link
Member

Choose a reason for hiding this comment

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

And maybe Path should be unique with RepoID ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes and that make me think that I should also use filepath.Clean before adding a entry.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done + add not null constraint

Copy link
Member Author

Choose a reason for hiding this comment

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

Revert back the uniqueness since mysql need a fixed size to index uniquess on field and path is a TEXT field. Uniqueness is preserve by code.

Copy link
Member

Choose a reason for hiding this comment

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

Path could be xorm:"varchar(1024)".

Copy link
Member Author

Choose a reason for hiding this comment

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

after looking at it linux limits path length to 4096

@lunny
Copy link
Member

lunny commented Nov 28, 2017

LGTM

@tboerger tboerger 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 Nov 28, 2017
@lafriks
Copy link
Member

lafriks commented Nov 28, 2017

@sapk please resolve vendor conflict

@sapk
Copy link
Member Author

sapk commented Nov 28, 2017

@lafriks done

@lafriks
Copy link
Member

lafriks commented Nov 28, 2017

LGTM

@tboerger tboerger 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 Nov 28, 2017
@lafriks lafriks merged commit d99f4ab into go-gitea:master Nov 28, 2017
@sapk sapk mentioned this pull request Nov 28, 2017
@sapk sapk deleted the git-lfs-lock-api branch December 9, 2017 21:47
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 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/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git LFS File Locking API
5 participants