]> git.proxmox.com Git - libgit2.git/blob - tests/status/status_helpers.c
Merge branch 'development'
[libgit2.git] / tests / status / status_helpers.c
1 #include "clar_libgit2.h"
2 #include "status_helpers.h"
3
4 int cb_status__normal(
5 const char *path, unsigned int status_flags, void *payload)
6 {
7 status_entry_counts *counts = payload;
8
9 if (counts->debug)
10 cb_status__print(path, status_flags, NULL);
11
12 if (counts->entry_count >= counts->expected_entry_count) {
13 counts->wrong_status_flags_count++;
14 goto exit;
15 }
16
17 if (strcmp(path, counts->expected_paths[counts->entry_count])) {
18 counts->wrong_sorted_path++;
19 goto exit;
20 }
21
22 if (status_flags != counts->expected_statuses[counts->entry_count])
23 counts->wrong_status_flags_count++;
24
25 exit:
26 counts->entry_count++;
27 return 0;
28 }
29
30 int cb_status__count(const char *p, unsigned int s, void *payload)
31 {
32 volatile int *count = (int *)payload;
33
34 GIT_UNUSED(p);
35 GIT_UNUSED(s);
36
37 (*count)++;
38
39 return 0;
40 }
41
42 int cb_status__single(const char *p, unsigned int s, void *payload)
43 {
44 status_entry_single *data = (status_entry_single *)payload;
45
46 if (data->debug)
47 fprintf(stderr, "%02d: %s (%04x)\n", data->count, p, s);
48
49 data->count++;
50 data->status = s;
51
52 return 0;
53 }
54
55 int cb_status__print(
56 const char *path, unsigned int status_flags, void *payload)
57 {
58 char istatus = ' ', wstatus = ' ';
59 int icount = 0, wcount = 0;
60
61 if (status_flags & GIT_STATUS_INDEX_NEW) {
62 istatus = 'A'; icount++;
63 }
64 if (status_flags & GIT_STATUS_INDEX_MODIFIED) {
65 istatus = 'M'; icount++;
66 }
67 if (status_flags & GIT_STATUS_INDEX_DELETED) {
68 istatus = 'D'; icount++;
69 }
70 if (status_flags & GIT_STATUS_INDEX_RENAMED) {
71 istatus = 'R'; icount++;
72 }
73 if (status_flags & GIT_STATUS_INDEX_TYPECHANGE) {
74 istatus = 'T'; icount++;
75 }
76
77 if (status_flags & GIT_STATUS_WT_NEW) {
78 wstatus = 'A'; wcount++;
79 }
80 if (status_flags & GIT_STATUS_WT_MODIFIED) {
81 wstatus = 'M'; wcount++;
82 }
83 if (status_flags & GIT_STATUS_WT_DELETED) {
84 wstatus = 'D'; wcount++;
85 }
86 if (status_flags & GIT_STATUS_WT_TYPECHANGE) {
87 wstatus = 'T'; wcount++;
88 }
89 if (status_flags & GIT_STATUS_IGNORED) {
90 wstatus = 'I'; wcount++;
91 }
92
93 fprintf(stderr, "%c%c %s (%d/%d%s)\n",
94 istatus, wstatus, path, icount, wcount,
95 (icount > 1 || wcount > 1) ? " INVALID COMBO" : "");
96
97 if (payload)
98 *((int *)payload) += 1;
99
100 return 0;
101 }