Skip to content

Commit 0162b3c

Browse files
jszakmeistergitster
authored andcommitted
contrib/git-credential-gnome-keyring.c: small stylistic cleanups
Signed-off-by: John Szakmeister <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Reviewed-by: Felipe Contreras <[email protected]>
1 parent a155a5f commit 0162b3c

File tree

1 file changed

+39
-46
lines changed

1 file changed

+39
-46
lines changed

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define gnome_keyring_memory_free gnome_keyring_free_password
6161
#define gnome_keyring_memory_strdup g_strdup
6262

63-
static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)
63+
static const char *gnome_keyring_result_to_message(GnomeKeyringResult result)
6464
{
6565
switch (result) {
6666
case GNOME_KEYRING_RESULT_OK:
@@ -95,9 +95,9 @@ static const char* gnome_keyring_result_to_message(GnomeKeyringResult result)
9595

9696
static void gnome_keyring_done_cb(GnomeKeyringResult result, gpointer user_data)
9797
{
98-
gpointer *data = (gpointer*) user_data;
99-
int *done = (int*) data[0];
100-
GnomeKeyringResult *r = (GnomeKeyringResult*) data[1];
98+
gpointer *data = (gpointer *)user_data;
99+
int *done = (int *)data[0];
100+
GnomeKeyringResult *r = (GnomeKeyringResult *)data[1];
101101

102102
*r = result;
103103
*done = 1;
@@ -130,34 +130,30 @@ static GnomeKeyringResult gnome_keyring_item_delete_sync(const char *keyring, gu
130130
/*
131131
* This credential struct and API is simplified from git's credential.{h,c}
132132
*/
133-
struct credential
134-
{
135-
char *protocol;
136-
char *host;
133+
struct credential {
134+
char *protocol;
135+
char *host;
137136
unsigned short port;
138-
char *path;
139-
char *username;
140-
char *password;
137+
char *path;
138+
char *username;
139+
char *password;
141140
};
142141

143-
#define CREDENTIAL_INIT \
144-
{ NULL,NULL,0,NULL,NULL,NULL }
142+
#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
145143

146-
typedef int (*credential_op_cb)(struct credential*);
144+
typedef int (*credential_op_cb)(struct credential *);
147145

148-
struct credential_operation
149-
{
150-
char *name;
146+
struct credential_operation {
147+
char *name;
151148
credential_op_cb op;
152149
};
153150

154-
#define CREDENTIAL_OP_END \
155-
{ NULL,NULL }
151+
#define CREDENTIAL_OP_END { NULL, NULL }
156152

157153
/* ----------------- GNOME Keyring functions ----------------- */
158154

159155
/* create a special keyring option string, if path is given */
160-
static char* keyring_object(struct credential *c)
156+
static char *keyring_object(struct credential *c)
161157
{
162158
if (!c->path)
163159
return NULL;
@@ -170,7 +166,7 @@ static char* keyring_object(struct credential *c)
170166

171167
static int keyring_get(struct credential *c)
172168
{
173-
char* object = NULL;
169+
char *object = NULL;
174170
GList *entries;
175171
GnomeKeyringNetworkPasswordData *password_data;
176172
GnomeKeyringResult result;
@@ -204,7 +200,7 @@ static int keyring_get(struct credential *c)
204200
}
205201

206202
/* pick the first one from the list */
207-
password_data = (GnomeKeyringNetworkPasswordData *) entries->data;
203+
password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
208204

209205
gnome_keyring_memory_free(c->password);
210206
c->password = gnome_keyring_memory_strdup(password_data->password);
@@ -221,7 +217,7 @@ static int keyring_get(struct credential *c)
221217
static int keyring_store(struct credential *c)
222218
{
223219
guint32 item_id;
224-
char *object = NULL;
220+
char *object = NULL;
225221
GnomeKeyringResult result;
226222

227223
/*
@@ -262,7 +258,7 @@ static int keyring_store(struct credential *c)
262258

263259
static int keyring_erase(struct credential *c)
264260
{
265-
char *object = NULL;
261+
char *object = NULL;
266262
GList *entries;
267263
GnomeKeyringNetworkPasswordData *password_data;
268264
GnomeKeyringResult result;
@@ -298,22 +294,20 @@ static int keyring_erase(struct credential *c)
298294
if (result == GNOME_KEYRING_RESULT_CANCELLED)
299295
return EXIT_SUCCESS;
300296

301-
if (result != GNOME_KEYRING_RESULT_OK)
302-
{
297+
if (result != GNOME_KEYRING_RESULT_OK) {
303298
g_critical("%s", gnome_keyring_result_to_message(result));
304299
return EXIT_FAILURE;
305300
}
306301

307302
/* pick the first one from the list (delete all matches?) */
308-
password_data = (GnomeKeyringNetworkPasswordData *) entries->data;
303+
password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
309304

310305
result = gnome_keyring_item_delete_sync(
311306
password_data->keyring, password_data->item_id);
312307

313308
gnome_keyring_network_password_list_free(entries);
314309

315-
if (result != GNOME_KEYRING_RESULT_OK)
316-
{
310+
if (result != GNOME_KEYRING_RESULT_OK) {
317311
g_critical("%s", gnome_keyring_result_to_message(result));
318312
return EXIT_FAILURE;
319313
}
@@ -325,9 +319,8 @@ static int keyring_erase(struct credential *c)
325319
* Table with helper operation callbacks, used by generic
326320
* credential helper main function.
327321
*/
328-
static struct credential_operation const credential_helper_ops[] =
329-
{
330-
{ "get", keyring_get },
322+
static struct credential_operation const credential_helper_ops[] = {
323+
{ "get", keyring_get },
331324
{ "store", keyring_store },
332325
{ "erase", keyring_erase },
333326
CREDENTIAL_OP_END
@@ -353,24 +346,23 @@ static void credential_clear(struct credential *c)
353346

354347
static int credential_read(struct credential *c)
355348
{
356-
char *buf;
349+
char *buf;
357350
size_t line_len;
358-
char *key;
359-
char *value;
351+
char *key;
352+
char *value;
360353

361354
key = buf = gnome_keyring_memory_alloc(1024);
362355

363-
while (fgets(buf, 1024, stdin))
364-
{
356+
while (fgets(buf, 1024, stdin)) {
365357
line_len = strlen(buf);
366358

367359
if (line_len && buf[line_len-1] == '\n')
368-
buf[--line_len]='\0';
360+
buf[--line_len] = '\0';
369361

370362
if (!line_len)
371363
break;
372364

373-
value = strchr(buf,'=');
365+
value = strchr(buf, '=');
374366
if (!value) {
375367
g_warning("invalid credential line: %s", key);
376368
gnome_keyring_memory_free(buf);
@@ -384,7 +376,7 @@ static int credential_read(struct credential *c)
384376
} else if (!strcmp(key, "host")) {
385377
g_free(c->host);
386378
c->host = g_strdup(value);
387-
value = strrchr(c->host,':');
379+
value = strrchr(c->host, ':');
388380
if (value) {
389381
*value++ = '\0';
390382
c->port = atoi(value);
@@ -398,7 +390,8 @@ static int credential_read(struct credential *c)
398390
} else if (!strcmp(key, "password")) {
399391
gnome_keyring_memory_free(c->password);
400392
c->password = gnome_keyring_memory_strdup(value);
401-
while (*value) *value++ = '\0';
393+
while (*value)
394+
*value++ = '\0';
402395
}
403396
/*
404397
* Ignore other lines; we don't know what they mean, but
@@ -429,24 +422,24 @@ static void credential_write(const struct credential *c)
429422
static void usage(const char *name)
430423
{
431424
struct credential_operation const *try_op = credential_helper_ops;
432-
const char *basename = strrchr(name,'/');
425+
const char *basename = strrchr(name, '/');
433426

434427
basename = (basename) ? basename + 1 : name;
435428
fprintf(stderr, "usage: %s <", basename);
436429
while (try_op->name) {
437-
fprintf(stderr,"%s",(try_op++)->name);
430+
fprintf(stderr, "%s", (try_op++)->name);
438431
if (try_op->name)
439-
fprintf(stderr,"%s","|");
432+
fprintf(stderr, "%s", "|");
440433
}
441-
fprintf(stderr,"%s",">\n");
434+
fprintf(stderr, "%s", ">\n");
442435
}
443436

444437
int main(int argc, char *argv[])
445438
{
446439
int ret = EXIT_SUCCESS;
447440

448441
struct credential_operation const *try_op = credential_helper_ops;
449-
struct credential cred = CREDENTIAL_INIT;
442+
struct credential cred = CREDENTIAL_INIT;
450443

451444
if (!argv[1]) {
452445
usage(argv[0]);

0 commit comments

Comments
 (0)