Skip to content

api refactor: locking#1824

Merged
technoweenie merged 14 commits intoapi-masterfrom
api/locking
Jan 6, 2017
Merged

api refactor: locking#1824
technoweenie merged 14 commits intoapi-masterfrom
api/locking

Conversation

@technoweenie
Copy link
Contributor

This updates the locking package to use the new lfsapi.Client from the api-master branch. As a result, this removes the dependencies on the api and config packages from locking, while adding lfsapi of course.

@ttaylorr ttaylorr mentioned this pull request Jan 3, 2017
17 tasks
This was referenced Jan 4, 2017
Copy link
Contributor

@ttaylorr ttaylorr left a comment

Choose a reason for hiding this comment

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

Looking good, just a few comments.


const slash = "/"

func joinURL(prefix, suffix string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use path.Join instead? That should work as a drop-in replacement here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does extra stuff we don't need (calling path.Clean()) in our limited uses of (*Client) NewRequest() that we don't need. suffix is always a simple string like "objects/batch" or "locks". Though I suppose anyone can import the package and call it with a weird suffix. Though I'm not sure why anyone would do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't work without parsing the URL:

	Error:		Not equal: "https://example.com/a" (expected)
			        != "https:///example.com/a" (actual)

}

func decodeResponse(res *http.Response, obj interface{}) error {
func IsDecodeTypeError(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

When adding error types to existing packages, I've usually stuck to putting them in the errors package itself, but I think defining them here for a new package is a great call 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think the errors package should know about all lfs errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

{Property: "a", Value: "A"},
},
Cursor: "cursor",
Limit: 5,
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about setting a limit of 1 so we can test paginating here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pagination isn't handled here, it's in locking.Client.

return
}

if strings.Contains(r.URL.Path, "/info/lfs/locks") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this handle unlocking? We should probably remove the two old handlers on L71-72 to make sure that we're hitting the right URL.

Copy link
Contributor

Choose a reason for hiding this comment

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

I used these to make sure all requests were routed correctly: https://github.com/git-lfs/git-lfs/pull/1818/files#diff-a3b6c1ff24bf259401c990b87d408bb6R160.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not going to worry about this since master diverged when you fixed the locking relative path issue.

return &Client{
Remote: remote,
client: &lockClient{Client: lfsClient},
cache: &nilLockCacher{},
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I'm a fan of this pattern in Go. I'd rather sacrifice some if-statements to have a more straightforward set of types than have gain an interface and another implementation. I don't feel strongly, so if you like this pattern, 👍.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer the null object pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To expand on that, things like zero values, interfaces, and typed nils in Go make me think it's designed for the null object pattern. The added locking cacher interface gives us the option to plug in alternate caching types too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me 😄


lockDir := filepath.Join(config.LocalGitStorageDir, "lfs")
err := os.MkdirAll(lockDir, 0755)
func (c *Client) SetupFileCache(path string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about having an option func passed to the constructor instead of this? I would love to avoid having to construct and then call another function before using something. I was thinking:

locking.NewClient(foo, bar, locking.WithFileCache(path))

I think this fits the bill of a good optional argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Option funcs are good if the values are needed in the constructor. Otherwise, setting properties seems to be closer to go conventions. You only have to call SetupFileCache() if you want a cacher.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Contributor

@ttaylorr ttaylorr left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at my comments. This looks good.

@technoweenie
Copy link
Contributor Author

Thanks for the review. A locking.Client pagination test should be added, but not in this API PR (since that pagination code is in the locking client).

@technoweenie technoweenie merged commit 4a771fb into api-master Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants