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