OSDN Git Service

08b16bca2640ea8ba7849888166cb26914d76715
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SVNProgressDlg.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "messagebox.h"\r
22 #include "SVNProgressDlg.h"\r
23 #include "LogDlg.h"\r
24 #include "TGitPath.h"\r
25 #include "Registry.h"\r
26 #include "GitStatus.h"\r
27 #include "AppUtils.h"\r
28 #include "PathUtils.h"\r
29 #include "StringUtils.h"\r
30 #include "TempFile.h"\r
31 #include "UnicodeUtils.h"\r
32 #include "SoundUtils.h"\r
33 #include "GitDiff.h"\r
34 #include "Hooks.h"\r
35 #include "DropFiles.h"\r
36 //#include "GitLogHelper.h"\r
37 #include "RegHistory.h"\r
38 //#include "ConflictResolveDlg.h"\r
39 #include "LogFile.h"\r
40 #include "ShellUpdater.h"\r
41 #include "IconMenu.h"\r
42 #include "BugTraqAssociations.h"\r
43 #include "patch.h"\r
44 \r
45 static UINT WM_GITPROGRESS = RegisterWindowMessage(_T("TORTOISEGIT_GITPROGRESS_MSG"));\r
46 \r
47 BOOL    CGitProgressDlg::m_bAscending = FALSE;\r
48 int             CGitProgressDlg::m_nSortedColumn = -1;\r
49 \r
50 #define TRANSFERTIMER   100\r
51 #define VISIBLETIMER    101\r
52 \r
53 enum SVNProgressDlgContextMenuCommands\r
54 {\r
55         // needs to start with 1, since 0 is the return value if *nothing* is clicked on in the context menu\r
56         ID_COMPARE = 1,\r
57         ID_EDITCONFLICT,\r
58         ID_CONFLICTRESOLVE,\r
59         ID_CONFLICTUSETHEIRS,\r
60         ID_CONFLICTUSEMINE,\r
61         ID_LOG,\r
62         ID_OPEN,\r
63         ID_OPENWITH,\r
64         ID_EXPLORE,\r
65         ID_COPY\r
66 };\r
67 \r
68 IMPLEMENT_DYNAMIC(CGitProgressDlg, CResizableStandAloneDialog)\r
69 CGitProgressDlg::CGitProgressDlg(CWnd* pParent /*=NULL*/)\r
70         : CResizableStandAloneDialog(CGitProgressDlg::IDD, pParent)\r
71         , m_bCancelled(FALSE)\r
72         , m_pThread(NULL)\r
73 #if 0\r
74         , m_Revision(_T("HEAD"))\r
75         //, m_RevisionEnd(0)\r
76         , m_bLockWarning(false)\r
77         , m_bLockExists(false)\r
78         , m_bThreadRunning(FALSE)\r
79         , m_nConflicts(0)\r
80         , m_bErrorsOccurred(FALSE)\r
81         , m_bMergesAddsDeletesOccurred(FALSE)\r
82         \r
83         , m_options(ProgOptNone)\r
84         , m_dwCloseOnEnd((DWORD)-1)\r
85         , m_bFinishedItemAdded(false)\r
86         , m_bLastVisible(false)\r
87 //      , m_depth(svn_depth_unknown)\r
88         , m_itemCount(-1)\r
89         , m_itemCountTotal(-1)\r
90         , m_AlwaysConflicted(false)\r
91         , m_BugTraqProvider(NULL)\r
92         , sIgnoredIncluded(MAKEINTRESOURCE(IDS_PROGRS_IGNOREDINCLUDED))\r
93         , sExtExcluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSEXCLUDED))\r
94         , sExtIncluded(MAKEINTRESOURCE(IDS_PROGRS_EXTERNALSINCLUDED))\r
95         , sIgnoreAncestry(MAKEINTRESOURCE(IDS_PROGRS_IGNOREANCESTRY))\r
96         , sRespectAncestry(MAKEINTRESOURCE(IDS_PROGRS_RESPECTANCESTRY))\r
97         , sDryRun(MAKEINTRESOURCE(IDS_PROGRS_DRYRUN))\r
98         , sRecordOnly(MAKEINTRESOURCE(IDS_MERGE_RECORDONLY))\r
99 #endif\r
100 {\r
101 }\r
102 \r
103 CGitProgressDlg::~CGitProgressDlg()\r
104 {\r
105         for (size_t i=0; i<m_arData.size(); i++)\r
106         {\r
107                 delete m_arData[i];\r
108         } \r
109         if(m_pThread != NULL)\r
110         {\r
111                 delete m_pThread;\r
112         }\r
113 }\r
114 \r
115 void CGitProgressDlg::DoDataExchange(CDataExchange* pDX)\r
116 {\r
117         CResizableStandAloneDialog::DoDataExchange(pDX);\r
118         DDX_Control(pDX, IDC_SVNPROGRESS, m_ProgList);\r
119 }\r
120 \r
121 BEGIN_MESSAGE_MAP(CGitProgressDlg, CResizableStandAloneDialog)\r
122         ON_BN_CLICKED(IDC_LOGBUTTON, OnBnClickedLogbutton)\r
123         ON_NOTIFY(NM_CUSTOMDRAW, IDC_SVNPROGRESS, OnNMCustomdrawSvnprogress)\r
124         ON_WM_CLOSE()\r
125         ON_NOTIFY(NM_DBLCLK, IDC_SVNPROGRESS, OnNMDblclkSvnprogress)\r
126         ON_NOTIFY(HDN_ITEMCLICK, 0, OnHdnItemclickSvnprogress)\r
127         ON_WM_SETCURSOR()\r
128         ON_WM_CONTEXTMENU()\r
129         ON_REGISTERED_MESSAGE(WM_GITPROGRESS, OnGitProgress)\r
130         ON_WM_TIMER()\r
131         ON_EN_SETFOCUS(IDC_INFOTEXT, &CGitProgressDlg::OnEnSetfocusInfotext)\r
132         ON_NOTIFY(LVN_BEGINDRAG, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnBegindragSvnprogress)\r
133         ON_WM_SIZE()\r
134         ON_NOTIFY(LVN_GETDISPINFO, IDC_SVNPROGRESS, &CGitProgressDlg::OnLvnGetdispinfoSvnprogress)\r
135         ON_BN_CLICKED(IDC_NONINTERACTIVE, &CGitProgressDlg::OnBnClickedNoninteractive)\r
136         ON_MESSAGE(WM_SHOWCONFLICTRESOLVER, OnShowConflictResolver)\r
137 END_MESSAGE_MAP()\r
138 \r
139 BOOL CGitProgressDlg::Cancel()\r
140 {\r
141         return m_bCancelled;\r
142 }\r
143 \r
144 LRESULT CGitProgressDlg::OnShowConflictResolver(WPARAM /*wParam*/, LPARAM lParam)\r
145 {\r
146 #if 0\r
147         CConflictResolveDlg dlg(this);\r
148         const svn_wc_conflict_description_t *description = (svn_wc_conflict_description_t *)lParam;\r
149         if (description)\r
150         {\r
151                 dlg.SetConflictDescription(description);\r
152                 if (dlg.DoModal() == IDOK)\r
153                 {\r
154                         if (dlg.GetResult() == svn_wc_conflict_choose_postpone)\r
155                         {\r
156                                 // if the result is conflicted and the dialog returned IDOK,\r
157                                 // that means we should not ask again in case of a conflict\r
158                                 m_AlwaysConflicted = true;\r
159                                 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);\r
160                         }\r
161                 }\r
162                 m_mergedfile = dlg.GetMergedFile();\r
163                 m_bCancelled = dlg.IsCancelled();\r
164                 return dlg.GetResult();\r
165         }\r
166 \r
167         return svn_wc_conflict_choose_postpone;\r
168 #endif\r
169         return 0;\r
170 }\r
171 #if 0\r
172 svn_wc_conflict_choice_t CGitProgressDlg::ConflictResolveCallback(const svn_wc_conflict_description_t *description, CString& mergedfile)\r
173 {\r
174         // we only bother the user when merging\r
175         if (((m_Command == GitProgress_Merge)||(m_Command == GitProgress_MergeAll)||(m_Command == GitProgress_MergeReintegrate))&&(!m_AlwaysConflicted)&&(description))\r
176         {\r
177                 // we're in a worker thread here. That means we must not show a dialog from the thread\r
178                 // but let the UI thread do it.\r
179                 // To do that, we send a message to the UI thread and let it show the conflict resolver dialog.\r
180                 LRESULT dlgResult = ::SendMessage(GetSafeHwnd(), WM_SHOWCONFLICTRESOLVER, 0, (LPARAM)description);\r
181                 mergedfile = m_mergedfile;\r
182                 return (svn_wc_conflict_choice_t)dlgResult;\r
183         }\r
184 \r
185         return svn_wc_conflict_choose_postpone;\r
186 }\r
187 #endif\r
188 void CGitProgressDlg::AddItemToList()\r
189 {\r
190         int totalcount = m_ProgList.GetItemCount();\r
191 \r
192         m_ProgList.SetItemCountEx(totalcount+1, LVSICF_NOSCROLL|LVSICF_NOINVALIDATEALL);\r
193         // make columns width fit\r
194         if (iFirstResized < 30)\r
195         {\r
196                 // only resize the columns for the first 30 or so entries.\r
197                 // after that, don't resize them anymore because that's an\r
198                 // expensive function call and the columns will be sized\r
199                 // close enough already.\r
200                 ResizeColumns();\r
201                 iFirstResized++;\r
202         }\r
203 \r
204         // Make sure the item is *entirely* visible even if the horizontal\r
205         // scroll bar is visible.\r
206         int count = m_ProgList.GetCountPerPage();\r
207         if (totalcount <= (m_ProgList.GetTopIndex() + count + nEnsureVisibleCount + 2))\r
208         {\r
209                 nEnsureVisibleCount++;\r
210                 m_bLastVisible = true;\r
211         }\r
212         else\r
213         {\r
214                 nEnsureVisibleCount = 0;\r
215                 if (IsIconic() == 0)\r
216                         m_bLastVisible = false;\r
217         }\r
218 }\r
219 \r
220 \r
221 BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action,\r
222                                                          int status ,\r
223                                                          CString *strErr \r
224                                                          /*\r
225                                                          svn_node_kind_t kind, const CString& mime_type, \r
226                                                          svn_wc_notify_state_t content_state, \r
227                                                          svn_wc_notify_state_t prop_state, LONG rev,\r
228                                                          const svn_lock_t * lock, svn_wc_notify_lock_state_t lock_state,\r
229                                                          const CString& changelistname,\r
230                                                          svn_merge_range_t * range,\r
231                                                          svn_error_t * err, apr_pool_t * pool\r
232                                                          */)\r
233 {\r
234         bool bNoNotify = false;\r
235         bool bDoAddData = true;\r
236         NotificationData * data = new NotificationData();\r
237         data->path = path;\r
238         data->action = action;\r
239         data->sPathColumnText=path.GetGitPathString();\r
240         data->bAuxItem = false;\r
241 #if 0\r
242         data->kind = kind;\r
243         data->mime_type = mime_type;\r
244         data->content_state = content_state;\r
245         data->prop_state = prop_state;\r
246         data->rev = rev;\r
247         data->lock_state = lock_state;\r
248         data->changelistname = changelistname;\r
249         if ((lock)&&(lock->owner))\r
250                 data->owner = CUnicodeUtils::GetUnicode(lock->owner);\r
251         data->sPathColumnText = path.GetUIPathString();\r
252         if (!m_basePath.IsEmpty())\r
253                 data->basepath = m_basePath;\r
254         if (range)\r
255                 data->merge_range = *range;\r
256 #endif\r
257         switch (data->action)\r
258         {\r
259         case git_wc_notify_add:\r
260         //case svn_wc_notify_update_add:\r
261         //      if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))\r
262         //      {\r
263         //              data->color = m_Colors.GetColor(CColors::Conflict);\r
264         //              data->bConflictedActionItem = true;\r
265         //              data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);\r
266         //              m_nConflicts++;\r
267         //      }\r
268         //      else\r
269         //      {\r
270         //              m_bMergesAddsDeletesOccurred = true;\r
271                         data->sActionColumnText.LoadString(IDS_SVNACTION_ADD);\r
272                         data->color = m_Colors.GetColor(CColors::Added);\r
273         //      }\r
274                 break;\r
275         case git_wc_notify_sendmail_start:\r
276                 data->bAuxItem = true;\r
277                 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START);\r
278                 data->color = m_Colors.GetColor(CColors::Modified);\r
279                 break;\r
280         \r
281         case git_wc_notify_sendmail_error:\r
282                 data->bAuxItem = true;\r
283                 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR);\r
284                 if(strErr)\r
285                         data->sPathColumnText = *strErr;\r
286                 else\r
287                         data->sPathColumnText.Empty();\r
288                 data->color = m_Colors.GetColor(CColors::Modified);\r
289                 break;\r
290 \r
291         case git_wc_notify_sendmail_done:\r
292                 \r
293                 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE);\r
294                 data->sPathColumnText.Empty();\r
295                 data->color = m_Colors.GetColor(CColors::Modified);\r
296                 break;\r
297 \r
298         case git_wc_notify_sendmail_retry:\r
299                 data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_RETRY);\r
300                 data->sPathColumnText.Empty();\r
301                 data->color = m_Colors.GetColor(CColors::Modified);\r
302                 break;\r
303 \r
304 \r
305         case git_wc_notify_resolved:\r
306                 data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);\r
307                 break;\r
308 \r
309 #if 0\r
310         case svn_wc_notify_commit_added:\r
311                 data->sActionColumnText.LoadString(IDS_SVNACTION_ADDING);\r
312                 data->color = m_Colors.GetColor(CColors::Added);\r
313                 break;\r
314         case svn_wc_notify_copy:\r
315                 data->sActionColumnText.LoadString(IDS_SVNACTION_COPY);\r
316                 break;\r
317         case svn_wc_notify_commit_modified:\r
318                 data->sActionColumnText.LoadString(IDS_SVNACTION_MODIFIED);\r
319                 data->color = m_Colors.GetColor(CColors::Modified);\r
320                 break;\r
321         case svn_wc_notify_delete:\r
322         case svn_wc_notify_update_delete:\r
323                 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETE);\r
324                 m_bMergesAddsDeletesOccurred = true;\r
325                 data->color = m_Colors.GetColor(CColors::Deleted);\r
326                 break;\r
327         case svn_wc_notify_commit_deleted:\r
328                 data->sActionColumnText.LoadString(IDS_SVNACTION_DELETING);\r
329                 data->color = m_Colors.GetColor(CColors::Deleted);\r
330                 break;\r
331         case svn_wc_notify_restore:\r
332                 data->sActionColumnText.LoadString(IDS_SVNACTION_RESTORE);\r
333                 break;\r
334         case svn_wc_notify_revert:\r
335                 data->sActionColumnText.LoadString(IDS_SVNACTION_REVERT);\r
336                 break;\r
337         case svn_wc_notify_update_replace:\r
338         case svn_wc_notify_commit_replaced:\r
339                 data->sActionColumnText.LoadString(IDS_SVNACTION_REPLACED);\r
340                 data->color = m_Colors.GetColor(CColors::Deleted);\r
341                 break;\r
342         case svn_wc_notify_exists:\r
343                 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))\r
344                 {\r
345                         data->color = m_Colors.GetColor(CColors::Conflict);\r
346                         data->bConflictedActionItem = true;\r
347                         m_nConflicts++;\r
348                         data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);\r
349                 }\r
350                 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))\r
351                 {\r
352                         data->color = m_Colors.GetColor(CColors::Merged);\r
353                         m_bMergesAddsDeletesOccurred = true;\r
354                         data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);\r
355                 }\r
356                 else\r
357                         data->sActionColumnText.LoadString(IDS_SVNACTION_EXISTS);\r
358                 break;\r
359         case svn_wc_notify_update_update:\r
360                 // if this is an inoperative dir change, don't show the notification.\r
361                 // an inoperative dir change is when a directory gets updated without\r
362                 // any real change in either text or properties.\r
363                 if ((kind == svn_node_dir)\r
364                         && ((prop_state == svn_wc_notify_state_inapplicable)\r
365                         || (prop_state == svn_wc_notify_state_unknown)\r
366                         || (prop_state == svn_wc_notify_state_unchanged)))\r
367                 {\r
368                         bNoNotify = true;\r
369                         break;\r
370                 }\r
371                 if ((data->content_state == svn_wc_notify_state_conflicted) || (data->prop_state == svn_wc_notify_state_conflicted))\r
372                 {\r
373                         data->color = m_Colors.GetColor(CColors::Conflict);\r
374                         data->bConflictedActionItem = true;\r
375                         m_nConflicts++;\r
376                         data->sActionColumnText.LoadString(IDS_SVNACTION_CONFLICTED);\r
377                 }\r
378                 else if ((data->content_state == svn_wc_notify_state_merged) || (data->prop_state == svn_wc_notify_state_merged))\r
379                 {\r
380                         data->color = m_Colors.GetColor(CColors::Merged);\r
381                         m_bMergesAddsDeletesOccurred = true;\r
382                         data->sActionColumnText.LoadString(IDS_SVNACTION_MERGED);\r
383                 }\r
384                 else if (((data->content_state != svn_wc_notify_state_unchanged)&&(data->content_state != svn_wc_notify_state_unknown)) || \r
385                         ((data->prop_state != svn_wc_notify_state_unchanged)&&(data->prop_state != svn_wc_notify_state_unknown)))\r
386                 {\r
387                         data->sActionColumnText.LoadString(IDS_SVNACTION_UPDATE);\r
388                 }\r
389                 else\r
390                 {\r
391                         bNoNotify = true;\r
392                         break;\r
393                 }\r
394                 if (lock_state == svn_wc_notify_lock_state_unlocked)\r
395                 {\r
396                         CString temp(MAKEINTRESOURCE(IDS_SVNACTION_UNLOCKED));\r
397                         data->sActionColumnText += _T(", ") + temp;\r
398                 }\r
399                 break;\r
400 \r
401         case svn_wc_notify_update_external:\r
402                 // For some reason we build a list of externals...\r
403                 m_ExtStack.AddHead(path.GetUIPathString());\r
404                 data->sActionColumnText.LoadString(IDS_SVNACTION_EXTERNAL);\r
405                 data->bAuxItem = true;\r
406                 break;\r
407 \r
408         case svn_wc_notify_update_completed:\r
409                 {\r
410                         data->sActionColumnText.LoadString(IDS_SVNACTION_COMPLETED);\r
411                         data->bAuxItem = true;\r
412                         bool bEmpty = !!m_ExtStack.IsEmpty();\r
413                         if (!bEmpty)\r
414                                 data->sPathColumnText.Format(IDS_PROGRS_PATHATREV, (LPCTSTR)m_ExtStack.RemoveHead(), rev);\r
415                         else\r
416                                 data->sPathColumnText.Format(IDS_PROGRS_ATREV, rev);\r
417 \r
418                         if ((m_nConflicts>0)&&(bEmpty))\r
419                         {\r
420                                 // We're going to add another aux item - let's shove this current onto the list first\r
421                                 // I don't really like this, but it will do for the moment.\r
422                                 m_arData.push_back(data);\r
423                                 AddItemToList();\r
424 \r
425                                 data = new NotificationData();\r
426                                 data->bAuxItem = true;\r
427                                 data->sActionColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED_WARNING);\r
428                                 data->sPathColumnText.LoadString(IDS_PROGRS_CONFLICTSOCCURED);\r
429                                 data->color = m_Colors.GetColor(CColors::Conflict);\r
430                                 CSoundUtils::PlayTSVNWarning();\r
431                                 // This item will now be added after the switch statement\r
432                         }\r
433                         if (!m_basePath.IsEmpty())\r
434                                 m_FinishedRevMap[m_basePath.GetSVNApiPath(pool)] = rev;\r
435                         m_RevisionEnd = rev;\r
436                         m_bFinishedItemAdded = true;\r
437                 }\r
438                 break;\r
439         case svn_wc_notify_commit_postfix_txdelta:\r
440                 data->sActionColumnText.LoadString(IDS_SVNACTION_POSTFIX);\r
441                 break;\r
442         case svn_wc_notify_failed_revert:\r
443                 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDREVERT);\r
444                 break;\r
445         case svn_wc_notify_status_completed:\r
446         case svn_wc_notify_status_external:\r
447                 data->sActionColumnText.LoadString(IDS_SVNACTION_STATUS);\r
448                 break;\r
449         case svn_wc_notify_skip:\r
450                 if ((content_state == svn_wc_notify_state_missing)||(content_state == svn_wc_notify_state_obstructed)||(content_state == svn_wc_notify_state_conflicted))\r
451                 {\r
452                         data->sActionColumnText.LoadString(IDS_SVNACTION_SKIPMISSING);\r
453 \r
454                         // The color settings dialog describes the red color with\r
455                         // "possible or real conflict / obstructed" which also applies to\r
456                         // skipped targets during a merge. So we just use the same color.\r
457                         data->color = m_Colors.GetColor(CColors::Conflict);\r
458                 }\r
459                 else\r
460                         data->sActionColumnText.LoadString(IDS_SVNACTION_SKIP);\r
461                 break;\r
462         case svn_wc_notify_locked:\r
463                 if ((lock)&&(lock->owner))\r
464                         data->sActionColumnText.Format(IDS_SVNACTION_LOCKEDBY, (LPCTSTR)CUnicodeUtils::GetUnicode(lock->owner));\r
465                 break;\r
466         case svn_wc_notify_unlocked:\r
467                 data->sActionColumnText.LoadString(IDS_SVNACTION_UNLOCKED);\r
468                 break;\r
469         case svn_wc_notify_failed_lock:\r
470                 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDLOCK);\r
471                 m_arData.push_back(data);\r
472                 AddItemToList();\r
473                 ReportError(SVN::GetErrorString(err));\r
474                 bDoAddData = false;\r
475                 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)\r
476                         m_bLockWarning = true;\r
477                 if (err->apr_err == SVN_ERR_FS_PATH_ALREADY_LOCKED)\r
478                         m_bLockExists = true;\r
479                 break;\r
480         case svn_wc_notify_failed_unlock:\r
481                 data->sActionColumnText.LoadString(IDS_SVNACTION_FAILEDUNLOCK);\r
482                 m_arData.push_back(data);\r
483                 AddItemToList();\r
484                 ReportError(SVN::GetErrorString(err));\r
485                 bDoAddData = false;\r
486                 if (err->apr_err == SVN_ERR_FS_OUT_OF_DATE)\r
487                         m_bLockWarning = true;\r
488                 break;\r
489         case svn_wc_notify_changelist_set:\r
490                 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTSET, (LPCTSTR)data->changelistname);\r
491                 break;\r
492         case svn_wc_notify_changelist_clear:\r
493                 data->sActionColumnText.LoadString(IDS_SVNACTION_CHANGELISTCLEAR);\r
494                 break;\r
495         case svn_wc_notify_changelist_moved:\r
496                 data->sActionColumnText.Format(IDS_SVNACTION_CHANGELISTMOVED, (LPCTSTR)data->changelistname);\r
497                 break;\r
498         case svn_wc_notify_foreign_merge_begin:\r
499         case svn_wc_notify_merge_begin:\r
500                 if (range == NULL)\r
501                         data->sActionColumnText.LoadString(IDS_SVNACTION_MERGEBEGINNONE);\r
502                 else if ((data->merge_range.start == data->merge_range.end) || (data->merge_range.start == data->merge_range.end - 1))\r
503                         data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLE, data->merge_range.end);\r
504                 else if (data->merge_range.start - 1 == data->merge_range.end)\r
505                         data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINSINGLEREVERSE, data->merge_range.start);\r
506                 else if (data->merge_range.start < data->merge_range.end)\r
507                         data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLE, data->merge_range.start + 1, data->merge_range.end);\r
508                 else\r
509                         data->sActionColumnText.Format(IDS_SVNACTION_MERGEBEGINMULTIPLEREVERSE, data->merge_range.start, data->merge_range.end + 1);\r
510                 data->bAuxItem = true;\r
511                 break;\r
512 #endif\r
513         default:\r
514                 break;\r
515         } // switch (data->action)\r
516 \r
517         if (bNoNotify)\r
518                 delete data;\r
519         else\r
520         {\r
521                 if (bDoAddData)\r
522                 {\r
523                         m_arData.push_back(data);\r
524                         AddItemToList();\r
525                         if ((!data->bAuxItem) && (m_itemCount > 0))\r
526                         {\r
527                                 m_itemCount--;\r
528 \r
529                                 CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);\r
530                                 progControl->ShowWindow(SW_SHOW);\r
531                                 progControl->SetPos(m_itemCountTotal - m_itemCount);\r
532                                 progControl->SetRange32(0, m_itemCountTotal);\r
533                         }\r
534                 }\r
535                 //if ((action == svn_wc_notify_commit_postfix_txdelta)&&(bSecondResized == FALSE))\r
536                 //{\r
537                 //      ResizeColumns();\r
538                 //      bSecondResized = TRUE;\r
539                 //}\r
540         }\r
541 \r
542         return TRUE;\r
543 }\r
544 \r
545 \r
546 CString CGitProgressDlg::BuildInfoString()\r
547 {\r
548         CString infotext;\r
549 #if 0\r
550         \r
551         CString temp;\r
552         int added = 0;\r
553         int copied = 0;\r
554         int deleted = 0;\r
555         int restored = 0;\r
556         int reverted = 0;\r
557         int resolved = 0;\r
558         int conflicted = 0;\r
559         int updated = 0;\r
560         int merged = 0;\r
561         int modified = 0;\r
562         int skipped = 0;\r
563         int replaced = 0;\r
564 \r
565         for (size_t i=0; i<m_arData.size(); ++i)\r
566         {\r
567                 const NotificationData * dat = m_arData[i];\r
568                 switch (dat->action)\r
569                 {\r
570                 case svn_wc_notify_add:\r
571                 case svn_wc_notify_update_add:\r
572                 case svn_wc_notify_commit_added:\r
573                         if (dat->bConflictedActionItem)\r
574                                 conflicted++;\r
575                         else\r
576                                 added++;\r
577                         break;\r
578                 case svn_wc_notify_copy:\r
579                         copied++;\r
580                         break;\r
581                 case svn_wc_notify_delete:\r
582                 case svn_wc_notify_update_delete:\r
583                 case svn_wc_notify_commit_deleted:\r
584                         deleted++;\r
585                         break;\r
586                 case svn_wc_notify_restore:\r
587                         restored++;\r
588                         break;\r
589                 case svn_wc_notify_revert:\r
590                         reverted++;\r
591                         break;\r
592                 case svn_wc_notify_resolved:\r
593                         resolved++;\r
594                         break;\r
595                 case svn_wc_notify_update_update:\r
596                         if (dat->bConflictedActionItem)\r
597                                 conflicted++;\r
598                         else if ((dat->content_state == svn_wc_notify_state_merged) || (dat->prop_state == svn_wc_notify_state_merged))\r
599                                 merged++;\r
600                         else\r
601                                 updated++;\r
602                         break;\r
603                 case svn_wc_notify_commit_modified:\r
604                         modified++;\r
605                         break;\r
606                 case svn_wc_notify_skip:\r
607                         skipped++;\r
608                         break;\r
609                 case svn_wc_notify_commit_replaced:\r
610                         replaced++;\r
611                         break;\r
612                 }\r
613         }\r
614         if (conflicted)\r
615         {\r
616                 temp.LoadString(IDS_SVNACTION_CONFLICTED);\r
617                 infotext += temp;\r
618                 temp.Format(_T(":%d "), conflicted);\r
619                 infotext += temp;\r
620         }\r
621         if (skipped)\r
622         {\r
623                 temp.LoadString(IDS_SVNACTION_SKIP);\r
624                 infotext += temp;\r
625                 infotext.AppendFormat(_T(":%d "), skipped);\r
626         }\r
627         if (merged)\r
628         {\r
629                 temp.LoadString(IDS_SVNACTION_MERGED);\r
630                 infotext += temp;\r
631                 infotext.AppendFormat(_T(":%d "), merged);\r
632         }\r
633         if (added)\r
634         {\r
635                 temp.LoadString(IDS_SVNACTION_ADD);\r
636                 infotext += temp;\r
637                 infotext.AppendFormat(_T(":%d "), added);\r
638         }\r
639         if (deleted)\r
640         {\r
641                 temp.LoadString(IDS_SVNACTION_DELETE);\r
642                 infotext += temp;\r
643                 infotext.AppendFormat(_T(":%d "), deleted);\r
644         }\r
645         if (modified)\r
646         {\r
647                 temp.LoadString(IDS_SVNACTION_MODIFIED);\r
648                 infotext += temp;\r
649                 infotext.AppendFormat(_T(":%d "), modified);\r
650         }\r
651         if (copied)\r
652         {\r
653                 temp.LoadString(IDS_SVNACTION_COPY);\r
654                 infotext += temp;\r
655                 infotext.AppendFormat(_T(":%d "), copied);\r
656         }\r
657         if (replaced)\r
658         {\r
659                 temp.LoadString(IDS_SVNACTION_REPLACED);\r
660                 infotext += temp;\r
661                 infotext.AppendFormat(_T(":%d "), replaced);\r
662         }\r
663         if (updated)\r
664         {\r
665                 temp.LoadString(IDS_SVNACTION_UPDATE);\r
666                 infotext += temp;\r
667                 infotext.AppendFormat(_T(":%d "), updated);\r
668         }\r
669         if (restored)\r
670         {\r
671                 temp.LoadString(IDS_SVNACTION_RESTORE);\r
672                 infotext += temp;\r
673                 infotext.AppendFormat(_T(":%d "), restored);\r
674         }\r
675         if (reverted)\r
676         {\r
677                 temp.LoadString(IDS_SVNACTION_REVERT);\r
678                 infotext += temp;\r
679                 infotext.AppendFormat(_T(":%d "), reverted);\r
680         }\r
681         if (resolved)\r
682         {\r
683                 temp.LoadString(IDS_SVNACTION_RESOLVE);\r
684                 infotext += temp;\r
685                 infotext.AppendFormat(_T(":%d "), resolved);\r
686         }\r
687 #endif\r
688         return infotext;\r
689 }\r
690 \r
691 void CGitProgressDlg::SetSelectedList(const CTGitPathList& selPaths)\r
692 {\r
693         m_selectedPaths = selPaths;\r
694 }\r
695 \r
696 void CGitProgressDlg::ResizeColumns()\r
697 {\r
698         m_ProgList.SetRedraw(FALSE);\r
699 \r
700         TCHAR textbuf[MAX_PATH];\r
701 \r
702         int maxcol = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;\r
703         for (int col = 0; col <= maxcol; col++)\r
704         {\r
705                 // find the longest width of all items\r
706                 int count = m_ProgList.GetItemCount();\r
707                 HDITEM hdi = {0};\r
708                 hdi.mask = HDI_TEXT;\r
709                 hdi.pszText = textbuf;\r
710                 hdi.cchTextMax = sizeof(textbuf);\r
711                 ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItem(col, &hdi);\r
712                 int cx = m_ProgList.GetStringWidth(hdi.pszText)+20; // 20 pixels for col separator and margin\r
713 \r
714                 for (int index = 0; index<count; ++index)\r
715                 {\r
716                         // get the width of the string and add 12 pixels for the column separator and margins\r
717                         int linewidth = cx;\r
718                         switch (col)\r
719                         {\r
720                         case 0:\r
721                                 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sActionColumnText) + 12;\r
722                                 break;\r
723                         case 1:\r
724                                 linewidth = m_ProgList.GetStringWidth(m_arData[index]->sPathColumnText) + 12;\r
725                                 break;\r
726                         case 2:\r
727                                 linewidth = m_ProgList.GetStringWidth(m_arData[index]->mime_type) + 12;\r
728                                 break;\r
729                         }\r
730                         if (cx < linewidth)\r
731                                 cx = linewidth;\r
732                 }\r
733                 m_ProgList.SetColumnWidth(col, cx);\r
734         }\r
735 \r
736         m_ProgList.SetRedraw(TRUE);     \r
737 }\r
738 \r
739 BOOL CGitProgressDlg::OnInitDialog()\r
740 {\r
741         __super::OnInitDialog();\r
742 \r
743         m_ProgList.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);\r
744 \r
745         m_ProgList.DeleteAllItems();\r
746         int c = ((CHeaderCtrl*)(m_ProgList.GetDlgItem(0)))->GetItemCount()-1;\r
747         while (c>=0)\r
748                 m_ProgList.DeleteColumn(c--);\r
749         CString temp;\r
750         temp.LoadString(IDS_PROGRS_ACTION);\r
751         m_ProgList.InsertColumn(0, temp);\r
752         temp.LoadString(IDS_PROGRS_PATH);\r
753         m_ProgList.InsertColumn(1, temp);\r
754         temp.LoadString(IDS_PROGRS_MIMETYPE);\r
755         m_ProgList.InsertColumn(2, temp);\r
756 \r
757         m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);\r
758         if (m_pThread==NULL)\r
759         {\r
760                 ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));\r
761         }\r
762         else\r
763         {\r
764                 m_pThread->m_bAutoDelete = FALSE;\r
765                 m_pThread->ResumeThread();\r
766         }\r
767 \r
768         UpdateData(FALSE);\r
769 \r
770         // Call this early so that the column headings aren't hidden before any\r
771         // text gets added.\r
772         ResizeColumns();\r
773 \r
774         SetTimer(VISIBLETIMER, 300, NULL);\r
775 \r
776         AddAnchor(IDC_SVNPROGRESS, TOP_LEFT, BOTTOM_RIGHT);\r
777         AddAnchor(IDC_PROGRESSLABEL, BOTTOM_LEFT, BOTTOM_CENTER);\r
778         AddAnchor(IDC_PROGRESSBAR, BOTTOM_CENTER, BOTTOM_RIGHT);\r
779         AddAnchor(IDC_INFOTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);\r
780         AddAnchor(IDC_NONINTERACTIVE, BOTTOM_LEFT, BOTTOM_RIGHT);\r
781         AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
782         AddAnchor(IDOK, BOTTOM_RIGHT);\r
783         AddAnchor(IDC_LOGBUTTON, BOTTOM_RIGHT);\r
784         //SetPromptParentWindow(this->m_hWnd);\r
785         if (hWndExplorer)\r
786                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
787         EnableSaveRestore(_T("SVNProgressDlg"));\r
788         return TRUE;\r
789 }\r
790 \r
791 bool CGitProgressDlg::SetBackgroundImage(UINT nID)\r
792 {\r
793         return CAppUtils::SetListCtrlBackgroundImage(m_ProgList.GetSafeHwnd(), nID);\r
794 }\r
795 \r
796 #if 0\r
797 void CGitProgressDlg::ReportSVNError()\r
798 {\r
799         ReportError(GetLastErrorMessage());\r
800 }\r
801 #endif\r
802 \r
803 void CGitProgressDlg::ReportError(const CString& sError)\r
804 {\r
805         CSoundUtils::PlayTGitError();\r
806         ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict));\r
807         m_bErrorsOccurred = true;\r
808 }\r
809 \r
810 void CGitProgressDlg::ReportWarning(const CString& sWarning)\r
811 {\r
812         CSoundUtils::PlayTGitWarning();\r
813         ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict));\r
814 }\r
815 \r
816 void CGitProgressDlg::ReportNotification(const CString& sNotification)\r
817 {\r
818         CSoundUtils::PlayTGitNotification();\r
819         ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));\r
820 }\r
821 \r
822 void CGitProgressDlg::ReportCmd(const CString& sCmd)\r
823 {\r
824         ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd));\r
825 }\r
826 \r
827 void CGitProgressDlg::ReportString(CString sMessage, const CString& sMsgKind, COLORREF color)\r
828 {\r
829         // instead of showing a dialog box with the error message or notification,\r
830         // just insert the error text into the list control.\r
831         // that way the user isn't 'interrupted' by a dialog box popping up!\r
832 \r
833         // the message may be split up into different lines\r
834         // so add a new entry for each line of the message\r
835         while (!sMessage.IsEmpty())\r
836         {\r
837                 NotificationData * data = new NotificationData();\r
838                 data->bAuxItem = true;\r
839                 data->sActionColumnText = sMsgKind;\r
840                 if (sMessage.Find('\n')>=0)\r
841                         data->sPathColumnText = sMessage.Left(sMessage.Find('\n'));\r
842                 else\r
843                         data->sPathColumnText = sMessage;               \r
844                 data->sPathColumnText.Trim(_T("\n\r"));\r
845                 data->color = color;\r
846                 if (sMessage.Find('\n')>=0)\r
847                 {\r
848                         sMessage = sMessage.Mid(sMessage.Find('\n'));\r
849                         sMessage.Trim(_T("\n\r"));\r
850                 }\r
851                 else\r
852                         sMessage.Empty();\r
853                 m_arData.push_back(data);\r
854                 AddItemToList();\r
855         }\r
856 }\r
857 \r
858 UINT CGitProgressDlg::ProgressThreadEntry(LPVOID pVoid)\r
859 {\r
860         return ((CGitProgressDlg*)pVoid)->ProgressThread();\r
861 }\r
862 \r
863 UINT CGitProgressDlg::ProgressThread()\r
864 {\r
865         // The SetParams function should have loaded something for us\r
866 \r
867         CString temp;\r
868         CString sWindowTitle;\r
869         bool localoperation = false;\r
870         bool bSuccess = false;\r
871         m_AlwaysConflicted = false;\r
872 \r
873         DialogEnableWindow(IDOK, FALSE);\r
874         DialogEnableWindow(IDCANCEL, TRUE);\r
875 //      SetAndClearProgressInfo(m_hWnd);\r
876         m_itemCount = m_itemCountTotal;\r
877 \r
878         InterlockedExchange(&m_bThreadRunning, TRUE);\r
879         iFirstResized = 0;\r
880         bSecondResized = FALSE;\r
881         m_bFinishedItemAdded = false;\r
882         CTime startTime = CTime::GetCurrentTime();\r
883         switch (m_Command)\r
884         {\r
885         case GitProgress_Add:\r
886                 bSuccess = CmdAdd(sWindowTitle, localoperation);\r
887                 break;\r
888         case GitProgress_Checkout:\r
889                 bSuccess = CmdCheckout(sWindowTitle, localoperation);\r
890                 break;\r
891         case GitProgress_Commit:\r
892                 bSuccess = CmdCommit(sWindowTitle, localoperation);\r
893                 break;\r
894         case GitProgress_Copy:\r
895                 bSuccess = CmdCopy(sWindowTitle, localoperation);\r
896                 break;\r
897         case GitProgress_Export:\r
898                 bSuccess = CmdExport(sWindowTitle, localoperation);\r
899                 break;\r
900         case GitProgress_Import:\r
901                 bSuccess = CmdImport(sWindowTitle, localoperation);\r
902                 break;\r
903         case GitProgress_Lock:\r
904                 bSuccess = CmdLock(sWindowTitle, localoperation);\r
905                 break;\r
906         case GitProgress_Merge:\r
907                 bSuccess = CmdMerge(sWindowTitle, localoperation);\r
908                 break;\r
909         case GitProgress_MergeAll:\r
910                 bSuccess = CmdMergeAll(sWindowTitle, localoperation);\r
911                 break;\r
912         case GitProgress_MergeReintegrate:\r
913                 bSuccess = CmdMergeReintegrate(sWindowTitle, localoperation);\r
914                 break;\r
915         case GitProgress_Rename:\r
916                 bSuccess = CmdRename(sWindowTitle, localoperation);\r
917                 break;\r
918         case GitProgress_Resolve:\r
919                 bSuccess = CmdResolve(sWindowTitle, localoperation);\r
920                 break;\r
921         case GitProgress_Revert:\r
922                 bSuccess = CmdRevert(sWindowTitle, localoperation);\r
923                 break;\r
924         case GitProgress_Switch:\r
925                 bSuccess = CmdSwitch(sWindowTitle, localoperation);\r
926                 break;\r
927         case GitProgress_Unlock:\r
928                 bSuccess = CmdUnlock(sWindowTitle, localoperation);\r
929                 break;\r
930         case GitProgress_Update:\r
931                 bSuccess = CmdUpdate(sWindowTitle, localoperation);\r
932                 break;\r
933         case GitProgress_SendMail:\r
934                 bSuccess = CmdSendMail(sWindowTitle, localoperation);\r
935                 break;\r
936         }\r
937         if (!bSuccess)\r
938                 temp.LoadString(IDS_PROGRS_TITLEFAILED);\r
939         else\r
940                 temp.LoadString(IDS_PROGRS_TITLEFIN);\r
941         sWindowTitle = sWindowTitle + _T(" ") + temp;\r
942         SetWindowText(sWindowTitle);\r
943 \r
944         KillTimer(TRANSFERTIMER);\r
945         KillTimer(VISIBLETIMER);\r
946 \r
947         DialogEnableWindow(IDCANCEL, FALSE);\r
948         DialogEnableWindow(IDOK, TRUE);\r
949 \r
950         CString info = BuildInfoString();\r
951         if (!bSuccess)\r
952                 info.LoadString(IDS_PROGRS_INFOFAILED);\r
953         SetDlgItemText(IDC_INFOTEXT, info);\r
954         ResizeColumns();\r
955         SendMessage(DM_SETDEFID, IDOK);\r
956         GetDlgItem(IDOK)->SetFocus();   \r
957 \r
958         CString sFinalInfo;\r
959         if (!m_sTotalBytesTransferred.IsEmpty())\r
960         {\r
961                 CTimeSpan time = CTime::GetCurrentTime() - startTime;\r
962                 temp.Format(IDS_PROGRS_TIME, (LONG)time.GetTotalMinutes(), (LONG)time.GetSeconds());\r
963                 sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp);\r
964                 SetDlgItemText(IDC_PROGRESSLABEL, sFinalInfo);\r
965         }\r
966         else\r
967                 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_HIDE);\r
968 \r
969         GetDlgItem(IDC_PROGRESSBAR)->ShowWindow(SW_HIDE);\r
970 \r
971         if (!m_bFinishedItemAdded)\r
972         {\r
973                 // there's no "finished: xxx" line at the end. We add one here to make\r
974                 // sure the user sees that the command is actually finished.\r
975                 NotificationData * data = new NotificationData();\r
976                 data->bAuxItem = true;\r
977                 data->sActionColumnText.LoadString(IDS_PROGRS_FINISHED);\r
978                 m_arData.push_back(data);\r
979                 AddItemToList();\r
980         }\r
981 \r
982         int count = m_ProgList.GetItemCount();\r
983         if ((count > 0)&&(m_bLastVisible))\r
984                 m_ProgList.EnsureVisible(count-1, FALSE);\r
985 \r
986         CLogFile logfile;\r
987         if (logfile.Open())\r
988         {\r
989                 logfile.AddTimeLine();\r
990                 for (size_t i=0; i<m_arData.size(); i++)\r
991                 {\r
992                         NotificationData * data = m_arData[i];\r
993                         temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText);\r
994                         logfile.AddLine(temp);\r
995                 }\r
996                 if (!sFinalInfo.IsEmpty())\r
997                         logfile.AddLine(sFinalInfo);\r
998                 logfile.Close();\r
999         }\r
1000 \r
1001         m_bCancelled = TRUE;\r
1002         InterlockedExchange(&m_bThreadRunning, FALSE);\r
1003         RefreshCursor();\r
1004 \r
1005         DWORD dwAutoClose = CRegStdWORD(_T("Software\\TortoiseGit\\AutoClose"));\r
1006         if (m_options & ProgOptDryRun)\r
1007                 dwAutoClose = 0;                // dry run means progress dialog doesn't auto close at all\r
1008         if (!m_bLastVisible)\r
1009                 dwAutoClose = 0;\r
1010         if (m_dwCloseOnEnd != (DWORD)-1)\r
1011                 dwAutoClose = m_dwCloseOnEnd;           // command line value has priority over setting value\r
1012         if ((dwAutoClose == CLOSE_NOERRORS)&&(!m_bErrorsOccurred))\r
1013                 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);\r
1014         if ((dwAutoClose == CLOSE_NOCONFLICTS)&&(!m_bErrorsOccurred)&&(m_nConflicts==0))\r
1015                 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);\r
1016         if ((dwAutoClose == CLOSE_NOMERGES)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(!m_bMergesAddsDeletesOccurred))\r
1017                 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);\r
1018         if ((dwAutoClose == CLOSE_LOCAL)&&(!m_bErrorsOccurred)&&(m_nConflicts==0)&&(localoperation))\r
1019                 PostMessage(WM_COMMAND, 1, (LPARAM)GetDlgItem(IDOK)->m_hWnd);\r
1020 \r
1021         //Don't do anything here which might cause messages to be sent to the window\r
1022         //The window thread is probably now blocked in OnOK if we've done an auto close\r
1023         return 0;\r
1024 }\r
1025 \r
1026 void CGitProgressDlg::OnBnClickedLogbutton()\r
1027 {\r
1028 #if 0\r
1029         if (m_targetPathList.GetCount() != 1)\r
1030                 return;\r
1031         StringRevMap::iterator it = m_UpdateStartRevMap.begin();\r
1032         svn_revnum_t rev = -1;\r
1033         if (it != m_UpdateStartRevMap.end())\r
1034         {\r
1035                 rev = it->second;\r
1036         }\r
1037         CLogDlg dlg;\r
1038         dlg.SetParams(m_targetPathList[0], m_RevisionEnd, m_RevisionEnd, rev, 0, TRUE);\r
1039         dlg.DoModal();\r
1040 #endif\r
1041 }\r
1042 \r
1043 \r
1044 void CGitProgressDlg::OnClose()\r
1045 {\r
1046         if (m_bCancelled)\r
1047         {\r
1048                 TerminateThread(m_pThread->m_hThread, (DWORD)-1);\r
1049                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1050         }\r
1051         else\r
1052         {\r
1053                 m_bCancelled = TRUE;\r
1054                 return;\r
1055         }\r
1056         DialogEnableWindow(IDCANCEL, TRUE);\r
1057         __super::OnClose();\r
1058 }\r
1059 \r
1060 void CGitProgressDlg::OnOK()\r
1061 {\r
1062         if ((m_bCancelled)&&(!m_bThreadRunning))\r
1063         {\r
1064                 // I have made this wait a sensible amount of time (10 seconds) for the thread to finish\r
1065                 // You must be careful in the thread that after posting the WM_COMMAND/IDOK message, you \r
1066                 // don't do any more operations on the window which might require message passing\r
1067                 // If you try to send windows messages once we're waiting here, then the thread can't finished\r
1068                 // because the Window's message loop is blocked at this wait\r
1069                 WaitForSingleObject(m_pThread->m_hThread, 10000);\r
1070                 __super::OnOK();\r
1071         }\r
1072         m_bCancelled = TRUE;\r
1073 }\r
1074 \r
1075 void CGitProgressDlg::OnCancel()\r
1076 {\r
1077         if ((m_bCancelled)&&(!m_bThreadRunning))\r
1078                 __super::OnCancel();\r
1079         m_bCancelled = TRUE;\r
1080 }\r
1081 \r
1082 void CGitProgressDlg::OnLvnGetdispinfoSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)\r
1083 {\r
1084         NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);\r
1085 \r
1086         if (pDispInfo)\r
1087         {\r
1088                 if (pDispInfo->item.mask & LVIF_TEXT)\r
1089                 {\r
1090                         if (pDispInfo->item.iItem < (int)m_arData.size())\r
1091                         {\r
1092                                 const NotificationData * data = m_arData[pDispInfo->item.iItem];\r
1093                                 switch (pDispInfo->item.iSubItem)\r
1094                                 {\r
1095                                 case 0:\r
1096                                         lstrcpyn(m_columnbuf, data->sActionColumnText, MAX_PATH);\r
1097                                         break;\r
1098                                 case 1:\r
1099                                         lstrcpyn(m_columnbuf, data->sPathColumnText, pDispInfo->item.cchTextMax);\r
1100                                         if (!data->bAuxItem)\r
1101                                         {\r
1102                                                 int cWidth = m_ProgList.GetColumnWidth(1);\r
1103                                                 cWidth = max(12, cWidth-12);\r
1104                                                 CDC * pDC = m_ProgList.GetDC();\r
1105                         if (pDC != NULL)\r
1106                         {\r
1107                                                     CFont * pFont = pDC->SelectObject(m_ProgList.GetFont());\r
1108                                                     PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth);\r
1109                                                     pDC->SelectObject(pFont);\r
1110                                                         ReleaseDC(pDC);\r
1111                         }\r
1112                                         }\r
1113                                         break;\r
1114                                 case 2:\r
1115                                         lstrcpyn(m_columnbuf, data->mime_type, MAX_PATH);\r
1116                                         break;\r
1117                                 default:\r
1118                                         m_columnbuf[0] = 0;\r
1119                                 }\r
1120                                 pDispInfo->item.pszText = m_columnbuf;\r
1121                         }\r
1122                 }\r
1123         }\r
1124         *pResult = 0;\r
1125 }\r
1126 \r
1127 void CGitProgressDlg::OnNMCustomdrawSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)\r
1128 {\r
1129         NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );\r
1130 \r
1131         // Take the default processing unless we set this to something else below.\r
1132         *pResult = CDRF_DODEFAULT;\r
1133 \r
1134         // First thing - check the draw stage. If it's the control's prepaint\r
1135         // stage, then tell Windows we want messages for every item.\r
1136 \r
1137         if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )\r
1138         {\r
1139                 *pResult = CDRF_NOTIFYITEMDRAW;\r
1140         }\r
1141         else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )\r
1142         {\r
1143                 // This is the prepaint stage for an item. Here's where we set the\r
1144                 // item's text color. Our return value will tell Windows to draw the\r
1145                 // item itself, but it will use the new color we set here.\r
1146 \r
1147                 // Tell Windows to paint the control itself.\r
1148                 *pResult = CDRF_DODEFAULT;\r
1149 \r
1150                 ASSERT(pLVCD->nmcd.dwItemSpec <  m_arData.size());\r
1151                 if(pLVCD->nmcd.dwItemSpec >= m_arData.size())\r
1152                 {\r
1153                         return;\r
1154                 }\r
1155                 const NotificationData * data = m_arData[pLVCD->nmcd.dwItemSpec];\r
1156                 ASSERT(data != NULL);\r
1157                 if (data == NULL)\r
1158                         return;\r
1159 \r
1160                 // Store the color back in the NMLVCUSTOMDRAW struct.\r
1161                 pLVCD->clrText = data->color;\r
1162         }\r
1163 }\r
1164 \r
1165 void CGitProgressDlg::OnNMDblclkSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)\r
1166 {\r
1167 #if 0\r
1168         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
1169         *pResult = 0;\r
1170         if (pNMLV->iItem < 0)\r
1171                 return;\r
1172         if (m_options & ProgOptDryRun)\r
1173                 return; //don't do anything in a dry-run.\r
1174 \r
1175         const NotificationData * data = m_arData[pNMLV->iItem];\r
1176         if (data == NULL)\r
1177                 return;\r
1178 \r
1179         if (data->bConflictedActionItem)\r
1180         {\r
1181                 // We've double-clicked on a conflicted item - do a three-way merge on it\r
1182                 SVNDiff::StartConflictEditor(data->path);\r
1183         }\r
1184         else if ((data->action == svn_wc_notify_update_update) && ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)) || (data->action == svn_wc_notify_resolved))\r
1185         {\r
1186                 // This is a modified file which has been merged on update. Diff it against base\r
1187                 CTGitPath temporaryFile;\r
1188                 SVNDiff diff(this, this->m_hWnd, true);\r
1189                 diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000));\r
1190                 svn_revnum_t baseRev = 0;\r
1191                 diff.DiffFileAgainstBase(data->path, baseRev);\r
1192         }\r
1193         else if ((!data->bAuxItem)&&(data->path.Exists())&&(!data->path.IsDirectory()))\r
1194         {\r
1195                 bool bOpenWith = false;\r
1196                 int ret = (int)ShellExecute(m_hWnd, NULL, data->path.GetWinPath(), NULL, NULL, SW_SHOWNORMAL);\r
1197                 if (ret <= HINSTANCE_ERROR)\r
1198                         bOpenWith = true;\r
1199                 if (bOpenWith)\r
1200                 {\r
1201                         CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");\r
1202                         cmd += data->path.GetWinPathString() + _T(" ");\r
1203                         CAppUtils::LaunchApplication(cmd, NULL, false);\r
1204                 }\r
1205         }\r
1206 #endif\r
1207 }\r
1208 \r
1209 void CGitProgressDlg::OnHdnItemclickSvnprogress(NMHDR *pNMHDR, LRESULT *pResult)\r
1210 {\r
1211         LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);\r
1212         if (m_bThreadRunning)\r
1213                 return;\r
1214         if (m_nSortedColumn == phdr->iItem)\r
1215                 m_bAscending = !m_bAscending;\r
1216         else\r
1217                 m_bAscending = TRUE;\r
1218         m_nSortedColumn = phdr->iItem;\r
1219         Sort();\r
1220 \r
1221         CString temp;\r
1222         m_ProgList.SetRedraw(FALSE);\r
1223         m_ProgList.DeleteAllItems();\r
1224         m_ProgList.SetItemCountEx (static_cast<int>(m_arData.size()));\r
1225 \r
1226         m_ProgList.SetRedraw(TRUE);\r
1227 \r
1228         *pResult = 0;\r
1229 }\r
1230 \r
1231 bool CGitProgressDlg::NotificationDataIsAux(const NotificationData* pData)\r
1232 {\r
1233         return pData->bAuxItem;\r
1234 }\r
1235 \r
1236 LRESULT CGitProgressDlg::OnGitProgress(WPARAM /*wParam*/, LPARAM lParam)\r
1237 {\r
1238 #if 0\r
1239         SVNProgress * pProgressData = (SVNProgress *)lParam;\r
1240         CProgressCtrl * progControl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESSBAR);\r
1241         if ((pProgressData->total > 1000)&&(!progControl->IsWindowVisible()))\r
1242         {\r
1243                 progControl->ShowWindow(SW_SHOW);\r
1244         }\r
1245         if (((pProgressData->total < 0)&&(pProgressData->progress > 1000)&&(progControl->IsWindowVisible()))&&(m_itemCountTotal<0))\r
1246         {\r
1247                 progControl->ShowWindow(SW_HIDE);\r
1248         }\r
1249         if (!GetDlgItem(IDC_PROGRESSLABEL)->IsWindowVisible())\r
1250                 GetDlgItem(IDC_PROGRESSLABEL)->ShowWindow(SW_SHOW);\r
1251         SetTimer(TRANSFERTIMER, 2000, NULL);\r
1252         if ((pProgressData->total > 0)&&(pProgressData->progress > 1000))\r
1253         {\r
1254                 progControl->SetPos((int)pProgressData->progress);\r
1255                 progControl->SetRange32(0, (int)pProgressData->total);\r
1256         }\r
1257         CString progText;\r
1258         if (pProgressData->overall_total < 1024)\r
1259                 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALBYTESTRANSFERRED, pProgressData->overall_total);  \r
1260         else if (pProgressData->overall_total < 1200000)\r
1261                 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALTRANSFERRED, pProgressData->overall_total / 1024);\r
1262         else\r
1263                 m_sTotalBytesTransferred.Format(IDS_SVN_PROGRESS_TOTALMBTRANSFERRED, (double)((double)pProgressData->overall_total / 1024000.0));\r
1264         progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)pProgressData->SpeedString);\r
1265         SetDlgItemText(IDC_PROGRESSLABEL, progText);\r
1266 #endif\r
1267         return 0;\r
1268 }\r
1269 \r
1270 void CGitProgressDlg::OnTimer(UINT_PTR nIDEvent)\r
1271 {\r
1272         if (nIDEvent == TRANSFERTIMER)\r
1273         {\r
1274                 CString progText;\r
1275                 CString progSpeed;\r
1276                 progSpeed.Format(IDS_SVN_PROGRESS_BYTES_SEC, 0);\r
1277                 progText.Format(IDS_SVN_PROGRESS_TOTALANDSPEED, (LPCTSTR)m_sTotalBytesTransferred, (LPCTSTR)progSpeed);\r
1278                 SetDlgItemText(IDC_PROGRESSLABEL, progText);\r
1279                 KillTimer(TRANSFERTIMER);\r
1280         }\r
1281         if (nIDEvent == VISIBLETIMER)\r
1282         {\r
1283                 if (nEnsureVisibleCount)\r
1284                         m_ProgList.EnsureVisible(m_ProgList.GetItemCount()-1, false);\r
1285                 nEnsureVisibleCount = 0;\r
1286         }\r
1287 }\r
1288 \r
1289 void CGitProgressDlg::Sort()\r
1290 {\r
1291         if(m_arData.size() < 2)\r
1292         {\r
1293                 return;\r
1294         }\r
1295 \r
1296         // We need to sort the blocks which lie between the auxiliary entries\r
1297         // This is so that any aux data stays where it was\r
1298         NotificationDataVect::iterator actionBlockBegin;\r
1299         NotificationDataVect::iterator actionBlockEnd = m_arData.begin();       // We start searching from here\r
1300 \r
1301         for(;;)\r
1302         {\r
1303                 // Search to the start of the non-aux entry in the next block\r
1304                 actionBlockBegin = std::find_if(actionBlockEnd, m_arData.end(), std::not1(std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux)));\r
1305                 if(actionBlockBegin == m_arData.end())\r
1306                 {\r
1307                         // There are no more actions\r
1308                         break;\r
1309                 }\r
1310                 // Now search to find the end of the block\r
1311                 actionBlockEnd = std::find_if(actionBlockBegin+1, m_arData.end(), std::ptr_fun(&CGitProgressDlg::NotificationDataIsAux));\r
1312                 // Now sort the block\r
1313                 std::sort(actionBlockBegin, actionBlockEnd, &CGitProgressDlg::SortCompare);\r
1314         }\r
1315 }\r
1316 \r
1317 bool CGitProgressDlg::SortCompare(const NotificationData * pData1, const NotificationData * pData2)\r
1318 {\r
1319         int result = 0;\r
1320         switch (m_nSortedColumn)\r
1321         {\r
1322         case 0:         //action column\r
1323                 result = pData1->sActionColumnText.Compare(pData2->sActionColumnText);\r
1324                 break;\r
1325         case 1:         //path column\r
1326                 // Compare happens after switch()\r
1327                 break;\r
1328         case 2:         //mime-type column\r
1329                 result = pData1->mime_type.Compare(pData2->mime_type);\r
1330                 break;\r
1331         default:\r
1332                 break;\r
1333         }\r
1334 \r
1335         // Sort by path if everything else is equal\r
1336         if (result == 0)\r
1337         {\r
1338                 result = CTGitPath::Compare(pData1->path, pData2->path);\r
1339         }\r
1340 \r
1341         if (!m_bAscending)\r
1342                 result = -result;\r
1343         return result < 0;\r
1344 }\r
1345 \r
1346 BOOL CGitProgressDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)\r
1347 {\r
1348         if (!GetDlgItem(IDOK)->IsWindowEnabled())\r
1349         {\r
1350                 // only show the wait cursor over the list control\r
1351                 if ((pWnd)&&(pWnd == GetDlgItem(IDC_SVNPROGRESS)))\r
1352                 {\r
1353                         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));\r
1354                         SetCursor(hCur);\r
1355                         return TRUE;\r
1356                 }\r
1357         }\r
1358         HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));\r
1359         SetCursor(hCur);\r
1360         return CResizableStandAloneDialog::OnSetCursor(pWnd, nHitTest, message);\r
1361 }\r
1362 \r
1363 BOOL CGitProgressDlg::PreTranslateMessage(MSG* pMsg)\r
1364 {\r
1365         if (pMsg->message == WM_KEYDOWN)\r
1366         {\r
1367                 if (pMsg->wParam == VK_ESCAPE)\r
1368                 {\r
1369                         // pressing the ESC key should close the dialog. But since we disabled the escape\r
1370                         // key (so the user doesn't get the idea that he could simply undo an e.g. update)\r
1371                         // this won't work.\r
1372                         // So if the user presses the ESC key, change it to VK_RETURN so the dialog gets\r
1373                         // the impression that the OK button was pressed.\r
1374                         if ((!m_bThreadRunning)&&(!GetDlgItem(IDCANCEL)->IsWindowEnabled())\r
1375                                 &&(GetDlgItem(IDOK)->IsWindowEnabled())&&(GetDlgItem(IDOK)->IsWindowVisible()))\r
1376                         {\r
1377                                 // since we convert ESC to RETURN, make sure the OK button has the focus.\r
1378                                 GetDlgItem(IDOK)->SetFocus();\r
1379                                 pMsg->wParam = VK_RETURN;\r
1380                         }\r
1381                 }\r
1382                 if (pMsg->wParam == 'A')\r
1383                 {\r
1384                         if (GetKeyState(VK_CONTROL)&0x8000)\r
1385                         {\r
1386                                 // Ctrl-A -> select all\r
1387                                 m_ProgList.SetSelectionMark(0);\r
1388                                 for (int i=0; i<m_ProgList.GetItemCount(); ++i)\r
1389                                 {\r
1390                                         m_ProgList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);\r
1391                                 }\r
1392                         }\r
1393                 }\r
1394                 if ((pMsg->wParam == 'C')||(pMsg->wParam == VK_INSERT))\r
1395                 {\r
1396                         int selIndex = m_ProgList.GetSelectionMark();\r
1397                         if (selIndex >= 0)\r
1398                         {\r
1399                                 if (GetKeyState(VK_CONTROL)&0x8000)\r
1400                                 {\r
1401                                         //Ctrl-C -> copy to clipboard\r
1402                                         CString sClipdata;\r
1403                                         POSITION pos = m_ProgList.GetFirstSelectedItemPosition();\r
1404                                         if (pos != NULL)\r
1405                                         {\r
1406                                                 while (pos)\r
1407                                                 {\r
1408                                                         int nItem = m_ProgList.GetNextSelectedItem(pos);\r
1409                                                         CString sAction = m_ProgList.GetItemText(nItem, 0);\r
1410                                                         CString sPath = m_ProgList.GetItemText(nItem, 1);\r
1411                                                         CString sMime = m_ProgList.GetItemText(nItem, 2);\r
1412                                                         CString sLogCopyText;\r
1413                                                         sLogCopyText.Format(_T("%s: %s  %s\r\n"),\r
1414                                                                 (LPCTSTR)sAction, (LPCTSTR)sPath, (LPCTSTR)sMime);\r
1415                                                         sClipdata +=  sLogCopyText;\r
1416                                                 }\r
1417                                                 CStringUtils::WriteAsciiStringToClipboard(sClipdata);\r
1418                                         }\r
1419                                 }\r
1420                         }\r
1421                 } \r
1422         } // if (pMsg->message == WM_KEYDOWN)\r
1423         return __super::PreTranslateMessage(pMsg);\r
1424 }\r
1425 \r
1426 void CGitProgressDlg::OnContextMenu(CWnd* pWnd, CPoint point)\r
1427 {\r
1428 #if 0\r
1429         if (m_options & ProgOptDryRun)\r
1430                 return; // don't do anything in a dry-run.\r
1431 \r
1432         if (pWnd == &m_ProgList)\r
1433         {\r
1434                 int selIndex = m_ProgList.GetSelectionMark();\r
1435                 if ((point.x == -1) && (point.y == -1))\r
1436                 {\r
1437                         // Menu was invoked from the keyboard rather than by right-clicking\r
1438                         CRect rect;\r
1439                         m_ProgList.GetItemRect(selIndex, &rect, LVIR_LABEL);\r
1440                         m_ProgList.ClientToScreen(&rect);\r
1441                         point = rect.CenterPoint();\r
1442                 }\r
1443 \r
1444                 if ((selIndex >= 0)&&(!m_bThreadRunning))\r
1445                 {\r
1446                         // entry is selected, thread has finished with updating so show the popup menu\r
1447                         CIconMenu popup;\r
1448                         if (popup.CreatePopupMenu())\r
1449                         {\r
1450                                 bool bAdded = false;\r
1451                                 NotificationData * data = m_arData[selIndex];\r
1452                                 if ((data)&&(!data->path.IsDirectory()))\r
1453                                 {\r
1454                                         if (data->action == svn_wc_notify_update_update || data->action == svn_wc_notify_resolved)\r
1455                                         {\r
1456                                                 if (m_ProgList.GetSelectedCount() == 1)\r
1457                                                 {\r
1458                                                         popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARE, IDI_DIFF);\r
1459                                                         bAdded = true;\r
1460                                                 }\r
1461                                         }\r
1462                                                 if (data->bConflictedActionItem)\r
1463                                                 {\r
1464                                                         if (m_ProgList.GetSelectedCount() == 1)\r
1465                                                         {\r
1466                                                                 popup.AppendMenuIcon(ID_EDITCONFLICT, IDS_MENUCONFLICT,IDI_CONFLICT);\r
1467                                                                 popup.SetDefaultItem(ID_EDITCONFLICT, FALSE);\r
1468                                                                 popup.AppendMenuIcon(ID_CONFLICTRESOLVE, IDS_SVNPROGRESS_MENUMARKASRESOLVED,IDI_RESOLVE);\r
1469                                                         }\r
1470                                                         popup.AppendMenuIcon(ID_CONFLICTUSETHEIRS, IDS_SVNPROGRESS_MENUUSETHEIRS,IDI_RESOLVE);\r
1471                                                         popup.AppendMenuIcon(ID_CONFLICTUSEMINE, IDS_SVNPROGRESS_MENUUSEMINE,IDI_RESOLVE);\r
1472                                                 }\r
1473                                                 else if ((data->content_state == svn_wc_notify_state_merged)||(GitProgress_Merge == m_Command)||(data->action == svn_wc_notify_resolved))\r
1474                                                         popup.SetDefaultItem(ID_COMPARE, FALSE);\r
1475                                         \r
1476                                         if (m_ProgList.GetSelectedCount() == 1)\r
1477                                         {\r
1478                                                 if ((data->action == svn_wc_notify_add)||\r
1479                                                         (data->action == svn_wc_notify_update_add)||\r
1480                                                         (data->action == svn_wc_notify_commit_added)||\r
1481                                                         (data->action == svn_wc_notify_commit_modified)||\r
1482                                                         (data->action == svn_wc_notify_restore)||\r
1483                                                         (data->action == svn_wc_notify_revert)||\r
1484                                                         (data->action == svn_wc_notify_resolved)||\r
1485                                                         (data->action == svn_wc_notify_commit_replaced)||\r
1486                                                         (data->action == svn_wc_notify_commit_modified)||\r
1487                                                         (data->action == svn_wc_notify_commit_postfix_txdelta)||\r
1488                                                         (data->action == svn_wc_notify_update_update))\r
1489                                                 {\r
1490                                                         popup.AppendMenuIcon(ID_LOG, IDS_MENULOG,IDI_LOG);\r
1491                                                         if (data->action == svn_wc_notify_update_update)\r
1492                                                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1493                                                         popup.AppendMenuIcon(ID_OPEN, IDS_LOG_POPUP_OPEN, IDI_OPEN);\r
1494                                                         popup.AppendMenuIcon(ID_OPENWITH, IDS_LOG_POPUP_OPENWITH, IDI_OPEN);\r
1495                                                         bAdded = true;\r
1496                                                 }\r
1497                                         }\r
1498                                 } // if ((data)&&(!data->path.IsDirectory()))\r
1499                                 if (m_ProgList.GetSelectedCount() == 1)\r
1500                                 {\r
1501                                         if (data)\r
1502                                         {\r
1503                                                 CString sPath = GetPathFromColumnText(data->sPathColumnText);\r
1504                                                 if ((!sPath.IsEmpty())&&(!SVN::PathIsURL(CTGitPath(sPath))))\r
1505                                                 {\r
1506                                                         CTGitPath path = CTGitPath(sPath);\r
1507                                                         if (path.GetDirectory().Exists())\r
1508                                                         {\r
1509                                                                 popup.AppendMenuIcon(ID_EXPLORE, IDS_SVNPROGRESS_MENUOPENPARENT, IDI_EXPLORER);\r
1510                                                                 bAdded = true;\r
1511                                                         }\r
1512                                                 }\r
1513                                         }\r
1514                                 }\r
1515                                 if (m_ProgList.GetSelectedCount() > 0)\r
1516                                 {\r
1517                                         if (bAdded)\r
1518                                                 popup.AppendMenu(MF_SEPARATOR, NULL);\r
1519                                         popup.AppendMenuIcon(ID_COPY, IDS_LOG_POPUP_COPYTOCLIPBOARD,IDI_COPYCLIP);\r
1520                                         bAdded = true;\r
1521                                 }\r
1522                                 if (bAdded)\r
1523                                 {\r
1524                                         int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);\r
1525                                         DialogEnableWindow(IDOK, FALSE);\r
1526                                         this->SetPromptApp(&theApp);\r
1527                                         theApp.DoWaitCursor(1);\r
1528                                         bool bOpenWith = false;\r
1529                                         switch (cmd)\r
1530                                         {\r
1531                                         case ID_COPY:\r
1532                                                 {\r
1533                                                         CString sLines;\r
1534                                                         POSITION pos = m_ProgList.GetFirstSelectedItemPosition();\r
1535                                                         while (pos)\r
1536                                                         {\r
1537                                                                 int nItem = m_ProgList.GetNextSelectedItem(pos);\r
1538                                                                 NotificationData * data = m_arData[nItem];\r
1539                                                                 if (data)\r
1540                                                                 {\r
1541                                                                         sLines += data->sPathColumnText;\r
1542                                                                         sLines += _T("\r\n");\r
1543                                                                 }\r
1544                                                         }\r
1545                                                         sLines.TrimRight();\r
1546                                                         if (!sLines.IsEmpty())\r
1547                                                         {\r
1548                                                                 CStringUtils::WriteAsciiStringToClipboard(sLines, GetSafeHwnd());\r
1549                                                         }\r
1550                                                 }\r
1551                                                 break;\r
1552                                         case ID_EXPLORE:\r
1553                                                 {\r
1554                                                         CString sPath = GetPathFromColumnText(data->sPathColumnText);\r
1555 \r
1556                                                         CTGitPath path = CTGitPath(sPath);\r
1557                                                         ShellExecute(m_hWnd, _T("explore"), path.GetDirectory().GetWinPath(), NULL, path.GetDirectory().GetWinPath(), SW_SHOW);\r
1558                                                 }\r
1559                                                 break;\r
1560                                         case ID_COMPARE:\r
1561                                                 {\r
1562                                                         svn_revnum_t rev = -1;\r
1563                                                         StringRevMap::iterator it = m_UpdateStartRevMap.end();\r
1564                                                         if (data->basepath.IsEmpty())\r
1565                                                                 it = m_UpdateStartRevMap.begin();\r
1566                                                         else\r
1567                                                                 it = m_UpdateStartRevMap.find(data->basepath.GetSVNApiPath(pool));\r
1568                                                         if (it != m_UpdateStartRevMap.end())\r
1569                                                                 rev = it->second;\r
1570                                                         // if the file was merged during update, do a three way diff between OLD, MINE, THEIRS\r
1571                                                         if (data->content_state == svn_wc_notify_state_merged)\r
1572                                                         {\r
1573                                                                 CTGitPath basefile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);\r
1574                                                                 CTGitPath newfile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_HEAD);\r
1575                                                                 SVN svn;\r
1576                                                                 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, basefile))\r
1577                                                                 {\r
1578                                                                         CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
1579                                                                         DialogEnableWindow(IDOK, TRUE);\r
1580                                                                         break;\r
1581                                                                 }\r
1582                                                                 // If necessary, convert the line-endings on the file before diffing\r
1583                                                                 if ((DWORD)CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"), TRUE))\r
1584                                                                 {\r
1585                                                                         CTGitPath temporaryFile = CTempFiles::Instance().GetTempFilePath(false, data->path, SVNRev::REV_BASE);\r
1586                                                                         if (!svn.Cat(data->path, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE), temporaryFile))\r
1587                                                                         {\r
1588                                                                                 temporaryFile.Reset();\r
1589                                                                                 break;\r
1590                                                                         }\r
1591                                                                         else\r
1592                                                                         {\r
1593                                                                                 newfile = temporaryFile;\r
1594                                                                         }\r
1595                                                                 }\r
1596 \r
1597                                                                 SetFileAttributes(newfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);\r
1598                                                                 SetFileAttributes(basefile.GetWinPath(), FILE_ATTRIBUTE_READONLY);\r
1599                                                                 CString revname, wcname, basename;\r
1600                                                                 revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);\r
1601                                                                 wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());\r
1602                                                                 basename.Format(IDS_DIFF_BASENAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());\r
1603                                                                 CAppUtils::StartExtMerge(basefile, newfile, data->path, data->path, basename, revname, wcname, CString(), true);\r
1604                                                         }\r
1605                                                         else\r
1606                                                         {\r
1607                                                                 CTGitPath tempfile = CTempFiles::Instance().GetTempFilePath(false, data->path, rev);\r
1608                                                                 SVN svn;\r
1609                                                                 if (!svn.Cat(data->path, SVNRev(SVNRev::REV_WC), rev, tempfile))\r
1610                                                                 {\r
1611                                                                         CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
1612                                                                         DialogEnableWindow(IDOK, TRUE);\r
1613                                                                         break;\r
1614                                                                 }\r
1615                                                                 else\r
1616                                                                 {\r
1617                                                                         SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY);\r
1618                                                                         CString revname, wcname;\r
1619                                                                         revname.Format(_T("%s Revision %ld"), (LPCTSTR)data->path.GetUIFileOrDirectoryName(), rev);\r
1620                                                                         wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)data->path.GetUIFileOrDirectoryName());\r
1621                                                                         CAppUtils::StartExtDiff(\r
1622                                                                                 tempfile, data->path, revname, wcname,\r
1623                                                                                 CAppUtils::DiffFlags().AlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)));\r
1624                                                                 }\r
1625                                                         }\r
1626                                                 }\r
1627                                                 break;\r
1628                                         case ID_EDITCONFLICT:\r
1629                                                 {\r
1630                                                         CString sPath = GetPathFromColumnText(data->sPathColumnText);\r
1631                                                         SVNDiff::StartConflictEditor(CTGitPath(sPath));\r
1632                                                 }\r
1633                                                 break;\r
1634                                         case ID_CONFLICTUSETHEIRS:\r
1635                                         case ID_CONFLICTUSEMINE:\r
1636                                         case ID_CONFLICTRESOLVE:\r
1637                                                 {\r
1638                                                         svn_wc_conflict_choice_t result = svn_wc_conflict_choose_merged;\r
1639                                                         switch (cmd)\r
1640                                                         {\r
1641                                                         case ID_CONFLICTUSETHEIRS:\r
1642                                                                 result = svn_wc_conflict_choose_theirs_full;\r
1643                                                                 break;\r
1644                                                         case ID_CONFLICTUSEMINE:\r
1645                                                                 result = svn_wc_conflict_choose_mine_full;\r
1646                                                                 break;\r
1647                                                         case ID_CONFLICTRESOLVE:\r
1648                                                                 result = svn_wc_conflict_choose_merged;\r
1649                                                                 break;\r
1650                                                         }\r
1651                                                         SVN svn;\r
1652                                                         POSITION pos = m_ProgList.GetFirstSelectedItemPosition();\r
1653                                                         CString sResolvedPaths;\r
1654                                                         while (pos)\r
1655                                                         {\r
1656                                                                 int nItem = m_ProgList.GetNextSelectedItem(pos);\r
1657                                                                 NotificationData * data = m_arData[nItem];\r
1658                                                                 if (data)\r
1659                                                                 {\r
1660                                                                         if (data->bConflictedActionItem)\r
1661                                                                         {\r
1662                                                                                 if (!svn.Resolve(data->path, result, FALSE))\r
1663                                                                                 {\r
1664                                                                                         CMessageBox::Show(m_hWnd, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
1665                                                                                         DialogEnableWindow(IDOK, TRUE);\r
1666                                                                                         break;\r
1667                                                                                 }\r
1668                                                                                 else\r
1669                                                                                 {\r
1670                                                                                         data->color = ::GetSysColor(COLOR_WINDOWTEXT);\r
1671                                                                                         data->action = svn_wc_notify_resolved;\r
1672                                                                                         data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE);\r
1673                                                                                         data->bConflictedActionItem = false;\r
1674                                                                                         m_nConflicts--;\r
1675 \r
1676                                                                                         if (m_nConflicts==0)\r
1677                                                                                         {\r
1678                                                                                                 // When the last conflict is resolved we remove\r
1679                                                                                                 // the warning which we assume is in the last line.\r
1680                                                                                                 int nIndex = m_ProgList.GetItemCount()-1;\r
1681                                                                                                 VERIFY(m_ProgList.DeleteItem(nIndex));\r
1682 \r
1683                                                                                                 delete m_arData[nIndex];\r
1684                                                                                                 m_arData.pop_back();\r
1685                                                                                         }\r
1686                                                                                         sResolvedPaths += data->path.GetWinPathString() + _T("\n");\r
1687                                                                                 }\r
1688                                                                         }\r
1689                                                                 }\r
1690                                                         }\r
1691                                                         m_ProgList.Invalidate();\r
1692                                                         CString info = BuildInfoString();\r
1693                                                         SetDlgItemText(IDC_INFOTEXT, info);\r
1694 \r
1695                                                         if (!sResolvedPaths.IsEmpty())\r
1696                                                         {\r
1697                                                                 CString msg;\r
1698                                                                 msg.Format(IDS_SVNPROGRESS_RESOLVED, (LPCTSTR)sResolvedPaths);\r
1699                                                                 CMessageBox::Show(m_hWnd, msg, _T("TortoiseSVN"), MB_OK | MB_ICONINFORMATION);\r
1700                                                         }\r
1701                                                 }\r
1702                                                 break;\r
1703                                         case ID_LOG:\r
1704                                                 {\r
1705                                                         CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);\r
1706                                                         int limit = (int)(DWORD)reg;\r
1707                                                         svn_revnum_t rev = m_RevisionEnd;\r
1708                                                         if (!data->basepath.IsEmpty())\r
1709                                                         {\r
1710                                                                 StringRevMap::iterator it = m_FinishedRevMap.find(data->basepath.GetSVNApiPath(pool));\r
1711                                                                 if (it != m_FinishedRevMap.end())\r
1712                                                                         rev = it->second;\r
1713                                                         }\r
1714                                                         CLogDlg dlg;\r
1715                                                         // fetch the log from HEAD, not the revision we updated to:\r
1716                                                         // the path might be inside an external folder which has its own\r
1717                                                         // revisions.\r
1718                                                         CString sPath = GetPathFromColumnText(data->sPathColumnText);\r
1719                                                         dlg.SetParams(CTGitPath(sPath), SVNRev(), SVNRev::REV_HEAD, 1, limit, TRUE);\r
1720                                                         dlg.DoModal();\r
1721                                                 }\r
1722                                                 break;\r
1723                                         case ID_OPENWITH:\r
1724                                                 bOpenWith = true;\r
1725                                         case ID_OPEN:\r
1726                                                 {\r
1727                                                         int ret = 0;\r
1728                                                         CString sWinPath = GetPathFromColumnText(data->sPathColumnText);\r
1729                                                         if (!bOpenWith)\r
1730                                                                 ret = (int)ShellExecute(this->m_hWnd, NULL, (LPCTSTR)sWinPath, NULL, NULL, SW_SHOWNORMAL);\r
1731                                                         if ((ret <= HINSTANCE_ERROR)||bOpenWith)\r
1732                                                         {\r
1733                                                                 CString cmd = _T("RUNDLL32 Shell32,OpenAs_RunDLL ");\r
1734                                                                 cmd += sWinPath + _T(" ");\r
1735                                                                 CAppUtils::LaunchApplication(cmd, NULL, false);\r
1736                                                         }\r
1737                                                 }\r
1738                                         }\r
1739                                         DialogEnableWindow(IDOK, TRUE);\r
1740                                         theApp.DoWaitCursor(-1);\r
1741                                 } // if (bAdded)\r
1742                         }\r
1743                 }\r
1744         }\r
1745 #endif\r
1746 }\r
1747 \r
1748 void CGitProgressDlg::OnEnSetfocusInfotext()\r
1749 {\r
1750         CString sTemp;\r
1751         GetDlgItemText(IDC_INFOTEXT, sTemp);\r
1752         if (sTemp.IsEmpty())\r
1753                 GetDlgItem(IDC_INFOTEXT)->HideCaret();\r
1754 }\r
1755 \r
1756 void CGitProgressDlg::OnLvnBegindragSvnprogress(NMHDR* , LRESULT *pResult)\r
1757 {\r
1758         //LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
1759 #if 0\r
1760         int selIndex = m_ProgList.GetSelectionMark();\r
1761         if (selIndex < 0)\r
1762                 return;\r
1763 \r
1764         CDropFiles dropFiles; // class for creating DROPFILES struct\r
1765 \r
1766         int index;\r
1767         POSITION pos = m_ProgList.GetFirstSelectedItemPosition();\r
1768         while ( (index = m_ProgList.GetNextSelectedItem(pos)) >= 0 )\r
1769         {\r
1770                 NotificationData * data = m_arData[index];\r
1771 \r
1772                 if ( data->kind==svn_node_file || data->kind==svn_node_dir )\r
1773                 {\r
1774                         CString sPath = GetPathFromColumnText(data->sPathColumnText);\r
1775 \r
1776                         dropFiles.AddFile( sPath );\r
1777                 }\r
1778         }\r
1779 \r
1780         if ( dropFiles.GetCount()>0 )\r
1781         {\r
1782                 dropFiles.CreateStructure();\r
1783         }\r
1784 #endif\r
1785         *pResult = 0;\r
1786 }\r
1787 \r
1788 void CGitProgressDlg::OnSize(UINT nType, int cx, int cy)\r
1789 {\r
1790         CResizableStandAloneDialog::OnSize(nType, cx, cy);\r
1791         if ((nType == SIZE_RESTORED)&&(m_bLastVisible))\r
1792         {\r
1793                 if(!m_ProgList.m_hWnd)\r
1794                         return;\r
1795 \r
1796                 int count = m_ProgList.GetItemCount();\r
1797                 if (count > 0)\r
1798                         m_ProgList.EnsureVisible(count-1, false);\r
1799         }\r
1800 }\r
1801 \r
1802 //////////////////////////////////////////////////////////////////////////\r
1803 /// commands\r
1804 //////////////////////////////////////////////////////////////////////////\r
1805 bool CGitProgressDlg::CmdAdd(CString& sWindowTitle, bool& localoperation)\r
1806 {\r
1807 \r
1808         localoperation = true;\r
1809         sWindowTitle.LoadString(IDS_PROGRS_TITLE_ADD);\r
1810         SetWindowText(sWindowTitle);\r
1811         SetBackgroundImage(IDI_ADD_BKG);\r
1812         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));\r
1813 \r
1814         for(int i=0;i<m_targetPathList.GetCount();i++)\r
1815         {\r
1816                 CString cmd,out;\r
1817                 cmd.Format(_T("git.exe add -f \"%s\""),m_targetPathList[i].GetGitPathString());\r
1818                 if(g_Git.Run(cmd,&out,CP_ACP))\r
1819                 {\r
1820                         CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
1821                         m_bErrorsOccurred=true;\r
1822                         return false;\r
1823                 }\r
1824                 Notify(m_targetPathList[i],git_wc_notify_add);\r
1825         }\r
1826 #if 0\r
1827         if (!Add(m_targetPathList, &m_ProjectProperties, svn_depth_empty, FALSE, TRUE, TRUE))\r
1828         {\r
1829                 ReportSVNError();\r
1830                 return false;\r
1831         }\r
1832 #endif\r
1833         //CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);\r
1834         m_bErrorsOccurred=false;\r
1835         return true;\r
1836 }\r
1837 \r
1838 bool CGitProgressDlg::CmdCheckout(CString& sWindowTitle, bool& /*localoperation*/)\r
1839 {\r
1840 #if 0\r
1841         ASSERT(m_targetPathList.GetCount() == 1);\r
1842         sWindowTitle.LoadString(IDS_PROGRS_TITLE_CHECKOUT);\r
1843         SetBackgroundImage(IDI_CHECKOUT_BKG);\r
1844         CTGitPathList urls;\r
1845         urls.LoadFromAsteriskSeparatedString(m_url.GetSVNPathString());\r
1846         CTGitPath checkoutdir = m_targetPathList[0];\r
1847         for (int i=0; i<urls.GetCount(); ++i)\r
1848         {\r
1849                 sWindowTitle = urls[i].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;\r
1850                 SetWindowText(sWindowTitle);\r
1851                 checkoutdir = m_targetPathList[0];\r
1852                 if (urls.GetCount() > 1)\r
1853                 {\r
1854                         CString fileordir = urls[i].GetFileOrDirectoryName();\r
1855                         fileordir = CPathUtils::PathUnescape(fileordir);\r
1856                         checkoutdir.AppendPathString(fileordir);\r
1857                 }\r
1858                 CString sCmdInfo;\r
1859                 sCmdInfo.Format(IDS_PROGRS_CMD_CHECKOUT, \r
1860                         (LPCTSTR)urls[i].GetSVNPathString(), (LPCTSTR)m_Revision.ToString(), \r
1861                         (LPCTSTR)SVNStatus::GetDepthString(m_depth), \r
1862                         m_options & ProgOptIgnoreExternals ? (LPCTSTR)sExtExcluded : (LPCTSTR)sExtIncluded);\r
1863                 ReportCmd(sCmdInfo);\r
1864 \r
1865                 if (!Checkout(urls[i], checkoutdir, m_Revision, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))\r
1866                 {\r
1867                         if (m_ProgList.GetItemCount()!=0)\r
1868                         {\r
1869                                 ReportSVNError();\r
1870                                 return false;\r
1871                         }\r
1872                         // if the checkout fails with the peg revision set to the checkout revision,\r
1873                         // try again with HEAD as the peg revision.\r
1874                         else\r
1875                         {\r
1876                                 if (!Checkout(urls[i], checkoutdir, SVNRev::REV_HEAD, m_Revision, m_depth, m_options & ProgOptIgnoreExternals))\r
1877                                 {\r
1878                                         ReportSVNError();\r
1879                                         return false;\r
1880                                 }\r
1881                         }\r
1882                 }\r
1883         }\r
1884 #endif\r
1885         return true;\r
1886 }\r
1887 \r
1888 bool CGitProgressDlg::CmdCommit(CString& sWindowTitle, bool& /*localoperation*/)\r
1889 {\r
1890 #if 0\r
1891         sWindowTitle.LoadString(IDS_PROGRS_TITLE_COMMIT);\r
1892         SetWindowText(sWindowTitle);\r
1893         SetBackgroundImage(IDI_COMMIT_BKG);\r
1894         if (m_targetPathList.GetCount()==0)\r
1895         {\r
1896                 SetWindowText(sWindowTitle);\r
1897 \r
1898                 DialogEnableWindow(IDCANCEL, FALSE);\r
1899                 DialogEnableWindow(IDOK, TRUE);\r
1900 \r
1901                 InterlockedExchange(&m_bThreadRunning, FALSE);\r
1902                 return true;\r
1903         }\r
1904         if (m_targetPathList.GetCount()==1)\r
1905         {\r
1906                 sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;\r
1907                 SetWindowText(sWindowTitle);\r
1908         }\r
1909         BOOL isTag = FALSE;\r
1910         BOOL bURLFetched = FALSE;\r
1911         CString url;\r
1912         for (int i=0; i<m_targetPathList.GetCount(); ++i)\r
1913         {\r
1914                 if (bURLFetched == FALSE)\r
1915                 {\r
1916                         url = GetURLFromPath(m_targetPathList[i]);\r
1917                         if (!url.IsEmpty())\r
1918                                 bURLFetched = TRUE;\r
1919                         CString urllower = url;\r
1920                         urllower.MakeLower();\r
1921                         // test if the commit goes to a tag.\r
1922                         // now since Subversion doesn't force users to\r
1923                         // create tags in the recommended /tags/ folder\r
1924                         // only a warning is shown. This won't work if the tags\r
1925                         // are stored in a non-recommended place, but the check\r
1926                         // still helps those who do.\r
1927                         if (urllower.Find(_T("/tags/"))>=0)\r
1928                                 isTag = TRUE;\r
1929                         break;\r
1930                 }\r
1931         }\r
1932         if (isTag)\r
1933         {\r
1934                 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_COMMITT_TRUNK, IDS_APPNAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION)==IDNO)\r
1935                         return false;\r
1936         }\r
1937         DWORD exitcode = 0;\r
1938         CString error;\r
1939         if (CHooks::Instance().PreCommit(m_selectedPaths, m_depth, m_sMessage, exitcode, error))\r
1940         {\r
1941                 if (exitcode)\r
1942                 {\r
1943                         CString temp;\r
1944                         temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);\r
1945                         ReportError(temp);\r
1946                         return false;\r
1947                 }\r
1948         }\r
1949 \r
1950         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_COMMIT)));\r
1951         CStringArray changelists;\r
1952     if (!m_changelist.IsEmpty())\r
1953             changelists.Add(m_changelist);\r
1954         bool commitSuccessful = true;\r
1955         if (!Commit(m_targetPathList, m_sMessage, changelists, m_keepchangelist, \r
1956                 m_depth, m_options & ProgOptKeeplocks))\r
1957         {\r
1958                 ReportSVNError();\r
1959                 error = GetLastErrorMessage();\r
1960                 // if a non-recursive commit failed with SVN_ERR_UNSUPPORTED_FEATURE,\r
1961                 // that means a folder deletion couldn't be committed.\r
1962                 if ((m_Revision != 0)&&(Err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))\r
1963                 {\r
1964                         ReportError(CString(MAKEINTRESOURCE(IDS_PROGRS_NONRECURSIVEHINT)));\r
1965                 }\r
1966                 commitSuccessful = false;\r
1967                 return false;\r
1968         }\r
1969         if (!PostCommitErr.IsEmpty())\r
1970         {\r
1971                 ReportWarning(PostCommitErr);\r
1972         }\r
1973         if (commitSuccessful)\r
1974         {\r
1975                 if (m_BugTraqProvider)\r
1976                 {\r
1977                         CComPtr<IBugTraqProvider2> pProvider = NULL;\r
1978                         HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
1979                         if (SUCCEEDED(hr))\r
1980                         {\r
1981                                 BSTR commonRoot = SysAllocString(m_targetPathList.GetCommonRoot().GetDirectory().GetWinPath());\r
1982                                 SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_targetPathList.GetCount());\r
1983 \r
1984                                 for (LONG index = 0; index < m_targetPathList.GetCount(); ++index)\r
1985                                         SafeArrayPutElement(pathList, &index, m_targetPathList[index].GetSVNPathString().AllocSysString());\r
1986 \r
1987                                 BSTR logMessage = m_sMessage.AllocSysString();\r
1988 \r
1989                                 BSTR temp = NULL;\r
1990                                 if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(), \r
1991                                         commonRoot,\r
1992                                         pathList,\r
1993                                         logMessage,\r
1994                                         (LONG)m_RevisionEnd,\r
1995                                         &temp)))\r
1996                                 {\r
1997                                         CString sErr = temp;\r
1998                                         if (!sErr.IsEmpty())\r
1999                                                 ReportError(temp);\r
2000                                 }\r
2001 \r
2002                                 SysFreeString(temp);\r
2003                         }\r
2004                 }\r
2005         }\r
2006         if (CHooks::Instance().PostCommit(m_selectedPaths, m_depth, m_RevisionEnd, m_sMessage, exitcode, error))\r
2007         {\r
2008                 if (exitcode)\r
2009                 {\r
2010                         CString temp;\r
2011                         temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);\r
2012                         ReportError(temp);\r
2013                         return false;\r
2014                 }\r
2015         }\r
2016 #endif\r
2017         return true;\r
2018 }\r
2019 \r
2020 bool CGitProgressDlg::CmdCopy(CString& sWindowTitle, bool& /*localoperation*/)\r
2021 {\r
2022 #if 0\r
2023         ASSERT(m_targetPathList.GetCount() == 1);\r
2024         sWindowTitle.LoadString(IDS_PROGRS_TITLE_COPY);\r
2025         SetWindowText(sWindowTitle);\r
2026         SetBackgroundImage(IDI_COPY_BKG);\r
2027 \r
2028         CString sCmdInfo;\r
2029         sCmdInfo.Format(IDS_PROGRS_CMD_COPY, \r
2030                 m_targetPathList[0].IsUrl() ? (LPCTSTR)m_targetPathList[0].GetSVNPathString() : m_targetPathList[0].GetWinPath(),\r
2031                 (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());\r
2032         ReportCmd(sCmdInfo);\r
2033 \r
2034         if (!Copy(m_targetPathList, m_url, m_Revision, m_pegRev, m_sMessage))\r
2035         {\r
2036                 ReportSVNError();\r
2037                 return false;\r
2038         }\r
2039         if (m_options & ProgOptSwitchAfterCopy)\r
2040         {\r
2041                 sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH, \r
2042                         m_targetPathList[0].GetWinPath(),\r
2043                         (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString());\r
2044                 ReportCmd(sCmdInfo);\r
2045                 if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, SVNRev::REV_HEAD, m_depth, TRUE, m_options & ProgOptIgnoreExternals))\r
2046                 {\r
2047                         if (!Switch(m_targetPathList[0], m_url, SVNRev::REV_HEAD, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))\r
2048                         {\r
2049                                 ReportSVNError();\r
2050                                 return false;\r
2051                         }\r
2052                 }\r
2053         }\r
2054         else\r
2055         {\r
2056                 if (SVN::PathIsURL(m_url))\r
2057                 {\r
2058                         CString sMsg(MAKEINTRESOURCE(IDS_PROGRS_COPY_WARNING));\r
2059                         ReportNotification(sMsg);\r
2060                 }\r
2061         }\r
2062 #endif\r
2063         return true;\r
2064 }\r
2065 \r
2066 bool CGitProgressDlg::CmdExport(CString& sWindowTitle, bool& /*localoperation*/)\r
2067 {\r
2068 #if 0\r
2069         ASSERT(m_targetPathList.GetCount() == 1);\r
2070         sWindowTitle.LoadString(IDS_PROGRS_TITLE_EXPORT);\r
2071         sWindowTitle = m_url.GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;\r
2072         SetWindowText(sWindowTitle);\r
2073         SetBackgroundImage(IDI_EXPORT_BKG);\r
2074         CString eol;\r
2075         if (m_options & ProgOptEolCRLF)\r
2076                 eol = _T("CRLF");\r
2077         if (m_options & ProgOptEolLF)\r
2078                 eol = _T("LF");\r
2079         if (m_options & ProgOptEolCR)\r
2080                 eol = _T("CR");\r
2081         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_EXPORT)));\r
2082         if (!Export(m_url, m_targetPathList[0], m_Revision, m_Revision, TRUE, m_options & ProgOptIgnoreExternals, m_depth, NULL, FALSE, eol))\r
2083         {\r
2084                 ReportSVNError();\r
2085                 return false;\r
2086         }\r
2087 #endif\r
2088         return true;\r
2089 }\r
2090 \r
2091 bool CGitProgressDlg::CmdImport(CString& sWindowTitle, bool& /*localoperation*/)\r
2092 {\r
2093 #if 0\r
2094         ASSERT(m_targetPathList.GetCount() == 1);\r
2095         sWindowTitle.LoadString(IDS_PROGRS_TITLE_IMPORT);\r
2096         sWindowTitle = m_targetPathList[0].GetUIFileOrDirectoryName()+_T(" - ")+sWindowTitle;\r
2097         SetWindowText(sWindowTitle);\r
2098         SetBackgroundImage(IDI_IMPORT_BKG);\r
2099         CString sCmdInfo;\r
2100         sCmdInfo.Format(IDS_PROGRS_CMD_IMPORT, \r
2101                 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(), \r
2102                 m_options & ProgOptIncludeIgnored ? (LPCTSTR)(_T(", ") + sIgnoredIncluded) : _T(""));\r
2103         ReportCmd(sCmdInfo);\r
2104         if (!Import(m_targetPathList[0], m_url, m_sMessage, &m_ProjectProperties, svn_depth_infinity, m_options & ProgOptIncludeIgnored ? true : false, false))\r
2105         {\r
2106                 ReportSVNError();\r
2107                 return false;\r
2108         }\r
2109 #endif\r
2110         return true;\r
2111 }\r
2112 \r
2113 bool CGitProgressDlg::CmdLock(CString& sWindowTitle, bool& /*localoperation*/)\r
2114 {\r
2115 #if 0\r
2116         sWindowTitle.LoadString(IDS_PROGRS_TITLE_LOCK);\r
2117         SetWindowText(sWindowTitle);\r
2118         SetBackgroundImage(IDI_LOCK_BKG);\r
2119         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_LOCK)));\r
2120         if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))\r
2121         {\r
2122                 ReportSVNError();\r
2123                 return false;\r
2124         }\r
2125         CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);\r
2126         if (m_bLockWarning)\r
2127         {\r
2128                 // the lock failed, because the file was outdated.\r
2129                 // ask the user whether to update the file and try again\r
2130                 if (CMessageBox::Show(m_hWnd, IDS_WARN_LOCKOUTDATED, IDS_APPNAME, MB_ICONQUESTION|MB_YESNO)==IDYES)\r
2131                 {\r
2132                         ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_UPDATEANDRETRY)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));\r
2133                         if (!Update(m_targetPathList, SVNRev::REV_HEAD, svn_depth_files, false, true))\r
2134                         {\r
2135                                 ReportSVNError();\r
2136                                 return false;\r
2137                         }\r
2138                         if (!Lock(m_targetPathList, m_options & ProgOptLockForce, m_sMessage))\r
2139                         {\r
2140                                 ReportSVNError();\r
2141                                 return false;\r
2142                         }\r
2143                 }\r
2144         }\r
2145         if (m_bLockExists)\r
2146         {\r
2147                 // the locking failed because there already is a lock.\r
2148                 // if the locking-dialog is skipped in the settings, tell the\r
2149                 // user how to steal the lock anyway (i.e., how to get the lock\r
2150                 // dialog back without changing the settings)\r
2151                 if (!DWORD(CRegDWORD(_T("Software\\TortoiseGit\\ShowLockDlg"), TRUE)))\r
2152                 {\r
2153                         ReportString(CString(MAKEINTRESOURCE(IDS_SVNPROGRESS_LOCKHINT)), CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));\r
2154                 }\r
2155                 return false;\r
2156         }\r
2157 #endif\r
2158         return true;\r
2159 }\r
2160 \r
2161 bool CGitProgressDlg::CmdMerge(CString& sWindowTitle, bool& /*localoperation*/)\r
2162 {\r
2163 #if 0\r
2164         bool bFailed = false;\r
2165         ASSERT(m_targetPathList.GetCount() == 1);\r
2166         sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);\r
2167         SetBackgroundImage(IDI_MERGE_BKG);\r
2168         if (m_options & ProgOptDryRun)\r
2169         {\r
2170                 sWindowTitle += _T(" ") + sDryRun;\r
2171         }\r
2172         if (m_options & ProgOptRecordOnly)\r
2173         {\r
2174                 sWindowTitle += _T(" ") + sRecordOnly;\r
2175         }\r
2176         SetWindowText(sWindowTitle);\r
2177 \r
2178         GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_HIDE);\r
2179         GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);\r
2180         CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);\r
2181         if (DWORD(nonint))\r
2182         {\r
2183                 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);\r
2184                 m_AlwaysConflicted = true;\r
2185         }\r
2186         // we only accept a revision list to merge for peg merges\r
2187         ATLASSERT((m_revisionArray.GetCount()==0) || (m_revisionArray.GetCount() && (m_url.IsEquivalentTo(m_url2))));\r
2188 \r
2189         if (m_url.IsEquivalentTo(m_url2))\r
2190         {\r
2191                 CString sSuggestedMessage;\r
2192                 CString sMergedLogMessage;\r
2193                 CString sSeparator = CRegString(_T("Software\\TortoiseGit\\MergeLogSeparator"), _T("........"));\r
2194                 CString temp;\r
2195 \r
2196                 // Merging revisions %s of %s to %s into %s, %s%s\r
2197                 CString sCmdInfo;\r
2198                 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEPEG, \r
2199                         (LPCTSTR)m_revisionArray.ToListString(),\r
2200                         (LPCTSTR)m_url.GetSVNPathString(),\r
2201                         m_targetPathList[0].GetWinPath(),\r
2202                         m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,\r
2203                         m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));\r
2204                 ReportCmd(sCmdInfo);\r
2205 \r
2206                 if (!PegMerge(m_url, m_revisionArray, \r
2207                         m_pegRev.IsValid() ? m_pegRev : (m_url.IsUrl() ? SVNRev::REV_HEAD : SVNRev(SVNRev::REV_WC)),\r
2208                         m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))\r
2209                 {\r
2210                         // if the merge fails with the peg revision set,\r
2211                         // try again with HEAD as the peg revision.\r
2212                         if (!PegMerge(m_url, m_revisionArray, SVNRev::REV_HEAD,\r
2213                                 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))\r
2214                         {\r
2215                                 ReportSVNError();\r
2216                                 bFailed = true;\r
2217                         }\r
2218                 }\r
2219         }\r
2220         else\r
2221         {\r
2222                 CString sCmdInfo;\r
2223                 sCmdInfo.Format(IDS_PROGRS_CMD_MERGEURL, \r
2224                         (LPCTSTR)m_url.GetSVNPathString(), (LPCTSTR)m_Revision.ToString(), \r
2225                         (LPCTSTR)m_url2.GetSVNPathString(), (LPCTSTR)m_RevisionEnd.ToString(),\r
2226                         m_targetPathList[0].GetWinPath(),\r
2227                         m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry,\r
2228                         m_options & ProgOptDryRun ? ((LPCTSTR)_T(", ") + sDryRun) : _T(""));\r
2229                 ReportCmd(sCmdInfo);\r
2230 \r
2231                 if (!Merge(m_url, m_Revision, m_url2, m_RevisionEnd, m_targetPathList[0], \r
2232                         true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), !!(m_options & ProgOptDryRun), !!(m_options & ProgOptRecordOnly)))\r
2233                 {\r
2234                         ReportSVNError();\r
2235                         bFailed = true;\r
2236                 }\r
2237         }\r
2238         GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);\r
2239         GetDlgItem(IDC_INFOTEXT)->ShowWindow(SW_SHOW);\r
2240         return !bFailed;\r
2241 #endif\r
2242         return true;\r
2243 }\r
2244 \r
2245 bool CGitProgressDlg::CmdMergeAll(CString& sWindowTitle, bool& /*localoperation*/)\r
2246 {\r
2247 #if 0\r
2248         ASSERT(m_targetPathList.GetCount() == 1);\r
2249         sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGE);\r
2250         SetBackgroundImage(IDI_MERGE_BKG);\r
2251         SetWindowText(sWindowTitle);\r
2252 \r
2253         ATLASSERT(m_targetPathList.GetCount() == 1);\r
2254 \r
2255         CString sCmdInfo;\r
2256         sCmdInfo.LoadString(IDS_PROGRS_INFOGETTINGINFO);\r
2257         ReportCmd(sCmdInfo);\r
2258         CTGitPathList suggestedSources;\r
2259         if (!SuggestMergeSources(m_targetPathList[0], m_Revision, suggestedSources))\r
2260         {\r
2261                 ReportSVNError();\r
2262                 return false;\r
2263         }\r
2264 \r
2265         if (suggestedSources.GetCount() == 0)\r
2266         {\r
2267                 CString sErr;\r
2268                 sErr.Format(IDS_PROGRS_MERGEALLNOSOURCES, m_targetPathList[0].GetWinPath());\r
2269                 ReportError(sErr);\r
2270                 return false;\r
2271         }\r
2272         sCmdInfo.Format(IDS_PROGRS_CMD_MERGEALL, \r
2273                 (LPCTSTR)suggestedSources[0].GetSVNPathString(),\r
2274                 m_targetPathList[0].GetWinPath(),\r
2275                 m_options & ProgOptIgnoreAncestry ? (LPCTSTR)sIgnoreAncestry : (LPCTSTR)sRespectAncestry);\r
2276         ReportCmd(sCmdInfo);\r
2277 \r
2278         GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);\r
2279         CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);\r
2280         if (DWORD(nonint))\r
2281         {\r
2282                 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);\r
2283                 m_AlwaysConflicted = true;\r
2284         }\r
2285 \r
2286         SVNRevRangeArray revarray;\r
2287         if (!PegMerge(suggestedSources[0], revarray, \r
2288                 SVNRev::REV_HEAD,\r
2289                 m_targetPathList[0], true, m_depth, m_diffoptions, !!(m_options & ProgOptIgnoreAncestry), FALSE))\r
2290         {\r
2291                 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);\r
2292                 ReportSVNError();\r
2293                 return false;\r
2294         }\r
2295 \r
2296         GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);\r
2297 #endif\r
2298         return true;\r
2299 }\r
2300 \r
2301 bool CGitProgressDlg::CmdMergeReintegrate(CString& sWindowTitle, bool& /*localoperation*/)\r
2302 {\r
2303 #if 0\r
2304         ASSERT(m_targetPathList.GetCount() == 1);\r
2305         sWindowTitle.LoadString(IDS_PROGRS_TITLE_MERGEREINTEGRATE);\r
2306         SetBackgroundImage(IDI_MERGE_BKG);\r
2307         SetWindowText(sWindowTitle);\r
2308 \r
2309         CString sCmdInfo;\r
2310         sCmdInfo.Format(IDS_PROGRS_CMD_MERGEREINTEGRATE, \r
2311                 (LPCTSTR)m_url.GetSVNPathString(),\r
2312                 m_targetPathList[0].GetWinPath());\r
2313         ReportCmd(sCmdInfo);\r
2314 \r
2315         GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_SHOW);\r
2316         CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);\r
2317         if (DWORD(nonint))\r
2318         {\r
2319                 ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_SETCHECK, BST_CHECKED, 0);\r
2320                 m_AlwaysConflicted = true;\r
2321         }\r
2322 \r
2323         if (!MergeReintegrate(m_url, SVNRev::REV_HEAD, m_targetPathList[0], !!(m_options & ProgOptDryRun), m_diffoptions))\r
2324         {\r
2325                 ReportSVNError();\r
2326                 GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);\r
2327                 return false;\r
2328         }\r
2329 \r
2330         GetDlgItem(IDC_NONINTERACTIVE)->ShowWindow(SW_HIDE);\r
2331 #endif\r
2332         return true;\r
2333 }\r
2334 \r
2335 bool CGitProgressDlg::CmdRename(CString& sWindowTitle, bool& localoperation)\r
2336 {\r
2337 #if 0\r
2338         ASSERT(m_targetPathList.GetCount() == 1);\r
2339         if ((!m_targetPathList[0].IsUrl())&&(!m_url.IsUrl()))\r
2340                 localoperation = true;\r
2341         sWindowTitle.LoadString(IDS_PROGRS_TITLE_RENAME);\r
2342         SetWindowText(sWindowTitle);\r
2343         SetBackgroundImage(IDI_RENAME_BKG);\r
2344         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RENAME)));\r
2345         if (!Move(m_targetPathList, m_url, m_Revision, m_sMessage))\r
2346         {\r
2347                 ReportSVNError();\r
2348                 return false;\r
2349         }\r
2350 #endif\r
2351         return true;\r
2352 }\r
2353 \r
2354 bool CGitProgressDlg::CmdResolve(CString& sWindowTitle, bool& localoperation)\r
2355 {\r
2356 \r
2357         localoperation = true;\r
2358         ASSERT(m_targetPathList.GetCount() == 1);\r
2359         sWindowTitle.LoadString(IDS_PROGRS_TITLE_RESOLVE);\r
2360         SetWindowText(sWindowTitle);\r
2361         SetBackgroundImage(IDI_RESOLVE_BKG);\r
2362         // check if the file may still have conflict markers in it.\r
2363         BOOL bMarkers = FALSE;\r
2364 \r
2365         for(int i=0;i<m_targetPathList.GetCount();i++)\r
2366         {\r
2367                 CString cmd,out,tempmergefile;\r
2368                 cmd.Format(_T("git.exe add -f \"%s\""),m_targetPathList[i].GetGitPathString());\r
2369                 if(g_Git.Run(cmd,&out,CP_ACP))\r
2370                 {\r
2371                         CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
2372                         m_bErrorsOccurred=true;\r
2373                         return false;\r
2374                 }\r
2375                 \r
2376 \r
2377                 try\r
2378                 {\r
2379                         tempmergefile = CAppUtils::GetMergeTempFile(_T("LOCAL"),(CTGitPath &)m_targetPathList[i]);\r
2380                         CFile::Remove(tempmergefile);\r
2381                 }catch(...)\r
2382                 {\r
2383                 }\r
2384                 \r
2385                 try\r
2386                 {\r
2387                         tempmergefile = CAppUtils::GetMergeTempFile(_T("REMOTE"),(CTGitPath &)m_targetPathList[i]);\r
2388                         CFile::Remove(tempmergefile);\r
2389                 }catch(...)\r
2390                 {\r
2391                 }\r
2392 \r
2393                 try\r
2394                 {\r
2395                         tempmergefile = CAppUtils::GetMergeTempFile(_T("BASE"),(CTGitPath &)m_targetPathList[i]);\r
2396                         CFile::Remove(tempmergefile);\r
2397                 }catch(...)\r
2398                 {\r
2399                 }\r
2400                 \r
2401 \r
2402                 Notify(m_targetPathList[i],git_wc_notify_resolved);\r
2403         }\r
2404 #if 0\r
2405         if ((m_options & ProgOptSkipConflictCheck) == 0)\r
2406         {\r
2407                 try\r
2408                 {\r
2409                         for (INT_PTR fileindex=0; (fileindex<m_targetPathList.GetCount()) && (bMarkers==FALSE); ++fileindex)\r
2410                         {\r
2411                                 if (!m_targetPathList[fileindex].IsDirectory())\r
2412                                 {\r
2413                                         CStdioFile file(m_targetPathList[fileindex].GetWinPath(), CFile::typeBinary | CFile::modeRead);\r
2414                                         CString strLine = _T("");\r
2415                                         while (file.ReadString(strLine))\r
2416                                         {\r
2417                                                 if (strLine.Find(_T("<<<<<<<"))==0)\r
2418                                                 {\r
2419                                                         bMarkers = TRUE;\r
2420                                                         break;\r
2421                                                 }\r
2422                                         }\r
2423                                         file.Close();\r
2424                                 }\r
2425                         }\r
2426                 } \r
2427                 catch (CFileException* pE)\r
2428                 {\r
2429                         TRACE(_T("CFileException in Resolve!\n"));\r
2430                         TCHAR error[10000] = {0};\r
2431                         pE->GetErrorMessage(error, 10000);\r
2432                         ReportError(error);\r
2433                         pE->Delete();\r
2434                         return false;\r
2435                 }\r
2436         }\r
2437         if (bMarkers)\r
2438         {\r
2439                 if (CMessageBox::Show(m_hWnd, IDS_PROGRS_REVERTMARKERS, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION)==IDYES)\r
2440                 {\r
2441                         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));\r
2442                         for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)\r
2443                                 Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);\r
2444                 }\r
2445         }\r
2446         else\r
2447         {\r
2448                 ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_RESOLVE)));\r
2449                 for (INT_PTR fileindex=0; fileindex<m_targetPathList.GetCount(); ++fileindex)\r
2450                         Resolve(m_targetPathList[fileindex], svn_wc_conflict_choose_merged, true);\r
2451         }\r
2452 #endif\r
2453         CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);\r
2454 \r
2455         return true;\r
2456 }\r
2457 \r
2458 bool CGitProgressDlg::CmdRevert(CString& sWindowTitle, bool& localoperation)\r
2459 {\r
2460 #if 0\r
2461         localoperation = true;\r
2462         sWindowTitle.LoadString(IDS_PROGRS_TITLE_REVERT);\r
2463         SetWindowText(sWindowTitle);\r
2464         SetBackgroundImage(IDI_REVERT_BKG);\r
2465 \r
2466         CTGitPathList delList = m_selectedPaths;\r
2467         if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))\r
2468                 delList.DeleteAllFiles(true);\r
2469 \r
2470         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));\r
2471         if (!Revert(m_targetPathList, CStringArray(), !!(m_options & ProgOptRecursive)))\r
2472         {\r
2473                 ReportSVNError();\r
2474                 return false;\r
2475         }\r
2476         CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);\r
2477 #endif\r
2478         return true;\r
2479 }\r
2480 \r
2481 bool CGitProgressDlg::CmdSwitch(CString& sWindowTitle, bool& /*localoperation*/)\r
2482 {\r
2483 #if 0\r
2484         ASSERT(m_targetPathList.GetCount() == 1);\r
2485         SVNStatus st;\r
2486         sWindowTitle.LoadString(IDS_PROGRS_TITLE_SWITCH);\r
2487         SetWindowText(sWindowTitle);\r
2488         SetBackgroundImage(IDI_SWITCH_BKG);\r
2489         LONG rev = 0;\r
2490         if (st.GetStatus(m_targetPathList[0]) != (-2))\r
2491         {\r
2492                 if (st.status->entry != NULL)\r
2493                 {\r
2494                         rev = st.status->entry->revision;\r
2495                 }\r
2496         }\r
2497 \r
2498         CString sCmdInfo;\r
2499         sCmdInfo.Format(IDS_PROGRS_CMD_SWITCH, \r
2500                 m_targetPathList[0].GetWinPath(), (LPCTSTR)m_url.GetSVNPathString(),\r
2501                 (LPCTSTR)m_Revision.ToString());\r
2502         ReportCmd(sCmdInfo);\r
2503 \r
2504         bool depthIsSticky = true;\r
2505         if (m_depth == svn_depth_unknown)\r
2506                 depthIsSticky = false;\r
2507         if (!Switch(m_targetPathList[0], m_url, m_Revision, m_Revision, m_depth, depthIsSticky, m_options & ProgOptIgnoreExternals))\r
2508         {\r
2509                 ReportSVNError();\r
2510                 return false;\r
2511         }\r
2512         m_UpdateStartRevMap[m_targetPathList[0].GetSVNApiPath(pool)] = rev;\r
2513         if ((m_RevisionEnd >= 0)&&(rev >= 0)\r
2514                 &&((LONG)m_RevisionEnd > (LONG)rev))\r
2515         {\r
2516                 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);\r
2517         }\r
2518 #endif\r
2519         return true;\r
2520 }\r
2521 \r
2522 bool CGitProgressDlg::CmdUnlock(CString& sWindowTitle, bool& /*localoperation*/)\r
2523 {\r
2524 #if 0\r
2525         sWindowTitle.LoadString(IDS_PROGRS_TITLE_UNLOCK);\r
2526         SetWindowText(sWindowTitle);\r
2527         SetBackgroundImage(IDI_UNLOCK_BKG);\r
2528         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UNLOCK)));\r
2529         if (!Unlock(m_targetPathList, m_options & ProgOptLockForce))\r
2530         {\r
2531                 ReportSVNError();\r
2532                 return false;\r
2533         }\r
2534         CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);\r
2535 #endif\r
2536         return true;\r
2537 }\r
2538 \r
2539 bool CGitProgressDlg::CmdUpdate(CString& sWindowTitle, bool& /*localoperation*/)\r
2540 {\r
2541 #if 0\r
2542         sWindowTitle.LoadString(IDS_PROGRS_TITLE_UPDATE);\r
2543         SetWindowText(sWindowTitle);\r
2544         SetBackgroundImage(IDI_UPDATE_BKG);\r
2545 \r
2546         int targetcount = m_targetPathList.GetCount();\r
2547         CString sfile;\r
2548         CStringA uuid;\r
2549         StringRevMap uuidmap;\r
2550         SVNRev revstore = m_Revision;\r
2551         int nUUIDs = 0;\r
2552         for(int nItem = 0; nItem < targetcount; nItem++)\r
2553         {\r
2554                 const CTGitPath& targetPath = m_targetPathList[nItem];\r
2555                 SVNStatus st;\r
2556                 LONG headrev = -1;\r
2557                 m_Revision = revstore;\r
2558                 if (m_Revision.IsHead())\r
2559                 {\r
2560                         if ((targetcount > 1)&&((headrev = st.GetStatus(targetPath, true)) != (-2)))\r
2561                         {\r
2562                                 if (st.status->entry != NULL)\r
2563                                 {\r
2564 \r
2565                                         m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;\r
2566                                         if (st.status->entry->uuid)\r
2567                                         {\r
2568                                                 uuid = st.status->entry->uuid;\r
2569                                                 StringRevMap::iterator iter = uuidmap.lower_bound(uuid);\r
2570                                                 if (iter == uuidmap.end() || iter->first != uuid)\r
2571                                                 {\r
2572                                                         uuidmap.insert(iter, std::make_pair(uuid, headrev));\r
2573                                                         nUUIDs++;\r
2574                                                 }\r
2575                                                 else\r
2576                                                         headrev = iter->second;\r
2577                                                 m_Revision = headrev;\r
2578                                         }\r
2579                                         else\r
2580                                                 m_Revision = headrev;\r
2581                                 }\r
2582                         }\r
2583                         else\r
2584                         {\r
2585                                 if ((headrev = st.GetStatus(targetPath, FALSE)) != (-2))\r
2586                                 {\r
2587                                         if (st.status->entry != NULL)\r
2588                                                 m_UpdateStartRevMap[targetPath.GetSVNApiPath(pool)] = st.status->entry->cmt_rev;\r
2589                                 }\r
2590                         }\r
2591                         if (uuidmap.size() > 1)\r
2592                                 m_Revision = SVNRev::REV_HEAD;\r
2593                 } // if (m_Revision.IsHead()) \r
2594         } // for(int nItem = 0; nItem < targetcount; nItem++) \r
2595         sWindowTitle = m_targetPathList.GetCommonRoot().GetWinPathString()+_T(" - ")+sWindowTitle;\r
2596         SetWindowText(sWindowTitle);\r
2597 \r
2598         DWORD exitcode = 0;\r
2599         CString error;\r
2600         if (CHooks::Instance().PreUpdate(m_targetPathList, m_depth, nUUIDs > 1 ? revstore : m_Revision, exitcode, error))\r
2601         {\r
2602                 if (exitcode)\r
2603                 {\r
2604                         CString temp;\r
2605                         temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);\r
2606                         ReportError(temp);\r
2607                         return false;\r
2608                 }\r
2609         }\r
2610         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_UPDATE)));\r
2611         if (nUUIDs > 1)\r
2612         {\r
2613                 // the selected items are from different repositories,\r
2614                 // so we have to update them separately\r
2615                 for(int nItem = 0; nItem < targetcount; nItem++)\r
2616                 {\r
2617                         const CTGitPath& targetPath = m_targetPathList[nItem];\r
2618                         m_basePath = targetPath;\r
2619                         CString sNotify;\r
2620                         sNotify.Format(IDS_PROGRS_UPDATEPATH, m_basePath.GetWinPath());\r
2621                         ReportString(sNotify, CString(MAKEINTRESOURCE(IDS_WARN_NOTE)));\r
2622                         if (!Update(CTGitPathList(targetPath), revstore, m_depth, TRUE, m_options & ProgOptIgnoreExternals))\r
2623                         {\r
2624                                 ReportSVNError();\r
2625                                 return false;\r
2626                         }\r
2627                 }\r
2628         }\r
2629         else \r
2630         {\r
2631                 // if we have only one target path, but that target path does not exist,\r
2632                 // we have to check whether at least the parent path exists. If not,\r
2633                 // then we have to update all paths in between the first path that exists and the\r
2634                 // parent path of the one we want to update\r
2635                 // This is required so a user can create a sparse checkout without having\r
2636                 // to update all intermediate folders manually\r
2637                 if ((m_targetPathList.GetCount() == 1) && (!m_targetPathList[0].Exists()))\r
2638                 {\r
2639                         CTGitPath wcPath = m_targetPathList[0].GetContainingDirectory();\r
2640                         CTGitPath existingParentPath = wcPath.GetContainingDirectory();\r
2641                         while (!existingParentPath.Exists() && (existingParentPath.GetWinPathString().GetLength() > 2))\r
2642                         {\r
2643                                 existingParentPath = existingParentPath.GetContainingDirectory();\r
2644                         }\r
2645                         if (existingParentPath.GetWinPathString().GetLength() && !existingParentPath.IsEquivalentTo(wcPath))\r
2646                         {\r
2647                                 // update all intermediate directories with depth 'empty'\r
2648                                 CTGitPath intermediatepath = existingParentPath;\r
2649                                 bool bSuccess = true;\r
2650                                 while (bSuccess && intermediatepath.IsAncestorOf(wcPath) && !intermediatepath.IsEquivalentTo(wcPath))\r
2651                                 {\r
2652                                         CString childname = wcPath.GetWinPathString().Mid(intermediatepath.GetWinPathString().GetLength(),\r
2653                                                 wcPath.GetWinPathString().Find('\\', intermediatepath.GetWinPathString().GetLength()+1)-intermediatepath.GetWinPathString().GetLength());\r
2654                                         if (childname.IsEmpty())\r
2655                                                 intermediatepath = wcPath;\r
2656                                         else\r
2657                                                 intermediatepath.AppendPathString(childname);\r
2658                                         bSuccess = !!Update(CTGitPathList(intermediatepath), m_Revision, svn_depth_empty, false, true);\r
2659                                 }\r
2660 \r
2661                                 if (!bSuccess)\r
2662                                 {\r
2663                                         ReportSVNError();\r
2664                                         return false;\r
2665                                 }\r
2666                         }\r
2667                 }\r
2668                 if (!Update(m_targetPathList, m_Revision, m_depth, TRUE, m_options & ProgOptIgnoreExternals))\r
2669                 {\r
2670                         ReportSVNError();\r
2671                         return false;\r
2672                 }\r
2673         }\r
2674         if (CHooks::Instance().PostUpdate(m_targetPathList, m_depth, m_RevisionEnd, exitcode, error))\r
2675         {\r
2676                 if (exitcode)\r
2677                 {\r
2678                         CString temp;\r
2679                         temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);\r
2680                         ReportError(temp);\r
2681                         return false;\r
2682                 }\r
2683         }\r
2684 \r
2685         // after an update, show the user the log button, but only if only one single item was updated\r
2686         // (either a file or a directory)\r
2687         if ((m_targetPathList.GetCount() == 1)&&(m_UpdateStartRevMap.size()>0))\r
2688                 GetDlgItem(IDC_LOGBUTTON)->ShowWindow(SW_SHOW);\r
2689 #endif\r
2690         return true;\r
2691 }\r
2692 \r
2693 void CGitProgressDlg::OnBnClickedNoninteractive()\r
2694 {\r
2695         LRESULT res = ::SendMessage(GetDlgItem(IDC_NONINTERACTIVE)->GetSafeHwnd(), BM_GETCHECK, 0, 0);\r
2696         m_AlwaysConflicted = (res == BST_CHECKED);\r
2697         CRegDWORD nonint = CRegDWORD(_T("Software\\TortoiseGit\\MergeNonInteractive"), FALSE);\r
2698         nonint = m_AlwaysConflicted;\r
2699 }\r
2700 \r
2701 CString CGitProgressDlg::GetPathFromColumnText(const CString& sColumnText)\r
2702 {\r
2703         CString sPath = CPathUtils::ParsePathInString(sColumnText);\r
2704         if (sPath.Find(':')<0)\r
2705         {\r
2706                 // the path is not absolute: add the common root of all paths to it\r
2707                 sPath = m_targetPathList.GetCommonRoot().GetDirectory().GetWinPathString() + _T("\\") + CPathUtils::ParsePathInString(sColumnText);\r
2708         }\r
2709         return sPath;\r
2710 }\r
2711 \r
2712 bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation*/)\r
2713 {\r
2714         sWindowTitle.LoadString(IDS_PROGRS_TITLE_SENDMAIL);\r
2715         SetWindowText(sWindowTitle);\r
2716         //SetBackgroundImage(IDI_ADD_BKG);\r
2717         ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_SENDMAIL)));\r
2718         bool ret=true;\r
2719         if(this->m_SendMailFlags&SENDMAIL_COMBINED)\r
2720         {\r
2721                 CString error;\r
2722                 CTGitPath path;\r
2723                 Notify(path,git_wc_notify_sendmail_start);\r
2724                 CString err;\r
2725                 int retry=0;\r
2726                 while(retry <3)\r
2727                 {\r
2728                         if(CPatch::Send(m_targetPathList,m_SendMailTO,m_SendMailCC,m_SendMailSubject,this->m_SendMailFlags&SENDMAIL_ATTACHMENT,&err))\r
2729                         {\r
2730                                 Notify(path,git_wc_notify_sendmail_error,ret,&err);\r
2731                                 ret = false;\r
2732                         }\r
2733                         else\r
2734                         {\r
2735                                 break;          \r
2736                         }\r
2737 \r
2738                         retry++;\r
2739                         Sleep(2000);\r
2740                         if(m_bCancelled)\r
2741                         {\r
2742                                 Notify(path,git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));\r
2743                             return false;\r
2744                         }\r
2745                 }\r
2746                 Notify(path,git_wc_notify_sendmail_done,ret);\r
2747 \r
2748         }else\r
2749         {\r
2750                 for(int i=0;i<m_targetPathList.GetCount();i++)\r
2751                 {\r
2752                         CPatch patch;\r
2753                         Notify(m_targetPathList[i],git_wc_notify_sendmail_start);\r
2754 \r
2755                         int retry=0;\r
2756                         while(retry<3)\r
2757                         {\r
2758                                 int ret=patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO,\r
2759                                          this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT);\r
2760                                 if(ret)\r
2761                                 {\r
2762                                         Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError);\r
2763                                         ret = false;\r
2764 \r
2765                                 }else\r
2766                                 {\r
2767                                         break;\r
2768                                 }\r
2769                                 Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&patch.m_LastError);\r
2770 \r
2771                                 retry++;\r
2772                                 Sleep(2000);\r
2773                                 if(m_bCancelled)\r
2774                                 {\r
2775                                         Notify(m_targetPathList[i],git_wc_notify_sendmail_retry,ret,&CString("User Canceled"));\r
2776                                     return false;\r
2777                                 }\r
2778                         }\r
2779                         Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret);\r
2780                         \r
2781                 }\r
2782         }\r
2783         return ret;\r
2784 }