Skip to content

Typedef git_pkt_type and clarify recv_pkt return type#4514

Merged
ethomson merged 5 commits into
libgit2:masterfrom
tiennou:fix/pkt-type-enum
Apr 16, 2018
Merged

Typedef git_pkt_type and clarify recv_pkt return type#4514
ethomson merged 5 commits into
libgit2:masterfrom
tiennou:fix/pkt-type-enum

Conversation

@tiennou
Copy link
Copy Markdown
Contributor

@tiennou tiennou commented Feb 6, 2018

This is extracted from my WIP shallow/smart-transport branch (a.k.a. shallow clones).

I was very confused by the "error handling" around that function, so hopefully this makes it clearer.

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

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

This is definitly much more readable, so I'm very happy with your change overall. Thanks! Just some comments to make it even more readable, even though your changes already go most of the way

git__free(pkt);

return pkt_type;
return error;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 This is our preferred style and definitly easier to handle than the previous interface

Comment thread src/transports/smart_protocol.c Outdated
}

static int recv_pkt(git_pkt **out, gitno_buffer *buf)
static int recv_pkt(git_pkt **out, git_pkt_type *pkt_type, gitno_buffer *buf)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe name it out_type instead? Just to make the parameter's intention a bit more clear

if (pkt_type == GIT_PKT_ACK) {
error = recv_pkt(NULL, &pkt_type, buf);
if (error < 0) {
goto on_error;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd propose to make it if ((error = recv_pkt(NULL, &pkt_type, buf)) < 0) goto on_error;. This would further disentangle handling of errors and the packet type.

if (pkt_type < 0) {
return pkt_type;
if (error < 0) {
return error;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

@tiennou
Copy link
Copy Markdown
Contributor Author

tiennou commented Feb 26, 2018

Rebased against master, and fixed review comments. I stumbled on a (small) memory leak when checking uses of recv_pkt, so that's also fixed.

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

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

There's some places where you're accidentally using spaces instead of tabs. Otherwise it looks fine, I think

Comment thread src/transports/smart_protocol.c Outdated
goto on_error;
} else if (pkt_type == GIT_PKT_ACK) {

if (pkt_type == GIT_PKT_ACK) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You're using spaces instead of tabs here

Comment thread src/transports/smart_protocol.c Outdated
return error;
} else if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {

if (pkt_type != GIT_PKT_ACK && pkt_type != GIT_PKT_NAK) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here as well, spaces instead of tab

Comment thread src/transports/smart_protocol.c Outdated
if (git_vector_insert(&t->common, pkt) < 0) {
git__free(pkt);
return -1;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here ;)

@tiennou tiennou force-pushed the fix/pkt-type-enum branch from eb2d9b9 to a2124a2 Compare April 11, 2018 19:04
@tiennou tiennou force-pushed the fix/pkt-type-enum branch from a2124a2 to 13a7727 Compare April 11, 2018 19:14
@tiennou
Copy link
Copy Markdown
Contributor Author

tiennou commented Apr 11, 2018

Fixup-ed spaces into tabs !

@ethomson
Copy link
Copy Markdown
Member

I like this cleanup, thanks for doing it (and thanks for your patience in getting it merged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants