Skip to content

Commit

Permalink
treewide: remove use of C++ style comments
Browse files Browse the repository at this point in the history
C++ style comment ("//") are not specified by the ISO C90 standard and
thus do not conform to it. While libgit2 aims to conform to C90, we did
not enforce it until now, which is why quite a lot of these
non-conforming comments have snuck into our codebase. Do a tree-wide
conversion of all C++ style comments to the supported C style comments
to allow us enforcing strict C90 compliance in a later commit.
  • Loading branch information
pks-t committed Jul 13, 2018
1 parent f347a44 commit 9994cd3
Show file tree
Hide file tree
Showing 69 changed files with 191 additions and 182 deletions.
12 changes: 7 additions & 5 deletions examples/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ static void oid_parsing(git_oid *oid)
*/
git_oid_fromstr(oid, hex);

// Once we've converted the string into the oid value, we can get the raw
// value of the SHA by accessing `oid.id`

// Next we will convert the 20 byte raw SHA1 value to a human readable 40
// char hex value.
/*
* Once we've converted the string into the oid value, we can get the raw
* value of the SHA by accessing `oid.id`
*
* Next we will convert the 20 byte raw SHA1 value to a human readable 40
* char hex value.
*/
printf("\n*Raw to Hex*\n");
out[GIT_OID_HEXSZ] = '\0';

Expand Down
10 changes: 5 additions & 5 deletions examples/network/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void print_progress(const progress_data *pd)

