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

Introduce default format for code base. #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ViToni
Copy link
Contributor

@ViToni ViToni commented May 5, 2017

The first commit introduces a new goal: make reformat based on clang-reformat (at least version 3.9 should be used).
This target is optional.

The second commit contains all changes after the execution of this command.

In the future committers can normalize their code by simply using the make goal.

@ViToni ViToni mentioned this pull request May 6, 2017
@pali
Copy link
Owner

pali commented May 6, 2017

It is a good idea to have just one consistent coding style in whole project, but I dislike your proposed code style where are too many spaces around parenthesis. E.g. spaces around void in
static void debugQueue( void );

@ViToni
Copy link
Contributor Author

ViToni commented May 7, 2017

Actually I don't mind which formatting style is to be used.
For me it's only important that there is one and that formatting is consistent all over the code base.

There are even some defaults styles (LLVM, Google, Chromium, Mozilla, WebKit) which could used:
http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html

Just choose a style and we can stick to it.

@pali
Copy link
Owner

pali commented May 7, 2017

Try something like this?

BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 4
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true

@ViToni
Copy link
Contributor Author

ViToni commented May 7, 2017

AFAIK AllowShortFunctionsOnASingleLine should be either true or false.

I would suggest having UseTab: Never as one of the mandatory options as the mixture of tabs and whitespaces really messes diffs up.

Having also MaxEmptyLinesToKeep: 1 or MaxEmptyLinesToKeep: 2 might be useful, too.

@ViToni
Copy link
Contributor Author

ViToni commented May 7, 2017

BTW I already pushed another version of reformatted source code settings (based on the initial format settings) when writting #19 (comment) , so you might want to check, if you like it more.

@pali
Copy link
Owner

pali commented May 7, 2017

AFAIK AllowShortFunctionsOnASingleLine should be either true or false

According to http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html possible values are: None, Empty, Inline, All

I would suggest having UseTab: Never

Already part of BasedOnStyle: LLVM

Having also MaxEmptyLinesToKeep: 1

Also part of BasedOnStyle: LLVM

or MaxEmptyLinesToKeep: 2 might be useful, too.

BasedOnStyle: LLVM set it to 1, but 2 seems to be better value.

@ViToni
Copy link
Contributor Author

ViToni commented May 7, 2017

AFAIK AllowShortFunctionsOnASingleLine should be either true or false

According to http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html possible values are: None, Empty, Inline, All

You are right. (saw the boolean option here https://clangformat.com/)

I would suggest having UseTab: Never

Already part of BasedOnStyle: LLVM

It was more meant to be explicit.

I update the PR using these settings:

BasedOnStyle: LLVM
Language: Cpp

IndentWidth: 4
ContinuationIndentWidth: 8

ColumnLimit: 120

MaxEmptyLinesToKeep: 2

AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true

src/ifvc.c Outdated
}

/*
** Builds up a vector with the interface of the machine. Calls to the other functions of
** Builds up a vector with the interface of the machine. Calls to the other
*functions of
Copy link
Owner

Choose a reason for hiding this comment

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

This is badly wrapped comment. Such changes are really not acceptable.

@ViToni
Copy link
Contributor Author

ViToni commented May 7, 2017

Changed the mentioned part manually so that future calls of make reformat should work there nicely.

src/confread.c Outdated
if(bufPtr == readSize) {
while (!finished) {
// If readpointer is at the end of the buffer, we should read next
// chunk...
Copy link
Owner

Choose a reason for hiding this comment

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

same there

src/igmp.c Outdated
for (i = 0; i < MAX_UPS_VIFS; i++) {
if (-1 != upStreamIfIdx[i]) {
// Check if the source address matches a valid address on upstream
// vif.
Copy link
Owner

Choose a reason for hiding this comment

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

same here

}
} else {
// Activate the route.
int vifindex = checkVIF->index;
my_log(LOG_DEBUG, 0, "Route activate request from %s to %s on VIF[%d]",
inetFmt(src,s1), inetFmt(dst,s2), vifindex);
my_log(LOG_DEBUG, 0, "Route activate request from %s to %s on VIF[%d]", inetFmt(src, s1),
Copy link
Owner

Choose a reason for hiding this comment

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

rather let inetFmt(src, s1) at second line after wrap

Copy link
Contributor Author

@ViToni ViToni May 7, 2017

Choose a reason for hiding this comment

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

This is the result of automatic reformatting.

It can be changed either by having other formatting options (which would still look differently) or
it could be solved by using clang directives such as

int formatted_code;
// clang-format off
    void    unformatted_code   ;
// clang-format on
void formatted_code_again;

I would prefer rather not introduce clang specific stuff into the code.

Copy link
Owner

Choose a reason for hiding this comment

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

So what does it mean? It means that automatic reformatting is not a perfect solution and has problems.

Therefore we should use it only as help tool, not enforcement, like here.

src/mcgroup.c Outdated
@@ -71,17 +65,19 @@ static int joinleave( int Cmd, int UdpSock, struct IfDesc *IfDp, uint32_t mcasta
* The join is bound to the UDP socket 'UdpSock', so if this socket is
* closed the membership is dropped.
*
* @return 0 if the function succeeds, 1 if parameters are wrong or the join fails
* @return 0 if the function succeeds, 1 if parameters are wrong or the join
* fails
Copy link
Owner

Choose a reason for hiding this comment

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

same here

* To make reformatting reproducible `make reformat` was used.

Signed-off-by: Victor Toni <[email protected]>
} else if (src == checkVIF->InAdr.s_addr) {
my_log(LOG_NOTICE, 0,
"Route activation request from %s for %s is "
"from myself. Ignoring.",
Copy link
Owner

Choose a reason for hiding this comment

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

Please do not split string into more multiline parts.

inetFmt(src, s1), inetFmt(dst, s2), i);
my_log(LOG_NOTICE, 0,
"The source address %s for group %s is "
"from downstream VIF[%d]. Ignoring.",
Copy link
Owner

Choose a reason for hiding this comment

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

same here (and on other places)

" -h Display this help screen\n"
" -d Run in debug mode. Output all messages on stderr\n"
" -v Be verbose. Give twice to see even debug messages.\n"
"\n" PACKAGE_STRING "\n";
Copy link
Owner

Choose a reason for hiding this comment

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

and here should be newline, after each "\n" to visually identify end of lines.


// Global vars...
static int sighandled = 0;
#define GOT_SIGINT 0x01
#define GOT_SIGHUP 0x02
Copy link
Owner

Choose a reason for hiding this comment

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

let that space here, to have visually aligned those #defines

) {
my_log( LOG_ERR, errno, "failed to detach daemon" );
if (close(0) < 0 || close(1) < 0 || close(2) < 0 || open("/dev/null", 0) != 0 || dup2(0, 1) < 0 ||
dup2(0, 2) < 0 || setpgid(0, 0) < 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

previous wrapping to 3 lines was better. close() calls on one line, open+dup() on second line and setpgid() on third.

#define MAX_IP_PACKET_LEN 576
#define MIN_IP_HEADER_LEN 20
#define MAX_IP_HEADER_LEN 60
#define IP_HEADER_RAOPT_LEN 24
Copy link
Owner

Choose a reason for hiding this comment

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

And let those defines aligned as they were too

((uint8_t *)&InAdr.s_addr)[ 0 ],
((uint8_t *)&InAdr.s_addr)[ 1 ],
((uint8_t *)&InAdr.s_addr)[ 2 ],
((uint8_t *)&InAdr.s_addr)[ 3 ] );
Copy link
Owner

Choose a reason for hiding this comment

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

And line wrapping here was also better before reformatting

* queries.
*
* It might be better to send only a query on the interface the leave
* was accepted on and remove only that interface from the route.
Copy link
Owner

Choose a reason for hiding this comment

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

This is not good reformat. Second sentence is also part of FIXME, but after change is not visually anymore.

inetFmt(Dp->InAdr.s_addr,s1),
inetFmt(allhosts_group,s2),
conf->queryResponseInterval);
my_log(LOG_DEBUG, 0, "Sent membership query from %s to %s. Delay: %d", inetFmt(Dp->InAdr.s_addr, s1),
Copy link
Owner

Choose a reason for hiding this comment

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

here also put inetFmt on second line


/*******************************************************************************
* Opens config file specified by filename.
******************************************************************************/
Copy link
Owner

Choose a reason for hiding this comment

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

This reformat (and on other places too) introduce inconsistency. As in other files is used just:

/**
*   ...
*   ...
*/

@pali
Copy link
Owner

pali commented Oct 30, 2017

@ViToni seems that auto-reformat by robot/machine for everything does not work as expected. After automatic reformat it needs some manual work to fix some parts. So I do not think that "make reformat" target is a good idea.

But, this is really an improvement for the code... so are you going to fix needed parts manually and finish this work in this pull request?

@pali pali mentioned this pull request Aug 28, 2018
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