{"thread":{"id":"35530","subject":"[PATCH v3] contrib/git-credential-gnome-keyring.c: small stylistic cleanups","startedAt":"2013-12-14T11:21:26Z","lastAt":"2013-12-14T11:21:26Z","messageCount":1,"participants":["John Szakmeister"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"232020","messageId":"1387020086-92690-1-git-send-email-john@szakmeister.net","threadId":"35530","inReplyTo":null,"subject":"[PATCH v3] contrib/git-credential-gnome-keyring.c: small stylistic cleanups","fromName":"John Szakmeister","fromEmail":"john@szakmeister.net","sentAt":"2013-12-14T11:21:26Z","receivedAt":"2013-12-14T11:21:26Z","isPatch":true,"sender":{"key":"john@szakmeister.net","avatar":"https://avatars.githubusercontent.com/u/448087?v=4"},"body":"Signed-off-by: John Szakmeister <john@szakmeister.net>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\nReviewed-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n\nThanks for the extra patch Junio.  I incorporated it and fixed a\nfew other minor violations I found afterwards.  This version\nbuilds on the first version of the patch--without dropping the\ngpointer casts.\n\n-John\n\n .../gnome-keyring/git-credential-gnome-keyring.c   | 85 ++++++++++------------\n 1 file changed, 39 insertions(+), 46 deletions(-)\n\ndiff --git a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\nindex 635c96b..2a317fc 100644\n--- a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\n+++ b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c\n@@ -60,7 +60,7 @@\n #define gnome_keyring_memory_free gnome_keyring_free_password\n #define gnome_keyring_memory_strdup g_strdup\n \n-static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)\n+static const char *gnome_keyring_result_to_message(GnomeKeyringResult result)\n {\n \tswitch (result) {\n \tcase GNOME_KEYRING_RESULT_OK:\n@@ -95,9 +95,9 @@ static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)\n \n static void gnome_keyring_done_cb(GnomeKeyringResult result, gpointer user_data)\n {\n-\tgpointer *data = (gpointer*) user_data;\n-\tint *done = (int*) data[0];\n-\tGnomeKeyringResult *r = (GnomeKeyringResult*) data[1];\n+\tgpointer *data = (gpointer *)user_data;\n+\tint *done = (int *)data[0];\n+\tGnomeKeyringResult *r = (GnomeKeyringResult *)data[1];\n \n \t*r = result;\n \t*done = 1;\n@@ -130,34 +130,30 @@ static GnomeKeyringResult gnome_keyring_item_delete_sync(const char *keyring, gu\n /*\n  * This credential struct and API is simplified from git's credential.{h,c}\n  */\n-struct credential\n-{\n-\tchar          *protocol;\n-\tchar          *host;\n+struct credential {\n+\tchar *protocol;\n+\tchar *host;\n \tunsigned short port;\n-\tchar          *path;\n-\tchar          *username;\n-\tchar          *password;\n+\tchar *path;\n+\tchar *username;\n+\tchar *password;\n };\n \n-#define CREDENTIAL_INIT \\\n-  { NULL,NULL,0,NULL,NULL,NULL }\n+#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }\n \n-typedef int (*credential_op_cb)(struct credential*);\n+typedef int (*credential_op_cb)(struct credential *);\n \n-struct credential_operation\n-{\n-\tchar             *name;\n+struct credential_operation {\n+\tchar *name;\n \tcredential_op_cb op;\n };\n \n-#define CREDENTIAL_OP_END \\\n-  { NULL,NULL }\n+#define CREDENTIAL_OP_END { NULL, NULL }\n \n /* ----------------- GNOME Keyring functions ----------------- */\n \n /* create a special keyring option string, if path is given */\n-static char* keyring_object(struct credential *c)\n+static char *keyring_object(struct credential *c)\n {\n \tif (!c->path)\n \t\treturn NULL;\n@@ -170,7 +166,7 @@ static char* keyring_object(struct credential *c)\n \n static int keyring_get(struct credential *c)\n {\n-\tchar* object = NULL;\n+\tchar *object = NULL;\n \tGList *entries;\n \tGnomeKeyringNetworkPasswordData *password_data;\n \tGnomeKeyringResult result;\n@@ -204,7 +200,7 @@ static int keyring_get(struct credential *c)\n \t}\n \n \t/* pick the first one from the list */\n-\tpassword_data = (GnomeKeyringNetworkPasswordData *) entries->data;\n+\tpassword_data = (GnomeKeyringNetworkPasswordData *)entries->data;\n \n \tgnome_keyring_memory_free(c->password);\n \tc->password = gnome_keyring_memory_strdup(password_data->password);\n@@ -221,7 +217,7 @@ static int keyring_get(struct credential *c)\n static int keyring_store(struct credential *c)\n {\n \tguint32 item_id;\n-\tchar  *object = NULL;\n+\tchar *object = NULL;\n \tGnomeKeyringResult result;\n \n \t/*\n@@ -262,7 +258,7 @@ static int keyring_store(struct credential *c)\n \n static int keyring_erase(struct credential *c)\n {\n-\tchar  *object = NULL;\n+\tchar *object = NULL;\n \tGList *entries;\n \tGnomeKeyringNetworkPasswordData *password_data;\n \tGnomeKeyringResult result;\n@@ -298,22 +294,20 @@ static int keyring_erase(struct credential *c)\n \tif (result == GNOME_KEYRING_RESULT_CANCELLED)\n \t\treturn EXIT_SUCCESS;\n \n-\tif (result != GNOME_KEYRING_RESULT_OK)\n-\t{\n+\tif (result != GNOME_KEYRING_RESULT_OK) {\n \t\tg_critical(\"%s\", gnome_keyring_result_to_message(result));\n \t\treturn EXIT_FAILURE;\n \t}\n \n \t/* pick the first one from the list (delete all matches?) */\n-\tpassword_data = (GnomeKeyringNetworkPasswordData *) entries->data;\n+\tpassword_data = (GnomeKeyringNetworkPasswordData *)entries->data;\n \n \tresult = gnome_keyring_item_delete_sync(\n \t\tpassword_data->keyring, password_data->item_id);\n \n \tgnome_keyring_network_password_list_free(entries);\n \n-\tif (result != GNOME_KEYRING_RESULT_OK)\n-\t{\n+\tif (result != GNOME_KEYRING_RESULT_OK) {\n \t\tg_critical(\"%s\", gnome_keyring_result_to_message(result));\n \t\treturn EXIT_FAILURE;\n \t}\n@@ -325,9 +319,8 @@ static int keyring_erase(struct credential *c)\n  * Table with helper operation callbacks, used by generic\n  * credential helper main function.\n  */\n-static struct credential_operation const credential_helper_ops[] =\n-{\n-\t{ \"get\",   keyring_get   },\n+static struct credential_operation const credential_helper_ops[] = {\n+\t{ \"get\",   keyring_get },\n \t{ \"store\", keyring_store },\n \t{ \"erase\", keyring_erase },\n \tCREDENTIAL_OP_END\n@@ -353,24 +346,23 @@ static void credential_clear(struct credential *c)\n \n static int credential_read(struct credential *c)\n {\n-\tchar    *buf;\n+\tchar *buf;\n \tsize_t line_len;\n-\tchar   *key;\n-\tchar   *value;\n+\tchar *key;\n+\tchar *value;\n \n \tkey = buf = gnome_keyring_memory_alloc(1024);\n \n-\twhile (fgets(buf, 1024, stdin))\n-\t{\n+\twhile (fgets(buf, 1024, stdin)) {\n \t\tline_len = strlen(buf);\n \n \t\tif (line_len && buf[line_len-1] == '\\n')\n-\t\t\tbuf[--line_len]='\\0';\n+\t\t\tbuf[--line_len] = '\\0';\n \n \t\tif (!line_len)\n \t\t\tbreak;\n \n-\t\tvalue = strchr(buf,'=');\n+\t\tvalue = strchr(buf, '=');\n \t\tif (!value) {\n \t\t\tg_warning(\"invalid credential line: %s\", key);\n \t\t\tgnome_keyring_memory_free(buf);\n@@ -384,7 +376,7 @@ static int credential_read(struct credential *c)\n \t\t} else if (!strcmp(key, \"host\")) {\n \t\t\tg_free(c->host);\n \t\t\tc->host = g_strdup(value);\n-\t\t\tvalue = strrchr(c->host,':');\n+\t\t\tvalue = strrchr(c->host, ':');\n \t\t\tif (value) {\n \t\t\t\t*value++ = '\\0';\n \t\t\t\tc->port = atoi(value);\n@@ -398,7 +390,8 @@ static int credential_read(struct credential *c)\n \t\t} else if (!strcmp(key, \"password\")) {\n \t\t\tgnome_keyring_memory_free(c->password);\n \t\t\tc->password = gnome_keyring_memory_strdup(value);\n-\t\t\twhile (*value) *value++ = '\\0';\n+\t\t\twhile (*value)\n+\t\t\t\t*value++ = '\\0';\n \t\t}\n \t\t/*\n \t\t * Ignore other lines; we don't know what they mean, but\n@@ -429,16 +422,16 @@ static void credential_write(const struct credential *c)\n static void usage(const char *name)\n {\n \tstruct credential_operation const *try_op = credential_helper_ops;\n-\tconst char *basename = strrchr(name,'/');\n+\tconst char *basename = strrchr(name, '/');\n \n \tbasename = (basename) ? basename + 1 : name;\n \tfprintf(stderr, \"usage: %s <\", basename);\n \twhile (try_op->name) {\n-\t\tfprintf(stderr,\"%s\",(try_op++)->name);\n+\t\tfprintf(stderr, \"%s\", (try_op++)->name);\n \t\tif (try_op->name)\n-\t\t\tfprintf(stderr,\"%s\",\"|\");\n+\t\t\tfprintf(stderr, \"%s\", \"|\");\n \t}\n-\tfprintf(stderr,\"%s\",\">\\n\");\n+\tfprintf(stderr, \"%s\", \">\\n\");\n }\n \n int main(int argc, char *argv[])\n@@ -446,7 +439,7 @@ int main(int argc, char *argv[])\n \tint ret = EXIT_SUCCESS;\n \n \tstruct credential_operation const *try_op = credential_helper_ops;\n-\tstruct credential                  cred   = CREDENTIAL_INIT;\n+\tstruct credential cred = CREDENTIAL_INIT;\n \n \tif (!argv[1]) {\n \t\tusage(argv[0]);\n-- \n1.8.3.1\n"}]}