| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include <assert.h> |
| 2 |
|
|
#include <glib.h> |
| 3 |
|
|
#include <stdbool.h> |
| 4 |
|
|
#include <stdio.h> |
| 5 |
|
|
#include <stdlib.h> |
| 6 |
|
|
#include <string.h> |
| 7 |
|
|
#include "cmd/cmd.h" |
| 8 |
|
|
#include "verify/verify.h" |
| 9 |
|
|
|
| 10 |
|
|
static error_t parse_opt(int key, char* arg, struct argp_state* state); |
| 11 |
|
|
|
| 12 |
|
|
struct verify_arguments { |
| 13 |
|
|
struct global_arguments* global; |
| 14 |
|
|
GPtrArray* branch_names; |
| 15 |
|
|
}; |
| 16 |
|
|
|
| 17 |
|
|
static struct argp_option options[] = {{NULL}}; |
| 18 |
|
|
|
| 19 |
|
|
static char doc[] = |
| 20 |
|
|
"Verifies that all commits on the specified branches (or all branches if " |
| 21 |
|
|
"none specified) are signed by authorized developers."; |
| 22 |
|
|
|
| 23 |
|
|
static struct argp argp = {options, parse_opt, "[branch...]", doc, |
| 24 |
|
|
NULL, NULL, NULL}; |
| 25 |
|
|
|
| 26 |
|
11 |
static error_t parse_opt(int key, char* arg, struct argp_state* state) { |
| 27 |
|
11 |
struct verify_arguments* args = state->input; |
| 28 |
|
|
|
| 29 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
|
11 |
switch (key) { |
| 30 |
|
2 |
case ARGP_KEY_ARG: { |
| 31 |
|
2 |
g_ptr_array_add(args->branch_names, arg); |
| 32 |
|
2 |
break; |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
9 |
default: |
| 36 |
|
9 |
return ARGP_ERR_UNKNOWN; |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
2 |
return 0; |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
2 |
extern int gittor_verify(struct argp_state* state) { |
| 43 |
|
|
// Set defaults arguments |
| 44 |
|
4 |
struct verify_arguments args = {.global = state->input, |
| 45 |
1/1
✓ Branch 1 taken 2 times.
|
2 |
.branch_names = g_ptr_array_new()}; |
| 46 |
|
|
|
| 47 |
|
|
// Change the arguments array for just verify |
| 48 |
|
2 |
int argc = state->argc - state->next + 1; |
| 49 |
|
2 |
char** argv = &state->argv[state->next - 1]; |
| 50 |
|
|
|
| 51 |
|
|
// Change the command name to gittor verify |
| 52 |
|
2 |
const char name[] = "verify"; |
| 53 |
|
2 |
size_t argv0len = strlen(state->name) + sizeof(name) + 1; |
| 54 |
|
2 |
char* argv0 = argv[0]; |
| 55 |
|
2 |
argv[0] = malloc(argv0len); |
| 56 |
1/1
✓ Branch 1 taken 2 times.
|
2 |
g_snprintf(argv[0], argv0len, "%s %s", state->name, name); |
| 57 |
|
|
|
| 58 |
|
|
// Parse arguments |
| 59 |
1/1
✓ Branch 1 taken 2 times.
|
2 |
int err = argp_parse(&argp, argc, argv, ARGP_NO_EXIT, &argc, &args); |
| 60 |
|
|
|
| 61 |
|
|
// Stub output for template |
| 62 |
|
2 |
printf("%s PATH: %s (verify command not yet implemented)\n", argv[0], |
| 63 |
1/1
✓ Branch 1 taken 2 times.
|
2 |
args.global->path); |
| 64 |
|
|
|
| 65 |
|
|
// Rest back to global |
| 66 |
|
2 |
free(argv[0]); |
| 67 |
|
2 |
argv[0] = argv0; |
| 68 |
|
2 |
state->next += argc - 1; |
| 69 |
|
|
|
| 70 |
1/1
✓ Branch 1 taken 2 times.
|
2 |
g_ptr_array_free(args.branch_names, true); |
| 71 |
|
2 |
return err; |
| 72 |
|
|
} |
| 73 |
|
|
|