-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstatus.cpp
executable file
·249 lines (221 loc) · 6.85 KB
/
status.cpp
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Status of files, including property dialogs.
*/
#include "stdafx.h"
typedef struct _LGitPropsDialogParams {
LGitContext *ctx;
unsigned int flags;
const char *path, *full_path;
const wchar_t *path_utf16, *full_path_utf16;
const git_index_entry *entry;
} LGitPropsDialogParams;
static void FillGeneral(HWND hwnd, LGitPropsDialogParams *params)
{
if (params->entry == NULL) {
return;
}
}
static void FillStatus(HWND hwnd, LGitPropsDialogParams *params)
{
/* Metaprogramming! */
#define LGIT_CHECK_PROPS_FLAG(flag) if(params->flags & GIT_STATUS_##flag) \
CheckDlgButton(hwnd, IDC_STATUS_##flag, BST_CHECKED);
/* XXX: how many here are actually possible? */
LGIT_CHECK_PROPS_FLAG(INDEX_NEW);
LGIT_CHECK_PROPS_FLAG(INDEX_MODIFIED);
LGIT_CHECK_PROPS_FLAG(INDEX_DELETED);
LGIT_CHECK_PROPS_FLAG(INDEX_RENAMED);
LGIT_CHECK_PROPS_FLAG(INDEX_TYPECHANGE);
LGIT_CHECK_PROPS_FLAG(WT_NEW);
LGIT_CHECK_PROPS_FLAG(WT_MODIFIED);
LGIT_CHECK_PROPS_FLAG(WT_DELETED);
LGIT_CHECK_PROPS_FLAG(WT_RENAMED);
LGIT_CHECK_PROPS_FLAG(WT_TYPECHANGE);
LGIT_CHECK_PROPS_FLAG(WT_UNREADABLE);
LGIT_CHECK_PROPS_FLAG(IGNORED);
LGIT_CHECK_PROPS_FLAG(CONFLICTED);
/* XXX: Do we display properties for the last commit? History covers it? */
}
static BOOL CALLBACK StatusDialogProc(HWND hwnd,
unsigned int iMsg,
WPARAM wParam,
LPARAM lParam)
{
LGitPropsDialogParams *param;
PROPSHEETPAGE *psp;
switch (iMsg) {
case WM_INITDIALOG:
psp = (PROPSHEETPAGE*)lParam;
param = (LGitPropsDialogParams*)psp->lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
FillStatus(hwnd, param);
return TRUE;
default:
return FALSE;
}
}
static void ShowSysFileProperties(const wchar_t *fullpath)
{
SHELLEXECUTEINFOW info;
ZeroMemory(&info, sizeof(SHELLEXECUTEINFO));
info.cbSize = sizeof info;
info.lpFile = fullpath;
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
info.lpVerb = L"properties";
/* XXX: COM should be initialized, VS does it for us? */
ShellExecuteExW(&info);
}
static void UpdateFileInfo(HWND hwnd, LGitPropsDialogParams *params)
{
const char *type = "Unknown";
uint32_t mode = -1;
if (params->entry == NULL) {
type = "No stage entry";
goto fin;
}
mode = params->entry->mode;
LGitLog(" ! Mode is %x/%o", mode, mode);
if ((mode & 0xE000) == 0xE000) {
type = "Gitlink";
} else if ((mode & 0xA000) == 0xA000) {
type = "Symlink";
} else if ((mode & 0x8000) == 0x8000) {
type = (mode & 0111)
? "Executable file"
: "File";
}
fin:
SetDlgItemText(hwnd, IDC_FILEPROPS_STAGE_TYPE, type);
}
static BOOL CALLBACK GeneralDialogProc(HWND hwnd,
unsigned int iMsg,
WPARAM wParam,
LPARAM lParam)
{
LGitPropsDialogParams *param;
PROPSHEETPAGE *psp;
switch (iMsg) {
case WM_INITDIALOG:
psp = (PROPSHEETPAGE*)lParam;
param = (LGitPropsDialogParams*)psp->lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
UpdateFileInfo(hwnd, param);
return TRUE;
case WM_COMMAND:
param = (LGitPropsDialogParams*)GetWindowLong(hwnd, GWL_USERDATA);
switch (LOWORD(wParam)) {
case IDC_FILESYSPROPS:
ShowSysFileProperties(param->full_path_utf16);
return TRUE;
}
return FALSE;
default:
return FALSE;
}
}
static SCCRTN ShowPropertiesDialog(LGitContext *ctx,
HWND hWnd,
const char *full_path,
const char *relative_path)
{
LGitPropsDialogParams params;
int rc = git_status_file(¶ms.flags, ctx->repo, relative_path);
switch (rc) {
case 0:
break;
case GIT_ENOTFOUND:
LGitLog(" ! Not found from status\n");
return SCC_E_FILENOTCONTROLLED;
default:
LGitLibraryError(NULL, "Query info");
return SCC_E_NONSPECIFICERROR;
}
/* Get the index entry in case it turns out to be useful */
git_index *index = NULL;
if (git_repository_index(&index, ctx->repo) != 0) {
LGitLibraryError(hWnd, "git_repository_index");
return SCC_E_NONSPECIFICERROR;
}
wchar_t relative_path_utf16[2048];
LGitUtf8ToWide(relative_path, relative_path_utf16, 2048);
wchar_t full_path_utf16[2048];
LGitUtf8ToWide(full_path, full_path_utf16, 2048);
params.ctx = ctx;
params.path = relative_path;
params.full_path = full_path;
params.path_utf16 = relative_path_utf16;
params.full_path_utf16 = full_path_utf16;
params.entry = git_index_get_bypath(index, relative_path, 0);
LGitLog(" ! Entry is %p\n", params.entry);
PROPSHEETPAGEW psp[2];
ZeroMemory(&psp[0], sizeof(PROPSHEETPAGEW));
psp[0].dwSize = sizeof(PROPSHEETPAGEW);
psp[0].hInstance = ctx->dllInst;
psp[0].pszTemplate = MAKEINTRESOURCEW(IDD_FILEPROPS_FILE);
psp[0].pfnDlgProc = GeneralDialogProc;
psp[0].lParam = (LPARAM)¶ms;
ZeroMemory(&psp[1], sizeof(PROPSHEETPAGEW));
psp[1].dwSize = sizeof(PROPSHEETPAGEW);
psp[1].hInstance = ctx->dllInst;
psp[1].pszTemplate = MAKEINTRESOURCEW(IDD_FILEPROPS_STATUS);
psp[1].pfnDlgProc = StatusDialogProc;
psp[1].lParam = (LPARAM)¶ms;
PROPSHEETHEADERW psh;
ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
psh.dwSize = sizeof(PROPSHEETHEADERW);
psh.dwFlags = PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
| PSH_PROPTITLE
| PSH_NOCONTEXTHELP
| PSH_USECALLBACK;
psh.pfnCallback = LGitImmutablePropSheetProc;
psh.hwndParent = hWnd;
psh.hInstance = ctx->dllInst;
psh.pszCaption = relative_path_utf16;
psh.nPages = 2;
psh.ppsp = psp;
PropertySheetW(&psh);
if (index != NULL) {
git_index_free(index);
}
return SCC_OK;
}
/**
* Like SccProperties, but takes a relative libgit2 path.
*
* (It will construct a full path based on the workdir.
*/
SCCRTN LGitFileProperties(LGitContext *ctx, HWND hWnd, LPCSTR relative_path)
{
char full_path[1024];
strlcpy(full_path, ctx->workdir_path, 1024);
strlcat(full_path, relative_path, 1024);
LGitTranslateStringChars(full_path, '/', '\\');
return ShowPropertiesDialog(ctx, hWnd, full_path, relative_path);
}
SCCRTN SccProperties (LPVOID context,
HWND hWnd,
LPCSTR lpFileName)
{
const char *relative_path;
char full_path[2048];
LGitContext *ctx = (LGitContext*)context;
LGitLog("**SccProperties** Context=%p\n", context);
LGitLog(" %s\n", lpFileName);
LGitAnsiToUtf8(lpFileName, full_path, 2048);
if (full_path == NULL) {
LGitLog("!! Couldn't alloc utf8 path str\n");
return SCC_E_NONSPECIFICERROR;
}
relative_path = LGitStripBasePath(ctx, full_path);
if (relative_path == NULL) {
LGitLog(" Couldn't get base path for %s\n", lpFileName);
return SCC_E_NONSPECIFICERROR;
}
/* Translate because libgit2 operates with forward slashes */
LGitTranslateStringChars(full_path, '\\', '/');
/* declaring here in case can use the wide conv from AnsiToUtf8Alloc */
SCCRTN ret = ShowPropertiesDialog(ctx, hWnd, full_path, relative_path);
return ret;
}