-
Notifications
You must be signed in to change notification settings - Fork 2
/
revparse.cpp
executable file
·188 lines (181 loc) · 4.76 KB
/
revparse.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
/*
* Generic dialogs for getting a revparse compatible string (or parsing it?)
*/
#include <stdafx.h>
typedef struct _LGitRevparseDialogParams {
LGitContext *ctx;
char spec[128];
char title[128];
git_object *obj;
git_reference *ref;
} LGitRevparseDialogParams;
static void InitRevparseView(HWND hwnd, LGitRevparseDialogParams* params)
{
if (strlen(params->title)) {
SetWindowText(hwnd, params->title);
};
/* yeah, we should load it from the struct... */
HWND ref_cb = GetDlgItem(hwnd, IDC_REVPARSE_SPEC);
LGitPopulateReferenceComboBox(hwnd, ref_cb, params->ctx);
wchar_t spec[128];
LGitUtf8ToWide(params->spec, spec, 128);
SetWindowTextW(ref_cb, spec);
}
static BOOL SetRevparseParams(HWND hwnd, LGitRevparseDialogParams* params)
{
wchar_t spec[128];
GetDlgItemTextW(hwnd, IDC_REVPARSE_SPEC, spec, 128);
LGitWideToUtf8(spec, params->spec, 128);
int rc = git_revparse_ext(¶ms->obj, ¶ms->ref, params->ctx->repo, params->spec);
BOOL ret = FALSE;
/* XXX: Should these be passed out? */;
switch (rc) {
case GIT_EAMBIGUOUS:
MessageBox(hwnd,
"The specification entered is ambiguous and needs to be more specific.",
params->spec,
MB_ICONERROR);
break;
case GIT_EINVALIDSPEC:
MessageBox(hwnd,
"The specification entered is invalid.",
params->spec,
MB_ICONERROR);
break;
case GIT_ENOTFOUND:
MessageBox(hwnd,
"The revision couldn't be found.",
params->spec,
MB_ICONERROR);
break;
case 0:
ret = TRUE;
break;
default:
LGitLibraryError(hwnd, "git_revparse_ext");
}
return ret;
}
static BOOL CALLBACK RevparseDialogProc(HWND hwnd,
unsigned int iMsg,
WPARAM wParam,
LPARAM lParam)
{
LGitRevparseDialogParams *param;
param = (LGitRevparseDialogParams*)GetWindowLong(hwnd, GWL_USERDATA);
switch (iMsg) {
case WM_INITDIALOG:
LGitLog(" ! Init\n");
param = (LGitRevparseDialogParams*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
InitRevparseView(hwnd, param);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
if (SetRevparseParams(hwnd, param)) {
EndDialog(hwnd, 2);
}
return TRUE;
case IDCANCEL:
EndDialog(hwnd, 1);
return TRUE;
}
return FALSE;
case WM_MEASUREITEM:
if (wParam == IDC_REVPARSE_SPEC) {
return LGitMeasureIconComboBoxItem(hwnd, wParam, (MEASUREITEMSTRUCT *)lParam);
}
return FALSE;
case WM_DRAWITEM:
if (wParam == IDC_REVPARSE_SPEC) {
return LGitDrawIconComboBox(param->ctx, param->ctx->refTypeIl, hwnd, wParam, (DRAWITEMSTRUCT *)lParam);
}
return FALSE;
default:
return FALSE;
}
}
/**
* A dialog that parses with revparse, but gives you the valid string instead.
*
* Caller provides the buffer, and can use it to suggest a name.
*/
SCCRTN LGitRevparseDialogString(LGitContext *ctx, HWND hwnd, const char *title, char *spec, size_t bufsz)
{
LGitLog("**LGitRevparseDialogString** Context=%p\n", ctx);
LGitLog(" spec %s\n", spec);
LGitRevparseDialogParams rp_params;
ZeroMemory(&rp_params, sizeof(LGitRevparseDialogParams));
rp_params.ctx = ctx;
strlcpy(rp_params.title, title, 128);
strlcpy(rp_params.spec, spec, 128);
SCCRTN ret = SCC_OK;
switch (DialogBoxParamW(ctx->dllInst,
MAKEINTRESOURCEW(IDD_REVPARSE),
hwnd,
RevparseDialogProc,
(LPARAM)&rp_params)) {
case 0:
case -1:
LGitLog(" ! Uh-oh, dialog error\n");
ret = SCC_E_NONSPECIFICERROR;
goto fin;
case 1:
ret = SCC_I_OPERATIONCANCELED;
goto fin;
case 2:
break;
}
fin:
if (rp_params.obj != NULL) {
git_object_free(rp_params.obj);
}
if (rp_params.ref != NULL) {
git_reference_free(rp_params.ref);
}
return ret;
}
/**
* A dialog that calls revparse for you. Caller frees libgit2 objects.
*
* XXX: Is above redundant?
*/
SCCRTN LGitRevparseDialog(LGitContext *ctx, HWND hwnd, const char *title, const char *suggested_spec, git_object **obj, git_reference **ref)
{
LGitLog("**LGitRevparseDialog** Context=%p\n", ctx);
LGitRevparseDialogParams rp_params;
ZeroMemory(&rp_params, sizeof(LGitRevparseDialogParams));
rp_params.ctx = ctx;
strlcpy(rp_params.title, title, 128);
strlcpy(rp_params.spec, suggested_spec, 128);
SCCRTN ret = SCC_OK;
switch (DialogBoxParamW(ctx->dllInst,
MAKEINTRESOURCEW(IDD_REVPARSE),
hwnd,
RevparseDialogProc,
(LPARAM)&rp_params)) {
case 0:
case -1:
LGitLog(" ! Uh-oh, dialog error\n");
ret = SCC_E_NONSPECIFICERROR;
goto fin;
case 1:
ret = SCC_I_OPERATIONCANCELED;
goto fin;
case 2:
break;
}
fin:
if (obj != NULL) {
*obj = rp_params.obj;
} else {
git_object_free(rp_params.obj);
}
if (ref != NULL) {
*ref = rp_params.ref;
} else {
git_reference_free(rp_params.ref);
}
return ret;
}