Do not use GitAdminDir objects
[TortoiseGit.git] / src / TortoiseProc / Commands / LogCommand.cpp
blobfd316253cdc1299ed71bbc3666c2b6a090863ba7
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008,2011 - TortoiseSVN
4 // Copyright (C) 2008-2015 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "LogCommand.h"
22 #include "StringUtils.h"
23 #include "LogDlg.h"
24 #include "MessageBox.h"
26 bool LogCommand::Execute()
28 if (!GitAdminDir::HasAdminDir(g_Git.m_CurrentDir) && !GitAdminDir::IsBareRepo(g_Git.m_CurrentDir)) {
29 CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR);
30 return false;
33 //the log command line looks like this:
34 //command:log path:<path_to_file_or_directory_to_show_the_log_messages> [startrev:<startrevision>] [endrev:<endrevision>]
36 CString range;
38 CString revstart = parser.GetVal(_T("startrev"));
39 if (revstart.IsEmpty())
41 // support deprecated parameter prior 1.5.0
42 revstart = parser.GetVal(_T("revstart"));
44 if (revstart == GIT_REV_ZERO)
45 revstart.Empty();
46 if (!revstart.IsEmpty())
47 range.Format(_T("%s.."), g_Git.FixBranchName(revstart));
49 CString revend = parser.GetVal(_T("endrev"));
50 if (revend.IsEmpty())
52 // support deprecated parameter prior 1.5.0
53 revend = parser.GetVal(_T("revend"));
55 if (revend == GIT_REV_ZERO)
56 revend.Empty();
57 if (!revend.IsEmpty())
58 range += g_Git.FixBranchName(revend);
60 if (parser.HasVal(_T("range")))
61 range = parser.GetVal(_T("range"));
63 CString val = parser.GetVal(_T("limit"));
64 int limit = _tstoi(val);
65 CString rev = parser.GetVal(_T("rev"));
67 if (limit == 0)
69 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
70 limit = (int)(LONG)reg;
73 CString findStr = parser.GetVal(_T("findstring"));
74 LONG findType = parser.GetLongVal(_T("findtype"));
75 bool findRegex = !!CRegDWORD(_T("Software\\TortoiseGit\\UseRegexFilter"), FALSE);
76 if (parser.HasKey(_T("findtext")))
77 findRegex = false;
78 if (parser.HasKey(_T("findregex")))
79 findRegex = true;
81 CLogDlg dlg;
82 theApp.m_pMainWnd = &dlg;
83 dlg.SetParams(orgCmdLinePath, cmdLinePath, rev, range, limit);
84 dlg.SetFilter(findStr, findType, findRegex);
85 if (parser.HasVal(_T("outfile")))
87 dlg.SetSelect(true);
88 dlg.SingleSelection(true);
90 dlg.DoModal();
91 if (parser.HasVal(_T("outfile")))
93 CString sText = dlg.GetSelectedHash();
94 CStringUtils::WriteStringToTextFile(parser.GetVal(L"outfile"), (LPCTSTR)sText, true);
96 return true;