Skip to content

Commit dc01f02

Browse files
committed
Sync
- Make SccGet able to use old behaviour, put new behaviour behind SccGetCommandOptions - Rump support for libgit2 to Win32 codepage conversion - Use wide text in commit view and history, as well as needed support functions. The wide text in commit view breaks compat with 9x unless it's runtime checked or unicows'd. (OFC, we need a unicows'd libgit2, so the point is moot.) - Mark SccEnumChangedFiles as unsupported, since the semantics don't make sense with remotes. - Refactor folder browser dialog for any future use.
1 parent c91219b commit dc01f02

17 files changed

Lines changed: 406 additions & 118 deletions

LGit.aps

736 Bytes
Binary file not shown.

LGit.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ typedef std::set<std::string> CheckoutQueue;
1818
typedef struct _LGitCommitOpts {
1919
BOOL push;
2020
} LGitCommitOpts;
21+
typedef struct _LGitGetOpts {
22+
BOOL pull;
23+
} LGitGetOpts;
2124

2225
typedef struct _LGitContext {
2326
/* housekeeping */
@@ -29,6 +32,8 @@ typedef struct _LGitContext {
2932
git_repository *repo;
3033
/* used for faking checkout status */
3134
CheckoutQueue *checkouts;
35+
/* suppress SccGet after clone */
36+
BOOL immediatelyAfterClone;
3237
/* callbacks and such provided by IDE */
3338
OPTNAMECHANGEPFN renameCb;
3439
LPVOID renameData;
@@ -43,6 +48,7 @@ typedef struct _LGitContext {
4348
char username[SCC_USER_SIZE];
4449
/* Command options */
4550
LGitCommitOpts commitOpts;
51+
LGitGetOpts getOpts;
4652
} LGitContext;
4753

4854
/* LGit.cpp */
@@ -62,8 +68,11 @@ const char *LGitStripBasePath(LGitContext *ctx, const char *abs);
6268
BOOL LGitGetProjectNameFromPath(char *project, const char *path, size_t bufsz);
6369

6470
/* format.cpp */
65-
BOOL LGitTimeToString(const git_time *time, char *buf, int bufsz);
66-
int LGitFormatSignature(const git_signature *sig, char *buf, int bufsz);
71+
BOOL LGitTimeToString(const git_time *time, char *buf, size_t bufsz);
72+
int LGitFormatSignature(const git_signature *sig, char *buf, size_t bufsz);
73+
BOOL LGitTimeToStringW(const git_time *time, wchar_t *buf, size_t bufsz);
74+
int LGitFormatSignatureW(const git_signature *sig, wchar_t *buf, size_t bufsz);
75+
UINT LGitGitToWindowsCodepage(const char *encoding);
6776

6877
/* checkout.cpp */
6978
void LGitPushCheckout(LGitContext *ctx, const char *fileName);
@@ -131,7 +140,10 @@ BOOL LGitCertificatePrompt(LGitContext *ctx, HWND parent, git_cert *cert, const
131140
char *strcasestr(const char *s, const char *find);
132141
size_t strlcat(char *dst, const char *src, size_t siz);
133142
size_t strlcpy(char *dst, const char *src, size_t siz);
143+
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t dsize);
144+
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t dsize);
134145

135146
/* winutil.cpp */
136147
void LGitPopulateRemoteComboBox(HWND parent, HWND cb, LGitContext *ctx);
148+
BOOL LGitBrowseForFolder(HWND hwnd, const char *title, char *buf, size_t bufsz);
137149
void LGitSetWindowIcon(HWND hwnd, HINSTANCE inst, LPCSTR name);

LGit.rc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ BEGIN
303303
WS_VSCROLL | WS_TABSTOP
304304
END
305305

306+
IDD_OPTIONS_GET DIALOG DISCARDABLE 0, 0, 162, 74
307+
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
308+
CAPTION "Get Options"
309+
FONT 8, "MS Sans Serif"
310+
BEGIN
311+
DEFPUSHBUTTON "OK",IDOK,50,53,50,14
312+
PUSHBUTTON "Cancel",IDCANCEL,105,53,50,14
313+
CONTROL "&Pull from remote",IDC_OPTIONS_COMMIT_PULL,"Button",
314+
BS_AUTOCHECKBOX | WS_TABSTOP,7,7,148,10
315+
LTEXT "When this option is checked, changes will be pulled from the repository instead of checking out the selected files from HEAD.",
316+
IDC_STATIC,7,22,148,26
317+
END
318+
306319

307320
/////////////////////////////////////////////////////////////////////////////
308321
//
@@ -486,6 +499,16 @@ BEGIN
486499
TOPMARGIN, 7
487500
BOTTOMMARGIN, 74
488501
END
502+
503+
IDD_OPTIONS_GET, DIALOG
504+
BEGIN
505+
LEFTMARGIN, 7
506+
RIGHTMARGIN, 155
507+
VERTGUIDE, 100
508+
VERTGUIDE, 105
509+
TOPMARGIN, 7
510+
BOTTOMMARGIN, 67
511+
END
489512
END
490513
#endif // APSTUDIO_INVOKED
491514

caps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ SCCEXTERNC SCCRTN EXTFUN __cdecl SccGetExtendedCapabilities (LPVOID pContext,
9797
case SCC_EXCAP_ENUM_CHANGED_FILES:
9898
/* SccEnumChangedFiles */
9999
LGitLog(" SCC_EXCAP_ENUM_CHANGED_FILES\n");
100-
*pbSupported = TRUE;
100+
/* We support this, but the semantics VS wants are hard w/ git. */
101+
*pbSupported = FALSE;
101102
break;
102103
case SCC_EXCAP_POPULATELIST_DIR:
103104
/* SccPopulateDirList */

checkout.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static SCCRTN LGitCheckoutInternal (LPVOID context,
2929
* the latter; the former could be done with adjustments in pathspec?
3030
* (That is, SCC_GET_ALL or SCC_GET_RECURSIVE)
3131
*/
32-
LGitLog(" files %x", dwFlags);
33-
LGitLog(" flags %d", nFiles);
32+
LGitLog(" flags %x", dwFlags);
33+
LGitLog(" files %d", nFiles);
3434

3535
git_checkout_options_init(&co_opts, GIT_CHECKOUT_OPTIONS_VERSION);
3636
LGitInitCheckoutProgressCallback(ctx, &co_opts);
@@ -92,6 +92,29 @@ SCCRTN SccUncheckout (LPVOID context,
9292
return LGitCheckoutInternal(context, hWnd, nFiles, lpFileNames, dwFlags, pvOptions);
9393
}
9494

95+
/**
96+
* Either:
97+
* - Replaces files with those from HEAD.
98+
* - Fetches/pulls. Will prompt and apply to all files.
99+
*/
100+
SCCRTN SccGet (LPVOID context,
101+
HWND hWnd,
102+
LONG nFiles,
103+
LPCSTR* lpFileNames,
104+
LONG dwFlags,
105+
LPCMDOPTS pvOptions)
106+
{
107+
LGitLog("**SccGet** Context=%p\n", context);
108+
LGitLog(" options %p", pvOptions);
109+
LGitGetOpts *getOpts = (LGitGetOpts*)pvOptions;
110+
if (pvOptions != NULL && getOpts->pull) {
111+
LGitContext *ctx = (LGitContext*)context;
112+
return LGitPullDialog(ctx, hWnd);
113+
} else {
114+
return LGitCheckoutInternal(context, hWnd, nFiles, lpFileNames, dwFlags, pvOptions);
115+
}
116+
}
117+
95118
static void LGitUnmarkReadOnly(LPCSTR fileName)
96119
{
97120
DWORD attr;

clone.cpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,12 @@ static void InitCloneView(HWND hwnd, LGitCloneDialogParams* params)
1919
SetDlgItemText(hwnd, IDC_CLONE_PATH, params->path);
2020
}
2121

22-
static int CALLBACK BrowseCallbackProc(HWND hwnd,
23-
UINT uMsg,
24-
LPARAM lParam,
25-
LPARAM lpData)
26-
{
27-
switch (uMsg) {
28-
case BFFM_INITIALIZED:
29-
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
30-
break;
31-
}
32-
return 0;
33-
}
34-
3522
static void BrowseForFolder(HWND hwnd, LGitCloneDialogParams* params)
3623
{
37-
char path[_MAX_PATH];
38-
BROWSEINFO bi;
39-
ZeroMemory(&bi, sizeof(BROWSEINFO));
40-
bi.lpszTitle = "Browse for Repository Folder";
41-
bi.ulFlags = BIF_RETURNONLYFSDIRS
42-
| BIF_RETURNFSANCESTORS
43-
| BIF_EDITBOX
44-
| BIF_NEWDIALOGSTYLE;
45-
/* callback to handle at least initializing the dialog */
46-
bi.lpfn = BrowseCallbackProc;
47-
GetDlgItemText(hwnd, IDC_CLONE_PATH, params->path, MAX_PATH);
48-
bi.lParam = (LPARAM) path;
49-
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
50-
if (pidl == NULL) {
51-
return;
24+
GetDlgItemText(hwnd, IDC_CLONE_PATH, params->path, _MAX_PATH);
25+
if (LGitBrowseForFolder(hwnd, "Browse for Repository Folder", params->path, _MAX_PATH)) {
26+
SetDlgItemText(hwnd, IDC_CLONE_PATH, params->path);
5227
}
53-
SHGetPathFromIDList(pidl, path);
54-
SetDlgItemText(hwnd, IDC_CLONE_PATH, path);
55-
/* for the sake of updating */
56-
strlcpy(params->path, path, _MAX_PATH);
57-
CoTaskMemFree(pidl);
5828
}
5929

6030
static BOOL ValidateAndSetParams(HWND hwnd, LGitCloneDialogParams* params)

cmdopts.cpp

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ static SCCRTN LGitOptionsCaps(enum SCCCOMMAND cmd)
1010
switch (cmd)
1111
{
1212
/*
13-
* We support commit (checkin, add, remove) for remote operations.
13+
* We support commit (checkin, add, remove) and get for remote operations.
1414
*/
15+
case SCC_COMMAND_GET:
1516
case SCC_COMMAND_ADD:
1617
case SCC_COMMAND_REMOVE:
1718
case SCC_COMMAND_CHECKIN:
@@ -34,12 +35,14 @@ static BOOL CALLBACK CommitOptsDialogProc(HWND hwnd,
3435
param = (LGitContext*)lParam;
3536
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
3637
CheckDlgButton(hwnd, IDC_OPTIONS_COMMIT_PUSH, param->commitOpts.push);
38+
LGitLog(" ! Push is %d\n", param->commitOpts.push);
3739
return TRUE;
3840
case WM_COMMAND:
3941
param = (LGitContext*)GetWindowLong(hwnd, GWL_USERDATA);
4042
switch (LOWORD(wParam)) {
4143
case IDOK:
4244
param->commitOpts.push = IsDlgButtonChecked(hwnd, IDC_OPTIONS_COMMIT_PUSH);
45+
LGitLog(" ! Push is now %d\n", param->commitOpts.push);
4346
EndDialog(hwnd, 2);
4447
return TRUE;
4548
case IDCANCEL:
@@ -74,6 +77,60 @@ static SCCRTN SetCommitOptions(LGitContext *ctx, HWND hWnd, LPCMDOPTS *opts)
7477
return SCC_E_NONSPECIFICERROR;
7578
}
7679

80+
static BOOL CALLBACK GetOptsDialogProc(HWND hwnd,
81+
unsigned int iMsg,
82+
WPARAM wParam,
83+
LPARAM lParam)
84+
{
85+
LGitContext *param;
86+
/* TODO: We should try to derive a path from the URL until overriden */
87+
switch (iMsg) {
88+
case WM_INITDIALOG:
89+
param = (LGitContext*)lParam;
90+
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
91+
CheckDlgButton(hwnd, IDC_OPTIONS_COMMIT_PULL, param->getOpts.pull);
92+
LGitLog(" ! Pull is %d\n", param->getOpts.pull);
93+
return TRUE;
94+
case WM_COMMAND:
95+
param = (LGitContext*)GetWindowLong(hwnd, GWL_USERDATA);
96+
switch (LOWORD(wParam)) {
97+
case IDOK:
98+
param->getOpts.pull = IsDlgButtonChecked(hwnd, IDC_OPTIONS_COMMIT_PULL);
99+
LGitLog(" ! Pull is now %d\n", param->getOpts.pull);
100+
EndDialog(hwnd, 2);
101+
return TRUE;
102+
case IDCANCEL:
103+
EndDialog(hwnd, 1);
104+
return TRUE;
105+
}
106+
return FALSE;
107+
default:
108+
return FALSE;
109+
}
110+
}
111+
112+
static SCCRTN SetGetOptions(LGitContext *ctx, HWND hWnd, LPCMDOPTS *opts)
113+
{
114+
if (opts != NULL && *opts == NULL) {
115+
*opts = &ctx->getOpts;
116+
ZeroMemory(&ctx->commitOpts, sizeof(LGitGetOpts));
117+
}
118+
switch (DialogBoxParam(ctx->dllInst,
119+
MAKEINTRESOURCE(IDD_OPTIONS_GET),
120+
hWnd,
121+
GetOptsDialogProc,
122+
(LPARAM)ctx)) {
123+
case 0:
124+
LGitLog(" ! Uh-oh, dialog error\n");
125+
break;
126+
case 1:
127+
return SCC_I_OPERATIONCANCELED;
128+
case 2:
129+
return SCC_OK;
130+
}
131+
return SCC_E_NONSPECIFICERROR;
132+
}
133+
77134
static SCCRTN SetPluginOptions(LGitContext *ctx, HWND hWnd)
78135
{
79136
/* The provided options aren't useful since this is our responsibility. */
@@ -89,6 +146,9 @@ SCCRTN SccGetCommandOptions (LPVOID context,
89146
LGitLog("**SccGetCommandOptions** Context=%p\n", context);
90147
LGitLog(" command %s\n", LGitCommandName(nCommand));
91148
LGitLog(" options %p\n", ppvOptions);
149+
if (ppvOptions != NULL) {
150+
LGitLog(" *options %p\n", *ppvOptions);
151+
}
92152
LGitContext *ctx = (LGitContext*)context;
93153

94154
/* IDE calls first with NULL to see if we support this option */
@@ -98,14 +158,23 @@ SCCRTN SccGetCommandOptions (LPVOID context,
98158
/* Context may not be open. Don't do things needing repos from dialogs. */
99159

100160
/* Dispatch to shared dialogs. */
161+
SCCRTN ret;
101162
switch (nCommand) {;
163+
case SCC_COMMAND_GET:
164+
ret = SetGetOptions(ctx, hWnd, ppvOptions);
165+
break;
102166
case SCC_COMMAND_ADD:
103167
case SCC_COMMAND_REMOVE:
104168
case SCC_COMMAND_CHECKIN:
105-
return SetCommitOptions(ctx, hWnd, ppvOptions);
169+
ret = SetCommitOptions(ctx, hWnd, ppvOptions);
170+
break;
106171
case SCC_COMMAND_OPTIONS:
107-
return SetPluginOptions(ctx, hWnd);
172+
ret = SetPluginOptions(ctx, hWnd);
173+
break;
108174
default:
109-
return SCC_E_OPNOTSUPPORTED;
175+
ret = SCC_E_OPNOTSUPPORTED;
176+
break;
110177
}
178+
LGitLog(" ! New ptr %p rc %d\n", *ppvOptions, ret);
179+
return ret;
111180
}

commit.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ SCCRTN SccCheckin (LPVOID context,
153153
LGitPopCheckout(ctx, path);
154154
}
155155
inner_ret = LGitCommitIndex(hWnd, ctx, index, lpComment);
156-
if (pvOptions != NULL && inner_ret == SCC_OK) {
156+
LGitCommitOpts *commitOpts = (LGitCommitOpts*)pvOptions;
157+
if (pvOptions != NULL && commitOpts->push && inner_ret == SCC_OK) {
157158
inner_ret = LGitPushDialog(ctx, hWnd);
158159
}
159160
git_index_free(index);
@@ -214,7 +215,8 @@ SCCRTN SccAdd (LPVOID context,
214215
LGitPopCheckout(ctx, path);
215216
}
216217
inner_ret = LGitCommitIndex(hWnd, ctx, index, lpComment);
217-
if (pvOptions != NULL && inner_ret == SCC_OK) {
218+
LGitCommitOpts *commitOpts = (LGitCommitOpts*)pvOptions;
219+
if (pvOptions != NULL && commitOpts->push && inner_ret == SCC_OK) {
218220
inner_ret = LGitPushDialog(ctx, hWnd);
219221
}
220222
git_index_free(index);
@@ -267,7 +269,8 @@ SCCRTN SccRemove (LPVOID context,
267269
LGitPopCheckout(ctx, path);
268270
}
269271
inner_ret = LGitCommitIndex(hWnd, ctx, index, lpComment);
270-
if (pvOptions != NULL && inner_ret == SCC_OK) {
272+
LGitCommitOpts *commitOpts = (LGitCommitOpts*)pvOptions;
273+
if (pvOptions != NULL && commitOpts->push && inner_ret == SCC_OK) {
271274
inner_ret = LGitPushDialog(ctx, hWnd);
272275
}
273276
git_index_free(index);

0 commit comments

Comments
 (0)