locking: rename 'committer' to 'owner'

This commit is contained in:
risk danger olson 2017-02-03 10:48:31 -07:00
parent 63dd3634a1
commit f0d9be4684
9 changed files with 48 additions and 62 deletions

@ -32,7 +32,7 @@ func locksCommand(cmd *cobra.Command, args []string) {
} }
for _, lock := range locks { for _, lock := range locks {
Print("%s\t%s", lock.Path, lock.Committer) Print("%s\t%s", lock.Path, lock.Owner)
lockCount++ lockCount++
} }

@ -178,7 +178,7 @@ func (c *uploadContext) Await() {
Print("Unable to push %d locked file(s):", ul) Print("Unable to push %d locked file(s):", ul)
for _, unowned := range c.unownedLocks { for _, unowned := range c.unownedLocks {
Print("* %s - %s", unowned.Path, unowned.Committer) Print("* %s - %s", unowned.Path, unowned.Owner)
} }
} else if len(c.ownedLocks) > 0 { } else if len(c.ownedLocks) > 0 {
Print("Consider unlocking your own locked file(s): (`git lfs unlock <path>`)") Print("Consider unlocking your own locked file(s): (`git lfs unlock <path>`)")

@ -53,9 +53,8 @@ as long as it's returned a string.
* `path` - String path name of the locked file. This should be relative to the * `path` - String path name of the locked file. This should be relative to the
root of the repository working directory. root of the repository working directory.
* `locked_at` - The string ISO 8601 formatted timestamp the lock was created. * `locked_at` - The string ISO 8601 formatted timestamp the lock was created.
* `committer` - The optional name/email of the user that created the Lock. This * `owner` - The name of the user that created the Lock. This should be set from
could be different from the `committer` values in the request if the lock the user credentials posted when creating the lock.
service already knows the committer's identity based on the API credentials.
```js ```js
// HTTP/1.1 201 Created // HTTP/1.1 201 Created
@ -65,9 +64,8 @@ service already knows the committer's identity based on the API credentials.
"id": "some-uuid", "id": "some-uuid",
"path": "/path/to/file", "path": "/path/to/file",
"locked_at": "2016-05-17T15:49:06+00:00", "locked_at": "2016-05-17T15:49:06+00:00",
"committer": { "owner": {
"name": "Jane Doe", "name": "Jane Doe",
"email": "janedoe@email.com"
} }
} }
} }
@ -177,7 +175,7 @@ Note: If the server has no locks, it must return an empty `locks` array.
"id": "some-uuid", "id": "some-uuid",
"path": "/path/to/file", "path": "/path/to/file",
"locked_at": "2016-05-17T15:49:06+00:00", "locked_at": "2016-05-17T15:49:06+00:00",
"committer": { "owner": {
"name": "Jane Doe" "name": "Jane Doe"
} }
} }
@ -285,7 +283,7 @@ Note: If the server has no locks, it must return an empty array in the `ours` or
"id": "some-uuid", "id": "some-uuid",
"path": "/path/to/file", "path": "/path/to/file",
"locked_at": "2016-05-17T15:49:06+00:00", "locked_at": "2016-05-17T15:49:06+00:00",
"committer": { "owner": {
"name": "Jane Doe" "name": "Jane Doe"
} }
} }
@ -390,7 +388,7 @@ response section to see what Lock properties are possible.
"id": "some-uuid", "id": "some-uuid",
"path": "/path/to/file", "path": "/path/to/file",
"locked_at": "2016-05-17T15:49:06+00:00", "locked_at": "2016-05-17T15:49:06+00:00",
"committer": { "owner": {
"name": "Jane Doe" "name": "Jane Doe"
} }
} }

@ -243,22 +243,18 @@ func (c *lockClient) SearchVerifiable(remote string, vreq *lockVerifiableRequest
return locks, res, err return locks, res, err
} }
// Committer represents a "First Last <email@domain.com>" pair. // User represents the owner of a lock.
type Committer struct { type User struct {
// Name is the name of the individual who would like to obtain the // Name is the name of the individual who would like to obtain the
// lock, for instance: "Rick Olson". // lock, for instance: "Rick Sanchez".
Name string `json:"name"` Name string `json:"name"`
// Email is the email assopsicated with the individual who would
// like to obtain the lock, for instance: "rick@github.com".
Email string `json:"email"`
} }
func NewCommitter(name, email string) *Committer { func NewUser(name string) *User {
return &Committer{Name: name, Email: email} return &User{Name: name}
} }
// String implements the fmt.Stringer interface by returning a string // String implements the fmt.Stringer interface.
// representation of the Committer in the format "First Last <email>". func (u *User) String() string {
func (c *Committer) String() string { return u.Name
return fmt.Sprintf("%s <%s>", c.Name, c.Email)
} }

