Hash :
22b6b82f
Author :
Date :
2013-06-20T12:16:06
Add status flags to force output sort order Files in status will, be default, be sorted according to the case insensitivity of the filesystem that we're running on. However, in some cases, this is not desirable. Even on case insensitive file systems, 'git status' at the command line will generally use a case sensitive sort (like 'ls'). Some GUIs prefer to display a list of file case insensitively even on case-sensitive platforms. This adds two new flags: GIT_STATUS_OPT_SORT_CASE_SENSITIVELY and GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY that will override the default sort order of the status output and give the user control. This includes tests for exercising these new options and makes the examples/status.c program emulate core Git and always use a case sensitive sort.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#include "clar_libgit2.h"
#include "status_helpers.h"
int cb_status__normal(
const char *path, unsigned int status_flags, void *payload)
{
status_entry_counts *counts = payload;
if (counts->debug)
cb_status__print(path, status_flags, NULL);
if (counts->entry_count >= counts->expected_entry_count) {
counts->wrong_status_flags_count++;
goto exit;
}
if (strcmp(path, counts->expected_paths[counts->entry_count])) {
counts->wrong_sorted_path++;
goto exit;
}
if (status_flags != counts->expected_statuses[counts->entry_count])
counts->wrong_status_flags_count++;
exit:
counts->entry_count++;
return 0;
}
int cb_status__count(const char *p, unsigned int s, void *payload)
{
volatile int *count = (int *)payload;
GIT_UNUSED(p);
GIT_UNUSED(s);
(*count)++;
return 0;
}
int cb_status__single(const char *p, unsigned int s, void *payload)
{
status_entry_single *data = (status_entry_single *)payload;
if (data->debug)
fprintf(stderr, "%02d: %s (%04x)\n", data->count, p, s);
data->count++;
data->status = s;
return 0;
}
int cb_status__print(
const char *path, unsigned int status_flags, void *payload)
{
char istatus = ' ', wstatus = ' ';
int icount = 0, wcount = 0;
if (status_flags & GIT_STATUS_INDEX_NEW) {
istatus = 'A'; icount++;
}
if (status_flags & GIT_STATUS_INDEX_MODIFIED) {
istatus = 'M'; icount++;
}
if (status_flags & GIT_STATUS_INDEX_DELETED) {
istatus = 'D'; icount++;
}
if (status_flags & GIT_STATUS_INDEX_RENAMED) {
istatus = 'R'; icount++;
}
if (status_flags & GIT_STATUS_INDEX_TYPECHANGE) {
istatus = 'T'; icount++;
}
if (status_flags & GIT_STATUS_WT_NEW) {
wstatus = 'A'; wcount++;
}
if (status_flags & GIT_STATUS_WT_MODIFIED) {
wstatus = 'M'; wcount++;
}
if (status_flags & GIT_STATUS_WT_DELETED) {
wstatus = 'D'; wcount++;
}
if (status_flags & GIT_STATUS_WT_TYPECHANGE) {
wstatus = 'T'; wcount++;
}
if (status_flags & GIT_STATUS_IGNORED) {
wstatus = 'I'; wcount++;
}
fprintf(stderr, "%c%c %s (%d/%d%s)\n",
istatus, wstatus, path, icount, wcount,
(icount > 1 || wcount > 1) ? " INVALID COMBO" : "");
if (payload)
*((int *)payload) += 1;
return 0;
}