Skip to content

locking: reintroduce Committer field#1863

Merged
ttaylorr merged 2 commits intomasterfrom
locking-committer-field
Jan 13, 2017
Merged

locking: reintroduce Committer field#1863
ttaylorr merged 2 commits intomasterfrom
locking-committer-field

Conversation

@ttaylorr
Copy link
Contributor

@ttaylorr ttaylorr commented Jan 13, 2017

This pull-request reintroduces the Committer field on the *locking.Lock type.

This was the original interface of that type, but was removed in #1732 in favor of Name and Email top-level fields on the Lock type. Instead, let's bring back the original API which:

  • has parity with how the data is sent over the network, and...
  • is more direct in it's meaning. A lock has a committer, not a name and email.

This pull-request also comes with some additional benefits:

  1. Fix a bug where the gitserver was unable to find the fields to de-serialize the committer's name and email, thus making all locks have "" empty-string owners.
  2. Implement fmt.Stringer on the Committer type, which yields the expected format: First Last <email@example.com>.

/cc @git-lfs/core

@ttaylorr ttaylorr added this to the v2.0.0 milestone Jan 13, 2017
@ttaylorr ttaylorr self-assigned this Jan 13, 2017
Copy link
Contributor

@technoweenie technoweenie left a comment

Choose a reason for hiding this comment

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

👍, just 1 thing...

func newCommitter(name, email string) committer {
return committer{Name: name, Email: email}
func NewCommitter(name, email string) Committer {
return Committer{Name: name, Email: email}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be returning a *Committer, since that's the receiver for String() below? Or should the func change the receiver to the struct value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. The constructor function returns a raw-value Committer, since that's how it's embedded in the Lock type. Lock prefers a Committer over a *Committer, since the extra data needed to store the pointer of an immutable value is unnecessary.

However, there's no danger of mutable behavior happening in the (*Committer) String() string method, so copying the value is unnecessary. Go will automatically take the address to call methods defined on the pointer type, i.e. in a type defined like:

type T struct {}

func (t *T) Foo() {}

calling

t := T{}

t.Foo()

is equivalent to calling:

t := T{}

(&t).Foo()

@ttaylorr ttaylorr merged commit 3572931 into master Jan 13, 2017
@ttaylorr ttaylorr deleted the locking-committer-field branch January 13, 2017 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants