1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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.
21 #include <ATLComTime.h>
22 #include "GitRevLoglist.h"
25 #include "UnicodeUtils.h"
27 typedef CComCritSecLock
<CComCriticalSection
> CAutoLocker
;
29 GitRevLoglist::GitRevLoglist(void)
35 m_IsUpdateing
= FALSE
;
36 m_IsCommitParsed
= FALSE
;
37 m_IsDiffFiles
= FALSE
;
38 m_CallDiffAsync
= nullptr;
39 m_IsSimpleListReady
= FALSE
;
42 SecureZeroMemory(&m_GitCommit
, sizeof(GIT_COMMIT
));
45 GitRevLoglist::~GitRevLoglist(void)
47 if (!m_IsCommitParsed
&& m_GitCommit
.m_pGitCommit
)
48 git_free_commit(&m_GitCommit
);
51 void GitRevLoglist::Clear()
62 int GitRevLoglist::SafeGetSimpleList(CGit
* git
)
64 if (InterlockedExchange(&m_IsUpdateing
, TRUE
) == TRUE
)
67 m_SimpleFileList
.clear();
68 git
->CheckAndInitDll();
69 GIT_COMMIT commit
= { 0 };
73 CAutoLocker
lock(g_Git
.m_critGitDllSec
);
77 if (git_get_commit_from_hash(&commit
, m_CommitHash
.m_hash
))
86 bool isRoot
= m_ParentHash
.empty();
87 git_get_commit_first_parent(&commit
, &list
);
88 while (git_get_commit_next_parent(&list
, parent
) == 0 || isRoot
)
95 git_root_diff(git
->GetGitSimpleListDiff(), commit
.m_hash
, &file
, &count
, 0);
97 git_do_diff(git
->GetGitSimpleListDiff(), parent
, commit
.m_hash
, &file
, &count
, 0);
106 for (int j
= 0; j
< count
; ++j
)
110 int mode
, IsBin
, inc
, dec
;
114 git_get_diff_file(git
->GetGitSimpleListDiff(), file
, j
, &newname
, &oldname
, &mode
, &IsBin
, &inc
, &dec
);
121 m_SimpleFileList
.push_back(CUnicodeUtils::GetUnicode(newname
));
124 git_diff_flush(git
->GetGitSimpleListDiff());
128 InterlockedExchange(&m_IsUpdateing
, FALSE
);
129 InterlockedExchange(&m_IsSimpleListReady
, TRUE
);
130 git_free_commit(&commit
);
135 int GitRevLoglist::SafeFetchFullInfo(CGit
* git
)
137 if (InterlockedExchange(&m_IsUpdateing
, TRUE
) == TRUE
)
141 git
->CheckAndInitDll();
142 GIT_COMMIT commit
= { 0 };
143 GIT_COMMIT_LIST list
;
146 CAutoLocker
lock(g_Git
.m_critGitDllSec
);
150 if (git_get_commit_from_hash(&commit
, m_CommitHash
.m_hash
))
159 git_get_commit_first_parent(&commit
, &list
);
160 bool isRoot
= (list
== nullptr);
162 while (git_get_commit_next_parent(&list
, parent
) == 0 || isRoot
)
170 git_root_diff(git
->GetGitDiff(), m_CommitHash
.m_hash
, &file
, &count
, 1);
172 git_do_diff(git
->GetGitDiff(), parent
, commit
.m_hash
, &file
, &count
, 1);
176 git_free_commit(&commit
);
185 for (int j
= 0; j
< count
; ++j
)
194 int mode
, IsBin
, inc
, dec
;
195 git_get_diff_file(git
->GetGitDiff(), file
, j
, &newname
, &oldname
, &mode
, &IsBin
, &inc
, &dec
);
197 git
->StringAppend(&strnewname
, (BYTE
*)newname
, CP_UTF8
);
198 git
->StringAppend(&stroldname
, (BYTE
*)oldname
, CP_UTF8
);
200 path
.SetFromGit(strnewname
, &stroldname
);
201 path
.ParserAction((BYTE
)mode
);
204 m_Action
|= path
.m_Action
;
208 path
.m_StatAdd
= _T("-");
209 path
.m_StatDel
= _T("-");
213 path
.m_StatAdd
.Format(_T("%d"), inc
);
214 path
.m_StatDel
.Format(_T("%d"), dec
);
216 m_Files
.AddPath(path
);
218 git_diff_flush(git
->GetGitDiff());
222 InterlockedExchange(&m_IsUpdateing
, FALSE
);
223 InterlockedExchange(&m_IsFull
, TRUE
);
224 git_free_commit(&commit
);