static int sideband_progress(const char *str, int len, void *payload)
{
(void)payload; // unused
(void)payload; /* unused */

printf("remote: %.*s", len, str);
fflush(stdout);
Expand Down Expand Up @@ -82,15 +82,15 @@ int do_clone(git_repository *repo, int argc, char **argv)
const char *path = argv[2];
int error;

(void)repo; // unused
(void)repo; /* unused */

// Validate args
/* Validate args */
if (argc < 3) {
printf ("USAGE: %s <url> <path>\n", argv[0]);
return -1;
}

// Set up options
/* Set up options */
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
Expand All @@ -100,7 +100,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
clone_opts.fetch_opts.callbacks.payload = &pd;

// Do the clone
/* Do the clone */
error = git_clone(&cloned_repo, url, path, &clone_opts);
printf("\n");
if (error != 0) {
Expand Down
6 changes: 4 additions & 2 deletions examples/network/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#endif
#include "common.h"

// This could be run in the main loop whilst the application waits for
// the indexing to finish in a worker thread
/*
* This could be run in the main loop whilst the application waits for
* the indexing to finish in a worker thread
*/
static int index_cb(const git_transfer_progress *stats, void *data)
{
(void)data;
Expand Down
2 changes: 1 addition & 1 deletion examples/network/ls-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static int use_remote(git_repository *repo, char *name)
size_t refs_len, i;
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;

// Find the remote by name
/* Find the remote by name */
error = git_remote_lookup(&remote, repo, name);
if (error < 0) {
error = git_remote_create_anonymous(&remote, repo, name);
Expand Down
2 changes: 1 addition & 1 deletion src/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static int note_write(
git_oid oid;
git_tree *tree = NULL;

// TODO: should we apply filters?
/* TODO: should we apply filters? */
/* create note object */
if ((error = git_blob_create_frombuffer(&oid, repo, note, strlen(note))) < 0)
goto cleanup;
Expand Down
2 changes: 1 addition & 1 deletion src/refspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

int git_refspec__parse(git_refspec *refspec, const char *input, bool is_fetch)
{
// Ported from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/remote.c#L518-636
/* Ported from https://github.com/git/git/blob/f06d47e7e0d9db709ee204ed13a8a7486149f494/remote.c#L518-636 */

size_t llen;
int is_glob = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,

if ((tz_start[0] != '-' && tz_start[0] != '+') ||
git__strtol32(&offset, tz_start + 1, &tz_end, 10) < 0) {
//malformed timezone, just assume it's zero
/* malformed timezone, just assume it's zero */
offset = 0;
}

Expand Down
12 changes: 6 additions & 6 deletions src/trailer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static const char *next_line(const char *str)
if (nl) {
return nl + 1;
} else {
// return pointer to the NUL terminator:
/* return pointer to the NUL terminator: */
return str + strlen(str);
}
}
Expand Down Expand Up @@ -310,12 +310,12 @@ int git_message_trailers(git_message_trailer_array *trailer_arr, const char *mes
}

if (isalnum(*ptr) || *ptr == '-') {
// legal key character
/* legal key character */
NEXT(S_KEY);
}

if (*ptr == ' ' || *ptr == '\t') {
// optional whitespace before separator
/* optional whitespace before separator */
*ptr = 0;
NEXT(S_KEY_WS);
}
Expand All @@ -325,7 +325,7 @@ int git_message_trailers(git_message_trailer_array *trailer_arr, const char *mes
NEXT(S_SEP_WS);
}

// illegal character
/* illegal character */
GOTO(S_IGNORE);
}
case S_KEY_WS: {
Expand All @@ -341,7 +341,7 @@ int git_message_trailers(git_message_trailer_array *trailer_arr, const char *mes
NEXT(S_SEP_WS);
}

// illegal character
/* illegal character */
GOTO(S_IGNORE);
}
case S_SEP_WS: {
Expand Down Expand Up @@ -369,7 +369,7 @@ int git_message_trailers(git_message_trailer_array *trailer_arr, const char *mes
}
case S_VALUE_NL: {
if (*ptr == ' ') {
// continuation;
/* continuation; */
NEXT(S_VALUE);
}

Expand Down
6 changes: 3 additions & 3 deletions src/transports/smart.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ static bool is_malformed_http_header(const char *http_header)
const char *c;
int name_len;

// Disallow \r and \n
/* Disallow \r and \n */
c = strchr(http_header, '\r');
if (c)
return true;
c = strchr(http_header, '\n');
if (c)
return true;

// Require a header name followed by :
/* Require a header name followed by : */
name_len = http_header_name_length(http_header);
if (name_len < 1)
return true;
Expand All @@ -112,7 +112,7 @@ static bool is_forbidden_custom_header(const char *custom_header)
unsigned long i;
int name_len = http_header_name_length(custom_header);

// Disallow headers that we set
/* Disallow headers that we set */
for (i = 0; i < ARRAY_SIZE(forbidden_custom_headers); i++)
if (strncmp(forbidden_custom_headers[i], custom_header, name_len) == 0)
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/win32/posix_w32.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ int p_mkstemp(char *tmp_path)
return -1;
#endif

return p_open(tmp_path, O_RDWR | O_CREAT | O_EXCL, 0744); //-V536
return p_open(tmp_path, O_RDWR | O_CREAT | O_EXCL, 0744); /* -V536 */
}

int p_access(const char* path, mode_t mode)
Expand Down
2 changes: 1 addition & 1 deletion tests/checkout/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void test_checkout_index__honor_coresymlinks_default(void)
const char *url = git_repository_path(g_repo);

cl_assert(getcwd(cwd, sizeof(cwd)) != NULL);
cl_assert_equal_i(0, p_mkdir("readonly", 0555)); // Read-only directory
cl_assert_equal_i(0, p_mkdir("readonly", 0555)); /* Read-only directory */
cl_assert_equal_i(0, chdir("readonly"));
cl_git_pass(git_repository_init(&repo, "../symlink.git", true));
cl_assert_equal_i(0, chdir(cwd));
Expand Down
2 changes: 1 addition & 1 deletion tests/checkout/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void test_checkout_tree__target_directory_from_bare(void)

void test_checkout_tree__extremely_long_file_name(void)
{
// A utf-8 string with 83 characters, but 249 bytes.
/* A utf-8 string with 83 characters, but 249 bytes. */
const char *longname = "\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97\xe5\x8f\x97";
char path[1024];

Expand Down
2 changes: 1 addition & 1 deletion tests/cherrypick/workdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
static git_repository *repo;
static git_index *repo_index;

// Fixture setup and teardown
/* Fixture setup and teardown */
void test_cherrypick_workdir__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
Expand Down
58 changes: 29 additions & 29 deletions tests/commit/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "commit.h"
#include "signature.h"

// Fixture setup
/* Fixture setup */
static git_repository *g_repo;
void test_commit_parse__initialize(void)
{
Expand All @@ -15,7 +15,7 @@ void test_commit_parse__cleanup(void)
}


// Header parsing
/* Header parsing */
typedef struct {
const char *line;
const char *header;
Expand Down Expand Up @@ -70,7 +70,7 @@ void test_commit_parse__header(void)
}


// Signature parsing
/* Signature parsing */
typedef struct {
const char *string;
const char *header;
Expand All @@ -89,27 +89,27 @@ passing_signature_test_case passing_signature_cases[] = {
{"committer Vicent Marti <[email protected]> 123456 +0000 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 0},
{"committer Vicent Marti <[email protected]> 123456 +0100 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 60},
{"committer Vicent Marti <[email protected]> 123456 -0100 \n", "committer ", "Vicent Marti", "[email protected]", 123456, -60},
// Parse a signature without an author field
/* Parse a signature without an author field */
{"committer <[email protected]> 123456 -0100 \n", "committer ", "", "[email protected]", 123456, -60},
// Parse a signature without an author field
/* Parse a signature without an author field */
{"committer <[email protected]> 123456 -0100 \n", "committer ", "", "[email protected]", 123456, -60},
// Parse a signature with an empty author field
/* Parse a signature with an empty author field */
{"committer <[email protected]> 123456 -0100 \n", "committer ", "", "[email protected]", 123456, -60},
// Parse a signature with an empty email field
/* Parse a signature with an empty email field */
{"committer Vicent Marti <> 123456 -0100 \n", "committer ", "Vicent Marti", "", 123456, -60},
// Parse a signature with an empty email field
/* Parse a signature with an empty email field */
{"committer Vicent Marti < > 123456 -0100 \n", "committer ", "Vicent Marti", "", 123456, -60},
// Parse a signature with empty name and email
/* Parse a signature with empty name and email */
{"committer <> 123456 -0100 \n", "committer ", "", "", 123456, -60},
// Parse a signature with empty name and email
/* Parse a signature with empty name and email */
{"committer <> 123456 -0100 \n", "committer ", "", "", 123456, -60},
// Parse a signature with empty name and email
/* Parse a signature with empty name and email */
{"committer < > 123456 -0100 \n", "committer ", "", "", 123456, -60},
// Parse an obviously invalid signature
/* Parse an obviously invalid signature */
{"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
// Parse an obviously invalid signature
/* Parse an obviously invalid signature */
{"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
// Parse an obviously invalid signature
/* Parse an obviously invalid signature */
{"committer <>\n", "committer ", "", "", 0, 0},
{"committer Vicent Marti <[email protected]> 123456 -1500 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 0},
{"committer Vicent Marti <[email protected]> 123456 +0163 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 0},
Expand Down Expand Up @@ -173,65 +173,65 @@ void test_commit_parse__signature(void)


static char *failing_commit_cases[] = {
// empty commit
/* empty commit */
"",
// random garbage
/* random garbage */
"asd97sa9du902e9a0jdsuusad09as9du098709aweu8987sd\n",
// broken endlines 1
/* broken endlines 1 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\r\n\
parent 05452d6349abcd67aa396dfb28660d765d8b2a36\r\n\
author Vicent Marti <[email protected]> 1273848544 +0200\r\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\r\n\
\r\n\
a test commit with broken endlines\r\n",
// broken endlines 2
/* broken endlines 2 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\
parent 05452d6349abcd67aa396dfb28660d765d8b2a36\
author Vicent Marti <[email protected]> 1273848544 +0200\
committer Vicent Marti <[email protected]> 1273848544 +0200\
\
another test commit with broken endlines",
// starting endlines
/* starting endlines */
"\ntree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a test commit with a starting endline\n",
// corrupted commit 1
/* corrupted commit 1 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent 05452d6349abcd67aa396df",
// corrupted commit 2
/* corrupted commit 2 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent ",
// corrupted commit 3
/* corrupted commit 3 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent ",
// corrupted commit 4
/* corrupted commit 4 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
par",
};


static char *passing_commit_cases[] = {
// simple commit with no message
/* simple commit with no message */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n",
// simple commit, no parent
/* simple commit, no parent */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a simple commit which works\n",
// simple commit, no parent, no newline in message
/* simple commit, no parent, no newline in message */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a simple commit which works",
// simple commit, 1 parent
/* simple commit, 1 parent */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
parent e90810b8df3e80c413d903f631643c716887138d\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
Expand Down Expand Up @@ -317,7 +317,7 @@ void test_commit_parse__entire_commit(void)
}


// query the details on a parsed commit
/* query the details on a parsed commit */
void test_commit_parse__details0(void) {
static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
Expand Down Expand Up @@ -365,7 +365,7 @@ void test_commit_parse__details0(void) {
old_parent = parent;
cl_git_pass(git_commit_parent(&parent, commit, p));
cl_assert(parent != NULL);
cl_assert(git_commit_author(parent) != NULL); // is it really a commit?
cl_assert(git_commit_author(parent) != NULL); /* is it really a commit? */
}
git_commit_free(old_parent);
git_commit_free(parent);
Expand Down
Loading

0 comments on commit 9994cd3

Please sign in to comment.