Fix warnings
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / ResetProgressCommand.cpp
blobc8d9117ac7acc36f04d05d6d89a20beb9ea04528
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2014 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "ResetProgressCommand.h"
21 #include "AppUtils.h"
22 #include "../TGitCache/CacheInterface.h"
24 bool ResetProgressCommand::Run(CGitProgressList* list, CString& sWindowTitle, int& /*m_itemCountTotal*/, int& /*m_itemCount*/)
26 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_RESET))
28 // should never run to here
29 ASSERT(0);
30 return false;
33 list->SetWindowTitle(IDS_PROGRS_TITLE_RESET, g_Git.m_CurrentDir, sWindowTitle);
34 list->SetBackgroundImage(IDI_UPDATE_BKG);
35 int resetTypesResource[] = { IDS_RESET_SOFT, IDS_RESET_MIXED, IDS_RESET_HARD };
36 list->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_RESET)) + _T(" ") + CString(MAKEINTRESOURCE(resetTypesResource[m_resetType])) + _T(" ") + m_revision);
38 list->ShowProgressBar();
39 CAutoRepository repo(g_Git.GetGitRepository());
40 if (!repo)
42 list->ReportGitError();
43 return false;
46 CGitProgressList::Payload cbpayload = { list, repo };
47 git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
49 CBlockCacheForPath block(g_Git.m_CurrentDir);
50 CAutoObject target;
51 if (git_revparse_single(target.GetPointer(), repo, CUnicodeUtils::GetUTF8(m_revision)))
52 goto error;
53 checkout_options.progress_payload = &cbpayload;
54 checkout_options.progress_cb = [](const char* path, size_t completed_steps, size_t total_steps, void* payload)
56 CGitProgressList::Payload* cbpayload = (CGitProgressList::Payload*)payload;
57 cbpayload->list->m_itemCountTotal = (int)total_steps;
58 cbpayload->list->m_itemCount = (int)completed_steps;
59 cbpayload->list->AddNotify(new CGitProgressList::WC_File_NotificationData(CUnicodeUtils::GetUnicode(path), CGitProgressList::WC_File_NotificationData::git_wc_notify_checkout));
61 if (git_reset(repo, target, (git_reset_t)(m_resetType + 1), &checkout_options, nullptr, nullptr))
62 goto error;
64 // Not setting m_PostCmdCallback here, as clone is only called from AppUtils.cpp
66 return true;
68 error:
69 list->ReportGitError();
70 return false;