@ -169,9 +169,8 @@ type Lock struct {
// Path is an absolute path to the file that is locked as a part of this // Path is an absolute path to the file that is locked as a part of this
// lock. // lock.
Path string `json:"path"` Path string `json:"path"`
// Committer is the identity of the person who holds the ownership of // Owner is the identity of the user that created this lock.
// this lock. Owner *User `json:"owner"`
Committer *Committer `json:"committer"`
// LockedAt is the time at which this lock was acquired. // LockedAt is the time at which this lock was acquired.
LockedAt time.Time `json:"locked_at"` LockedAt time.Time `json:"locked_at"`
} }
@ -325,11 +324,9 @@ func (c *Client) lockIdFromPath(path string) (string, error) {
} }
} }
// Fetch locked files for the current committer and cache them locally // Fetch locked files for the current user and cache them locally
// This can be used to sync up locked files when moving machines // This can be used to sync up locked files when moving machines
func (c *Client) refreshLockCache() error { func (c *Client) refreshLockCache() error {
// TODO: filters don't seem to currently define how to search for a
// committer's email. Is it "committer.email"? For now, just iterate
ourLocks, _, err := c.VerifiableLocks(0) ourLocks, _, err := c.VerifiableLocks(0)
if err != nil { if err != nil {
return err return err
@ -345,9 +342,8 @@ func (c *Client) refreshLockCache() error {
} }
// IsFileLockedByCurrentCommitter returns whether a file is locked by the // IsFileLockedByCurrentCommitter returns whether a file is locked by the
// current committer, as cached locally // current user, as cached locally
func (c *Client) IsFileLockedByCurrentCommitter(path string) bool { func (c *Client) IsFileLockedByCurrentCommitter(path string) bool {
filter := map[string]string{"path": path} filter := map[string]string{"path": path}
locks, err := c.searchCachedLocks(filter, 1) locks, err := c.searchCachedLocks(filter, 1)
if err != nil { if err != nil {

@ -26,17 +26,19 @@ func TestRefreshCache(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method) assert.Equal(t, "POST", r.Method)
assert.Equal(t, "/api/locks", r.URL.Path) assert.Equal(t, "/api/locks/verify", r.URL.Path)
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(lockList{ err = json.NewEncoder(w).Encode(lockVerifiableList{
Locks: []Lock{ Theirs: []Lock{
Lock{Id: "99", Path: "folder/test3.dat", Committer: &Committer{Name: "Alice", Email: "alice@wonderland.com"}}, Lock{Id: "99", Path: "folder/test3.dat", Owner: &User{Name: "Alice"}},
Lock{Id: "101", Path: "folder/test1.dat", Committer: &Committer{Name: "Fred", Email: "fred@bloggs.com"}}, Lock{Id: "199", Path: "other/test1.dat", Owner: &User{Name: "Charles"}},
Lock{Id: "102", Path: "folder/test2.dat", Committer: &Committer{Name: "Fred", Email: "fred@bloggs.com"}}, },
Lock{Id: "103", Path: "root.dat", Committer: &Committer{Name: "Fred", Email: "fred@bloggs.com"}}, Ours: []Lock{
Lock{Id: "199", Path: "other/test1.dat", Committer: &Committer{Name: "Charles", Email: "charles@incharge.com"}}, Lock{Id: "101", Path: "folder/test1.dat", Owner: &User{Name: "Fred"}},
Lock{Id: "102", Path: "folder/test2.dat", Owner: &User{Name: "Fred"}},
Lock{Id: "103", Path: "root.dat", Owner: &User{Name: "Fred"}},
}, },
}) })
assert.Nil(t, err) assert.Nil(t, err)
@ -74,9 +76,9 @@ func TestRefreshCache(t *testing.T) {
// Sort locks for stable comparison // Sort locks for stable comparison
sort.Sort(LocksById(locks)) sort.Sort(LocksById(locks))
assert.Equal(t, []Lock{ assert.Equal(t, []Lock{
Lock{Path: "folder/test1.dat", Id: "101", Committer: &Committer{Name: "Fred", Email: "fred@bloggs.com"}, LockedAt: zeroTime}, Lock{Path: "folder/test1.dat", Id: "101", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
Lock{Path: "folder/test2.dat", Id: "102", Committer: &Committer{Name: "Fred", Email: "fred@bloggs.com"}, LockedAt: zeroTime}, Lock{Path: "folder/test2.dat", Id: "102", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
Lock{Path: "root.dat", Id: "103", Committer: &Committer{Name: "Fred", Email: "fred@bloggs.com"}, LockedAt: zeroTime}, Lock{Path: "root.dat", Id: "103", Owner: &User{Name: "Fred"}, LockedAt: zeroTime},
}, locks) }, locks)
} }

@ -757,21 +757,19 @@ func redirect307Handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(307) w.WriteHeader(307)
} }
type Committer struct { type User struct {
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"`
} }
type Lock struct { type Lock struct {
Id string `json:"id"` Id string `json:"id"`
Path string `json:"path"` Path string `json:"path"`
Committer Committer `json:"committer"` Owner User `json:"owner"`
LockedAt time.Time `json:"locked_at"` LockedAt time.Time `json:"locked_at"`
} }
type LockRequest struct { type LockRequest struct {
Path string `json:"path"` Path string `json:"path"`
Committer Committer `json:"committer"`
} }
type LockResponse struct { type LockResponse struct {
@ -1031,7 +1029,7 @@ func locksHandler(w http.ResponseWriter, r *http.Request, repo string) {
lock := &Lock{ lock := &Lock{
Id: fmt.Sprintf("%x", id[:]), Id: fmt.Sprintf("%x", id[:]),
Path: lockRequest.Path, Path: lockRequest.Path,
Committer: lockRequest.Committer, Owner: User{Name: "Git LFS Tests"},
LockedAt: time.Now(), LockedAt: time.Now(),
} }

@ -17,7 +17,7 @@ begin_test "list a single lock"
GITLFSLOCKSENABLED=1 git lfs locks --path "f.dat" | tee locks.log GITLFSLOCKSENABLED=1 git lfs locks --path "f.dat" | tee locks.log
grep "1 lock(s) matched query" locks.log grep "1 lock(s) matched query" locks.log
grep "f.dat" locks.log grep "f.dat" locks.log
grep "Git LFS Tests <git-lfs@example.com>" locks.log grep "Git LFS Tests" locks.log
) )
end_test end_test
@ -35,7 +35,7 @@ begin_test "list a single lock (--json)"
GITLFSLOCKSENABLED=1 git lfs locks --json --path "f_json.dat" | tee locks.log GITLFSLOCKSENABLED=1 git lfs locks --json --path "f_json.dat" | tee locks.log
grep "\"path\":\"f_json.dat\"" locks.log grep "\"path\":\"f_json.dat\"" locks.log
grep "\"committer\":{\"name\":\"Git LFS Tests\",\"email\":\"git-lfs@example.com\"}" locks.log grep "\"owner\":{\"name\":\"Git LFS Tests\"}" locks.log
) )
end_test end_test

@ -529,10 +529,6 @@ begin_test "pre-push with their lock"
setup_remote_repo "$reponame" setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame" clone_repo "$reponame" "$reponame"
# Use a different Git persona so the locks are owned by a different person
git config --local user.name "Example Locker"
git config --local user.email "locker@example.com"
git lfs track "*.dat" git lfs track "*.dat"
git add .gitattributes git add .gitattributes
git commit -m "initial commit" git commit -m "initial commit"
@ -563,7 +559,7 @@ begin_test "pre-push with their lock"
git push origin master 2>&1 | tee push.log git push origin master 2>&1 | tee push.log
grep "Unable to push 1 locked file(s)" push.log grep "Unable to push 1 locked file(s)" push.log
grep "* locked_theirs.dat - Example Locker <locker@example.com>" push.log grep "* locked_theirs.dat - Git LFS Tests" push.log
popd >/dev/null popd >/dev/null
) )
end_test end_test