-
Notifications
You must be signed in to change notification settings - Fork 2
/
history.cpp
executable file
·675 lines (618 loc) · 19.3 KB
/
history.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/*
* History of files.
*/
#include "stdafx.h"
static LVCOLUMNW author_column = {
LVCF_TEXT | LVCF_WIDTH, 0, 175, L"Author"
};
static LVCOLUMNW authored_when_column = {
LVCF_TEXT | LVCF_WIDTH, 0, 125, L"Authored At"
};
static LVCOLUMNW comment_column = {
LVCF_TEXT | LVCF_WIDTH, 0, 200, L"Comment"
};
static LVCOLUMNW oid_column = {
LVCF_TEXT | LVCF_WIDTH, 0, 75, L"Object ID"
};
/*
* All these variables are a pain to carry indiviually, so we pack a pointer
* to this in LPARAM. The DialogBoxParam call is anchored to the source of
* all of this, so they won't expire lifetime-wise past the dialog.
*/
typedef struct _LGitHistoryDialogParams {
LGitContext *ctx;
const char *ref; /* NULL is head */
git_revwalk *walker;
git_pathspec *ps;
git_diff_options *diffopts;
char **paths;
int path_count;
int max_index;
BOOL changed;
BOOL is_head;
/* window sundry */
HMENU menu;
} LGitHistoryDialogParams;
static void InitializeHistoryWindow(HWND hwnd, LGitHistoryDialogParams *params)
{
SetMenu(hwnd, params->menu);
wchar_t title[256], thing[256];
/* XXX: Load string resources */
if (params->path_count == 0 && params->ref == NULL) {
wcslcpy(title, L"Commit History for Repository", 256);
} else if (params->path_count == 0) {
LGitUtf8ToWide(params->ref, thing, 256);
_snwprintf(title, 256, L"Commit History for %s", thing);
} else if (params->path_count == 1) {
LGitUtf8ToWide(params->paths[0], thing, 256);
_snwprintf(title, 256, L"Commit History for %s", thing);
} else {
_snwprintf(title, 256, L"Commit History for %d files", params->path_count);
}
SetWindowTextW(hwnd, title);
}
static void InitializeHistoryListView(HWND hwnd, LGitHistoryDialogParams *param)
{
HWND lv;
lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
/* Unicode even works on 9x with IE5! */
ListView_SetUnicodeFormat(lv, TRUE);
SendMessage(lv, WM_SETFONT, (WPARAM)param->ctx->listviewFont, TRUE);
ListView_SetExtendedListViewStyle(lv, LVS_EX_FULLROWSELECT
| LVS_EX_HEADERDRAGDROP
| LVS_EX_LABELTIP);
/* There is no A/W version of ListView_InsertColumn, it's always TCHAR */
SendMessage(lv, LVM_INSERTCOLUMNW, 0, (LPARAM)&oid_column);
SendMessage(lv, LVM_INSERTCOLUMNW, 1, (LPARAM)&author_column);
SendMessage(lv, LVM_INSERTCOLUMNW, 2, (LPARAM)&authored_when_column);
SendMessage(lv, LVM_INSERTCOLUMNW, 3, (LPARAM)&comment_column);
/*
* XXX: Wonder if maybe callbacks are the way to go:
* https://docs.microsoft.com/en-us/windows/win32/controls/add-list-view-items-and-subitems
*/
}
/** Helper to find how many files in a commit changed from its nth parent. */
static int match_with_parent(HWND hwnd, git_commit *commit, int i, git_diff_options *opts)
{
git_commit *parent;
git_tree *a, *b;
git_diff *diff;
int ndeltas;
if (git_commit_parent(&parent, commit, (size_t)i) != 0) {
LGitLibraryError(hwnd, "match_with_parent git_commit_parent");
return -1;
}
if (git_commit_tree(&a, parent) != 0) {
LGitLibraryError(hwnd, "match_with_parent git_commit_tree A");
git_commit_free(parent);
return -1;
}
if (git_commit_tree(&b, commit) != 0) {
LGitLibraryError(hwnd, "match_with_parent git_commit_tree B");
git_tree_free(a);
git_commit_free(parent);
return -1;
}
if (git_diff_tree_to_tree(&diff, git_commit_owner(commit), a, b, opts) != 0) {
LGitLibraryError(hwnd, "match_with_parent git_diff_tree_to_tree");
git_tree_free(a);
git_tree_free(b);
git_commit_free(parent);
return -1;
}
ndeltas = (int)git_diff_num_deltas(diff);
git_diff_free(diff);
git_tree_free(a);
git_tree_free(b);
git_commit_free(parent);
return ndeltas > 0;
}
static BOOL FillHistoryListView(HWND hwnd,
LGitHistoryDialogParams *param,
BOOL whole_repo)
{
HWND lv;
git_oid oid;
git_commit *commit = NULL;
int parents, i, index;
LGitContext *ctx = param->ctx;
git_revwalk *walker = param->walker;
git_pathspec *ps = param->ps;
git_diff_options *diffopts = param->diffopts;
const char *ref = param->ref;
lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
/* clear if we're replenishing */
ListView_DeleteAllItems(lv);
/* Push HEAD again */
if (ref == NULL && git_revwalk_push_head(walker) != 0) {
LGitLibraryError(hwnd, "History (Pushing Reference)");
return FALSE;
}
if (ref != NULL && git_revwalk_push_ref(walker, ref) != 0) {
LGitLibraryError(hwnd, "History (Pushing Reference)");
return FALSE;
}
/*
* We can only get the revision count by walking it like we're doing now,
* so it's unquantifiable.
*/
LGitProgressInit(param->ctx, "Walking History", 0);
LGitProgressStart(param->ctx, hwnd, FALSE);
for (index = 0; !git_revwalk_next(&oid, walker); git_commit_free(commit)) {
const git_signature *author, *committer;
const char *message;
char *oid_str; /* owned by library statically, do not free */
wchar_t formatted[256];
LVITEMW lvi;
if (LGitProgressCancelled(param->ctx)) {
/* We'll work with what we have. */
break;
}
if (git_commit_lookup(&commit, ctx->repo, &oid) != 0) {
LGitLibraryError(hwnd, "SccHistory git_commit_lookup");
git_commit_free(commit);
return FALSE;
}
parents = (int)git_commit_parentcount(commit);
if (!whole_repo) {
int unmatched = parents;
if (parents == 0) {
git_tree *tree;
if (git_commit_tree(&tree, commit) != 0) {
LGitLibraryError(hwnd, "SccHistory git_commit_tree");
git_commit_free(commit);
return FALSE;
}
if (git_pathspec_match_tree(
NULL, tree, GIT_PATHSPEC_NO_MATCH_ERROR, ps) != 0)
unmatched = 1;
git_tree_free(tree);
} else if (parents == 1) {
unmatched = match_with_parent(hwnd, commit, 0, diffopts) ? 0 : 1;
} else {
for (i = 0; i < parents; ++i) {
if (match_with_parent(hwnd, commit, i, diffopts))
unmatched--;
}
}
if (unmatched > 0)
continue;
}
UINT encoding = LGitGitToWindowsCodepage(git_commit_message_encoding(commit));
/* Actually insert */
oid_str = git_oid_tostr_s(&oid);
author = git_commit_author(commit);
committer = git_commit_committer(commit);
message = git_commit_message(commit);
/* Let's inform the dialog. May spam TextOut tho */
LGitProgressText(param->ctx, oid_str, 1);
ZeroMemory(&lvi, sizeof(LVITEM));
lvi.mask = LVIF_TEXT;
LGitUtf8ToWide(oid_str, formatted, 256);
lvi.pszText = formatted;
lvi.iItem = index++;
lvi.iSubItem = 0;
lvi.iItem = SendMessage(lv, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
if (lvi.iItem == -1) {
LGitLog(" ! ListView_InsertItem failed for %s\n", oid_str);
continue;
}
/* now for the subitems... */
lvi.iSubItem = 1;
LGitFormatSignatureW(author, formatted, 256);
SendMessage(lv, LVM_SETITEMW, 0, (LPARAM)&lvi);
lvi.iSubItem = 2;
LGitTimeToStringW(&author->when, formatted, 256);
SendMessage(lv, LVM_SETITEMW, 0, (LPARAM)&lvi);
lvi.iSubItem = 3;
MultiByteToWideChar(encoding, 0, git_commit_summary(commit), -1, formatted, 256);
SendMessage(lv, LVM_SETITEMW, 0, (LPARAM)&lvi);
}
LGitProgressDeinit(param->ctx);
param->max_index = index;
/* Recalculate after adding because of scroll bars */
ListView_SetColumnWidth(lv, 3, LVSCW_AUTOSIZE_USEHEADER);
return TRUE;
}
static void ShowSelectedCommitDiff(HWND hwnd, LGitHistoryDialogParams *params)
{
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
int selected = ListView_GetNextItem(lv, -1, LVNI_SELECTED);
if (selected == -1) {
return;
}
/* get the OID as a string then convert */
char oid_s[80];
ListView_GetItemText(lv, selected, 0, oid_s, 80);
git_oid oid;
if (git_oid_fromstr(&oid, oid_s) != 0) {
LGitLibraryError(hwnd, "git_oid_fromstr");
return;
}
/* now try to find the parent to make a diff from */
git_commit *commit = NULL;
if (git_commit_lookup(&commit, params->ctx->repo, &oid) != 0) {
LGitLibraryError(hwnd, "git_commit_lookup");
return;
}
/*
* Slightly gross: The normal diff operations shouldn't have the progress
* callbacks, because they'd pop up a lot and disturb internal history
* build operations. Instead, make a copy with the same settings, just
* initialized with the progress callback. This might be pointless since
* such a diff could be fast, or maybe it'd be worth having...
*/
git_diff_options temp_diffopts;
memcpy(&temp_diffopts, params->diffopts, sizeof(git_diff_options));
LGitInitDiffProgressCallback(params->ctx, &temp_diffopts);
LGitCommitToParentDiff(params->ctx, hwnd, commit, &temp_diffopts);
if (commit != NULL) {
git_commit_free(commit);
}
}
static void ShowSelectedCommitInfo(HWND hwnd, LGitHistoryDialogParams *params)
{
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
int selected = ListView_GetNextItem(lv, -1, LVNI_SELECTED);
if (selected == -1) {
return;
}
char oid_s[80];
ListView_GetItemText(lv, selected, 0, oid_s, 80);
git_oid oid;
if (git_oid_fromstr(&oid, oid_s) != 0) {
LGitLibraryError(hwnd, "git_oid_fromstr");
return;
}
git_commit *commit = NULL;
if (git_commit_lookup(&commit, params->ctx->repo, &oid) != 0) {
LGitLibraryError(hwnd, "git_commit_lookup");
return;
}
LGitViewCommitInfo(params->ctx, hwnd, commit, NULL);
}
static void CheckoutSelectedCommit(HWND hwnd, LGitHistoryDialogParams *params)
{
if (MessageBox(hwnd,
"Are you sure you want to check out this commit? It will detach the HEAD.",
"Checkout Commit?",
MB_ICONQUESTION | MB_YESNO) == IDNO) {
return;
}
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
int selected = ListView_GetNextItem(lv, -1, LVNI_SELECTED);
if (selected == -1) {
return;
}
char oid_s[80];
ListView_GetItemText(lv, selected, 0, oid_s, 80);
git_oid oid;
if (git_oid_fromstr(&oid, oid_s) != 0) {
LGitLibraryError(hwnd, "git_oid_fromstr");
return;
}
if (LGitCheckoutTree(params->ctx, hwnd, &oid) == SCC_OK) {
FillHistoryListView(hwnd, params, params->path_count == 0);
}
params->changed = TRUE;
}
static void RevertSelectedCommit(HWND hwnd, LGitHistoryDialogParams *params)
{
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
int selected = ListView_GetNextItem(lv, -1, LVNI_SELECTED);
if (selected == -1) {
return;
}
char oid_s[80];
ListView_GetItemText(lv, selected, 0, oid_s, 80);
git_oid oid;
if (git_oid_fromstr(&oid, oid_s) != 0) {
LGitLibraryError(hwnd, "git_oid_fromstr");
return;
}
if (LGitRevertCommit(params->ctx, hwnd, &oid) == SCC_OK) {
/* History may be mutated */
FillHistoryListView(hwnd, params, params->path_count == 0);
}
params->changed = TRUE;
}
/* This prob shouldn't be shown for the current branch... */
static void CherryPickSelectedCommit(HWND hwnd, LGitHistoryDialogParams *params)
{
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
int selected = ListView_GetNextItem(lv, -1, LVNI_SELECTED);
if (selected == -1) {
return;
}
char oid_s[80];
ListView_GetItemText(lv, selected, 0, oid_s, 80);
git_oid oid;
if (git_oid_fromstr(&oid, oid_s) != 0) {
LGitLibraryError(hwnd, "git_oid_fromstr");
return;
}
if (LGitCherryPickCommit(params->ctx, hwnd, &oid) == SCC_OK) {
/* History may be mutated */
FillHistoryListView(hwnd, params, params->path_count == 0);
}
params->changed = TRUE;
}
static void ResetSelectedCommit(HWND hwnd, LGitHistoryDialogParams *params, BOOL hard)
{
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
if (lv == NULL) {
return;
}
int selected = ListView_GetNextItem(lv, -1, LVNI_SELECTED);
if (selected == -1) {
return;
}
char oid_s[80];
ListView_GetItemText(lv, selected, 0, oid_s, 80);
git_oid oid;
if (git_oid_fromstr(&oid, oid_s) != 0) {
LGitLibraryError(hwnd, "git_oid_fromstr");
return;
}
if (LGitResetToCommit(params->ctx, hwnd, &oid, hard) == SCC_OK) {
/* History may be mutated */
FillHistoryListView(hwnd, params, params->path_count == 0);
}
params->changed = TRUE;
}
static void UpdateHistoryMenu(HWND hwnd, LGitHistoryDialogParams *params)
{
HWND lv = GetDlgItem(hwnd, IDC_COMMITHISTORY);
UINT selected = ListView_GetSelectedCount(lv);
UINT newState = MF_BYCOMMAND
| (selected ? MF_ENABLED : MF_GRAYED);
#define EnableMenuItemIfCommitSelected(id) EnableMenuItem(params->menu,id,newState)
EnableMenuItemIfCommitSelected(ID_HISTORY_COMMIT_DIFF);
EnableMenuItemIfCommitSelected(ID_HISTORY_COMMIT_INFO);
EnableMenuItemIfCommitSelected(ID_HISTORY_COMMIT_CHECKOUT);
EnableMenuItemIfCommitSelected(ID_HISTORY_COMMIT_REVERT);
EnableMenuItemIfCommitSelected(ID_HISTORY_COMMIT_RESET_HARD);
EnableMenuItemIfCommitSelected(ID_HISTORY_COMMIT_CHERRYPICK);
if (params->is_head) {
/* it doesn't make sense to show for the branch you're on */
EnableMenuItem(params->menu, ID_HISTORY_COMMIT_CHERRYPICK, MF_BYCOMMAND | MF_GRAYED);
}
}
static BOOL CALLBACK HistoryDialogProc(HWND hwnd,
unsigned int iMsg,
WPARAM wParam,
LPARAM lParam)
{
LGitHistoryDialogParams *param;
param = (LGitHistoryDialogParams*)GetWindowLong(hwnd, GWL_USERDATA);
switch (iMsg) {
case WM_INITDIALOG:
param = (LGitHistoryDialogParams*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (long)param); /* XXX: 64-bit... */
LGitSetWindowIcon(hwnd, param->ctx->dllInst, MAKEINTRESOURCE(IDI_HISTORY));
InitializeHistoryWindow(hwnd, param);
InitializeHistoryListView(hwnd, param);
if (!FillHistoryListView(hwnd, param, param->path_count == 0)) {
EndDialog(hwnd, 0);
}
LGitControlFillsParentDialog(hwnd, IDC_COMMITHISTORY);
UpdateHistoryMenu(hwnd, param);
return TRUE;
case WM_SIZE:
LGitControlFillsParentDialog(hwnd, IDC_COMMITHISTORY);
return TRUE;
case WM_CONTEXTMENU:
return LGitContextMenuFromSubmenu(hwnd, param->menu, 1, LOWORD(lParam), HIWORD(lParam));
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_HISTORY_COMMIT_DIFF:
ShowSelectedCommitDiff(hwnd, param);
return TRUE;
case ID_HISTORY_COMMIT_INFO:
ShowSelectedCommitInfo(hwnd, param);
return TRUE;
case ID_HISTORY_COMMIT_CHECKOUT:
CheckoutSelectedCommit(hwnd, param);
return TRUE;
case ID_HISTORY_COMMIT_REVERT:
RevertSelectedCommit(hwnd, param);
return TRUE;
case ID_HISTORY_COMMIT_RESET_HARD:
ResetSelectedCommit(hwnd, param, TRUE);
return TRUE;
case ID_HISTORY_COMMIT_CHERRYPICK:
CherryPickSelectedCommit(hwnd, param);
return TRUE;
case ID_HISTORY_REFRESH:
FillHistoryListView(hwnd, param, param->path_count == 0);
return TRUE;
case ID_HISTORY_CLOSE:
case IDOK:
case IDCANCEL:
EndDialog(hwnd, 1);
return TRUE;
}
return FALSE;
case WM_NOTIFY:
switch (wParam) {
case IDC_COMMITHISTORY:
LPNMHDR child_msg = (LPNMHDR)lParam;
switch (child_msg->code) {
case LVN_ITEMACTIVATE:
/* XXX: Could use fields of NMITEMACTIVATE? */
ShowSelectedCommitInfo(hwnd, param);
return TRUE;
case LVN_ITEMCHANGED:
UpdateHistoryMenu(hwnd, param);
return TRUE;
}
}
return FALSE;
default:
return FALSE;
}
}
static SCCRTN LGitHistoryInternal(LGitContext *ctx,
HWND hWnd,
git_strarray *paths,
LONG dwFlags,
LPCMDOPTS pvOptions,
const char *ref)
{
SCCRTN ret = SCC_OK;
git_diff_options diffopts;
git_pathspec *ps = NULL;
git_revwalk *walker = NULL;
LGitHistoryDialogParams params;
ZeroMemory(¶ms, sizeof(LGitHistoryDialogParams));
git_diff_options_init(&diffopts, GIT_DIFF_OPTIONS_VERSION);
if (paths != NULL) {
diffopts.pathspec.strings = paths->strings;
diffopts.pathspec.count = paths->count;
if (paths->count > 0) {
if (git_pathspec_new(&ps, &diffopts.pathspec) != 0) {
LGitLibraryError(hWnd, "SccHistory git_pathspec_new");
ret = SCC_E_NONSPECIFICERROR;
goto fin;
}
}
params.paths = paths->strings;
params.path_count = paths->count;
}
if (git_revwalk_new(&walker, ctx->repo) != 0) {
LGitLibraryError(hWnd, "SccHistory git_revwalk_new");
ret = SCC_E_NONSPECIFICERROR;
goto fin;
}
git_revwalk_sorting(walker, GIT_SORT_TIME);
/* are we using the HEAD? */
if (ref != NULL && strlen(ref) > 0) {
/* it's a branch because only those can be a HEAD */
git_reference *possible_head = NULL;
/* failures here are insignificant */
if (git_reference_lookup(&possible_head, ctx->repo, ref) != 0) {
params.is_head = FALSE;
} else {
params.is_head = git_branch_is_head(possible_head);
git_reference_free(possible_head);
}
} else {
/* default is to use HEAD, so yes */
params.is_head = TRUE;
}
params.ctx = ctx;
params.walker = walker;
params.ps = ps;
params.diffopts = &diffopts;
params.ref = ref;
params.menu = LoadMenu(ctx->dllInst, MAKEINTRESOURCE(IDR_HISTORY_MENU));
switch (DialogBoxParamW(ctx->dllInst,
MAKEINTRESOURCEW(IDD_COMMITHISTORY),
hWnd,
HistoryDialogProc,
(LPARAM)¶ms)) {
case 0:
case -1:
LGitLog(" ! Uh-oh, dialog error\n");
ret = SCC_E_NONSPECIFICERROR;
goto fin;
default:
break;
}
fin:
DestroyMenu(params.menu);
if (ps != NULL) {
git_pathspec_free(ps);
}
if (walker != NULL) {
git_revwalk_free(walker);
}
if (params.changed) {
ret = SCC_I_RELOADFILE;
}
return ret;
}
/*
* Note that this takes a list of files; we only should grab the commits
* relevant for those files.
*/
SCCRTN SccHistory (LPVOID context,
HWND hWnd,
LONG nFiles,
LPCSTR* lpFileNames,
LONG dwFlags,
LPCMDOPTS pvOptions)
{
LGitContext *ctx = (LGitContext*)context;
LGitLog("**SccHistory** Context=%p\n", context);
LGitLog(" files %d\n", nFiles);
LGitLog(" flags %x\n", dwFlags);
git_strarray strings;
ZeroMemory(&strings, sizeof(git_strarray));
if (nFiles > 0) {
char **paths = NULL;
int i, path_count = 0;
paths = (char**)calloc(sizeof(char*), nFiles);
if (paths == NULL) {
return SCC_E_NONSPECIFICERROR;
}
for (i = 0; i < nFiles; i++) {
char *path = LGitAnsiToUtf8Alloc(lpFileNames[i]);
const char *raw_path = LGitStripBasePath(ctx, path);
if (raw_path == NULL) {
LGitLog(" Couldn't get base path for %s\n", path);
free(path);
continue;
}
/* Translate because libgit2 operates with forward slashes */
LGitTranslateStringChars(path, '\\', '/');
LGitLog(" %s\n", raw_path);
paths[path_count++] = (char*)raw_path;
}
strings.strings = paths;
strings.count = path_count;
}
SCCRTN ret = LGitHistoryInternal(ctx, hWnd, &strings, dwFlags, pvOptions, NULL);
if (strings.strings != NULL) {
LGitFreePathList(strings.strings, strings.count);
}
return ret;
}
SCCRTN LGitHistoryForRefByName(LPVOID context,
HWND hWnd,
const char *ref)
{
LGitContext *ctx = (LGitContext*)context;
LGitLog("**LGitHistoryForRefByName** Context=%p\n", context);
LGitLog(" ref %s\n", ref);
return LGitHistoryInternal(ctx, hWnd, NULL, 0, NULL, ref);
}
SCCRTN LGitHistory(LPVOID context,
HWND hWnd,
git_strarray *paths)
{
LGitContext *ctx = (LGitContext*)context;
LGitLog("**LGitHistory** Context=%p\n", context);
if (paths != NULL) {
LGitLog(" path count %d\n", paths->count);
}
return LGitHistoryInternal(ctx, hWnd, paths, 0, NULL, NULL);
}