Skip to content

Commit dd837c9

Browse files
committed
isolated diff2stat utility for customization
1 parent 8481e24 commit dd837c9

File tree

6 files changed

+129
-60
lines changed

6 files changed

+129
-60
lines changed

source/P4VFS.Core/Include/DepotClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace P4 {
114114
template <typename Result>
115115
Result FDepotClient::Run(const DepotCommand& cmd)
116116
{
117-
Result result = std::make_shared<Result::element_type>();
117+
Result result = MakeResult<Result>();
118118
Run(cmd, *result.get());
119119
return result;
120120
}

source/P4VFS.Core/Include/DepotOperations.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ namespace P4 {
147147
CreateFileSpecFlags::Enum flags = CreateFileSpecFlags::None
148148
);
149149

150+
static DepotResultDiff2
151+
DepotOperations::Diff2Stat(
152+
DepotClient& depotClient,
153+
DepotSyncFlags::Enum syncFlags,
154+
const DepotStringArray& fileSpecs,
155+
const DepotSyncActionInfoArray& fileModifications
156+
);
157+
150158
static DepotResultDiff2
151159
Diff2(
152160
DepotClient& depotClient,

source/P4VFS.Core/Include/DepotResult.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ namespace P4 {
8080
P4VFS_CORE_API const Array<DepotResultTag>& TagList() const;
8181
P4VFS_CORE_API const Array<DepotResultText>& TextList() const;
8282
const DepotString& GetTagValue(const DepotString& tagKey) const;
83+
84+
void Append(const FDepotResult& src);
85+
void Append(const Array<DepotResultTag>& srcTagList);
86+
void Append(const Array<DepotResultText>& srcTextList);
8387

8488
protected:
8589
friend class DepotClientCommand;
@@ -162,6 +166,20 @@ namespace P4 {
162166
return FDepotResultNode::Create<NodeType>(index < m_TagList.size() ? m_TagList[index] : nullptr);
163167
}
164168
};
169+
170+
template <typename Result>
171+
Result MakeResult()
172+
{
173+
return std::make_shared<Result::element_type>();
174+
}
175+
176+
template <typename Result>
177+
Result MakeErrorResult(const DepotString& errorText)
178+
{
179+
Result result = MakeResult<Result>();
180+
result->SetError(errorText.c_str());
181+
return result;
182+
}
165183
}}}
166184

167185
#pragma managed(pop)

source/P4VFS.Core/Include/SettingManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace FileCore {
3131
_N( int32_t, PoolDefaultNumberOfThreads, 8 ) \
3232
_N( int32_t, GarbageCollectPeriodMs, 5*60*1000 ) \
3333
_N( int32_t, DepotClientCacheIdleTimeoutMs, 5*60*1000 ) \
34+
_N( int32_t, MaxDiff2StatFileCount, 0 ) \
3435

3536

3637
class SettingManager;
@@ -82,7 +83,7 @@ namespace FileCore {
8283
P4VFS_CORE_API void SetInt32(int32_t value);
8384
P4VFS_CORE_API void SetString(const String& value);
8485

85-
template <typename T> T Get(const T& defaultValue) const = 0;
86+
template <typename T> T Get(const T& defaultValue) const;
8687
template <> bool Get<bool>(const bool& defaultValue) const { return GetBool(defaultValue); }
8788
template <> int32_t Get<int32_t>(const int32_t& defaultValue) const { return GetInt32(defaultValue); }
8889
template <> String Get<String>(const String& defaultValue) const { return GetString(defaultValue); }

source/P4VFS.Core/Source/DepotOperations.cpp

Lines changed: 84 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -833,64 +833,6 @@ DepotOperations::SyncCommand(
833833
return nullptr;
834834
}
835835

836-
typedef HashSet<DepotString, StringInfo::EqualInsensitive> DepotFileHashSet;
837-
typedef Map<DepotString, FDepotResultSizesNode, StringInfo::LessInsensitive> DepotFileClientSizeMapType;
838-
839-
DepotFileHashSet writeableHeadDepotFiles;
840-
DepotFileHashSet writeableHaveDepotFiles;
841-
DepotFileHashSet symlinkDepotFiles;
842-
DepotFileHashSet diffDepotFiles;
843-
DepotFileClientSizeMapType depotFileClientSizeMap;
844-
845-
if ((syncFlags & (DepotSyncFlags::Preview | DepotSyncFlags::Flush)) != 0 && (syncFlags & DepotSyncFlags::IgnoreOutput) == 0)
846-
{
847-
DepotRevision haveRevision = (syncFlags & DepotSyncFlags::Force) ? FDepotRevision::New<FDepotRevisionNone>() : FDepotRevision::New<FDepotRevisionHave>();
848-
for (const DepotString& fileSpec : fileSpecs)
849-
{
850-
const DepotString haveFileSpec = CreateFileSpec(fileSpec, haveRevision, CreateFileSpecFlags::OverrideRevison);
851-
if (haveFileSpec.empty())
852-
{
853-
reportError(StringInfo::Format("Invalid haveFileSpec for fileSpec='%s' rev='%s'", fileSpec.c_str(), FDepotRevision::ToString(haveRevision).c_str()));
854-
return nullptr;
855-
}
856-
857-
const DepotString& headFileSpec = fileSpec;
858-
if (headFileSpec.empty())
859-
{
860-
reportError(StringInfo::Format("Invalid headFileSpec for fileSpec='%s' rev='%s'", fileSpec.c_str(), FDepotRevision::ToString(revision).c_str()));
861-
return nullptr;
862-
}
863-
864-
DepotResultDiff2 diff2 = Diff2(depotClient, haveFileSpec, headFileSpec);
865-
for (size_t diff2NodeIndex = 0; diff2NodeIndex < diff2->NodeCount(); ++diff2NodeIndex)
866-
{
867-
FDepotResultDiff2Node node = diff2->Node(diff2NodeIndex);
868-
diffDepotFiles.insert(node.DepotFile());
869-
diffDepotFiles.insert(node.DepotFile2());
870-
871-
if (DepotInfo::IsWritableFileType(node.Type()))
872-
writeableHaveDepotFiles.insert(node.DepotFile());
873-
if (DepotInfo::IsWritableFileType(node.Type2()))
874-
writeableHeadDepotFiles.insert(node.DepotFile2());
875-
876-
if (DepotInfo::IsSymlinkFileType(node.Type()))
877-
symlinkDepotFiles.insert(node.DepotFile());
878-
if (DepotInfo::IsSymlinkFileType(node.Type2()))
879-
symlinkDepotFiles.insert(node.DepotFile2());
880-
}
881-
882-
if ((syncFlags & DepotSyncFlags::ClientSize) != 0 && depotClient->GetServerApiLevel() >= DepotProtocol::SERVER_SIZES_C)
883-
{
884-
DepotResultSizes sizes = Sizes(depotClient, headFileSpec, SizesFlags::ClientSize);
885-
for (size_t sizesNodeIndex = 0; sizesNodeIndex < sizes->NodeCount(); ++sizesNodeIndex)
886-
{
887-
FDepotResultSizesNode node = sizes->Node(sizesNodeIndex);
888-
depotFileClientSizeMap[node.DepotFile()] = node;
889-
}
890-
}
891-
}
892-
}
893-
894836
DepotClientLogCallback onClientLogCallback = std::make_shared<FDepotClientLogCallback>([log](LogChannel::Enum channel, const char* severity, const char* text) -> void
895837
{
896838
if (log != nullptr)
@@ -972,6 +914,55 @@ DepotOperations::SyncCommand(
972914
}
973915
}
974916

917+
typedef HashSet<DepotString, StringInfo::EqualInsensitive> DepotFileHashSet;
918+
typedef Map<DepotString, FDepotResultSizesNode, StringInfo::LessInsensitive> DepotFileClientSizeMapType;
919+
920+
DepotFileHashSet writeableHeadDepotFiles;
921+
DepotFileHashSet writeableHaveDepotFiles;
922+
DepotFileHashSet symlinkDepotFiles;
923+
DepotFileHashSet diffDepotFiles;
924+
DepotFileClientSizeMapType depotFileClientSizeMap;
925+
926+
if (syncFlags & (DepotSyncFlags::Preview | DepotSyncFlags::Flush))
927+
{
928+
DepotResultDiff2 diff2 = Diff2Stat(depotClient, syncFlags, fileSpecs, modifications);
929+
if (diff2.get() == nullptr || diff2->HasError())
930+
{
931+
reportError(StringInfo::Format("Failed get filetype differences. %s", diff2.get() ? diff2->GetError().c_str() : "Invalid result"));
932+
return nullptr;
933+
}
934+
935+
for (size_t diff2NodeIndex = 0; diff2NodeIndex < diff2->NodeCount(); ++diff2NodeIndex)
936+
{
937+
FDepotResultDiff2Node node = diff2->Node(diff2NodeIndex);
938+
diffDepotFiles.insert(node.DepotFile());
939+
diffDepotFiles.insert(node.DepotFile2());
940+
941+
if (DepotInfo::IsWritableFileType(node.Type()))
942+
writeableHaveDepotFiles.insert(node.DepotFile());
943+
if (DepotInfo::IsWritableFileType(node.Type2()))
944+
writeableHeadDepotFiles.insert(node.DepotFile2());
945+
946+
if (DepotInfo::IsSymlinkFileType(node.Type()))
947+
symlinkDepotFiles.insert(node.DepotFile());
948+
if (DepotInfo::IsSymlinkFileType(node.Type2()))
949+
symlinkDepotFiles.insert(node.DepotFile2());
950+
}
951+
952+
for (const DepotString& fileSpec : fileSpecs)
953+
{
954+
if ((syncFlags & DepotSyncFlags::ClientSize) != 0 && depotClient->GetServerApiLevel() >= DepotProtocol::SERVER_SIZES_C)
955+
{
956+
DepotResultSizes sizes = Sizes(depotClient, fileSpec, SizesFlags::ClientSize);
957+
for (size_t sizesNodeIndex = 0; sizesNodeIndex < sizes->NodeCount(); ++sizesNodeIndex)
958+
{
959+
FDepotResultSizesNode node = sizes->Node(sizesNodeIndex);
960+
depotFileClientSizeMap[node.DepotFile()] = node;
961+
}
962+
}
963+
}
964+
}
965+
975966
typedef Map<DepotString, FDepotResultFStatNode, StringInfo::LessInsensitive> OpenedHeadDepotFilesType;
976967
OpenedHeadDepotFilesType openedHeadDepotFiles;
977968

@@ -1159,6 +1150,41 @@ DepotOperations::CreateFileSpecs(
11591150
return fileSpecs;
11601151
}
11611152

1153+
DepotResultDiff2
1154+
DepotOperations::Diff2Stat(
1155+
DepotClient& depotClient,
1156+
DepotSyncFlags::Enum syncFlags,
1157+
const DepotStringArray& fileSpecs,
1158+
const DepotSyncActionInfoArray& fileModifications
1159+
)
1160+
{
1161+
DepotResultDiff2 diff2stat = MakeResult<DepotResultDiff2>();
1162+
1163+
DepotRevision haveRevision = (syncFlags & DepotSyncFlags::Force) ? FDepotRevision::New<FDepotRevisionNone>() : FDepotRevision::New<FDepotRevisionHave>();
1164+
for (const DepotString& fileSpec : fileSpecs)
1165+
{
1166+
const DepotString haveFileSpec = CreateFileSpec(fileSpec, haveRevision, CreateFileSpecFlags::OverrideRevison);
1167+
if (haveFileSpec.empty())
1168+
{
1169+
return MakeErrorResult<DepotResultDiff2>(StringInfo::Format("Invalid haveFileSpec for fileSpec='%s' rev='%s'", fileSpec.c_str(), FDepotRevision::ToString(haveRevision).c_str()));
1170+
}
1171+
1172+
const DepotString& headFileSpec = fileSpec;
1173+
if (headFileSpec.empty())
1174+
{
1175+
return MakeErrorResult<DepotResultDiff2>(StringInfo::Format("Invalid headFileSpec for fileSpec='%s'", fileSpec.c_str()));
1176+
}
1177+
1178+
DepotResultDiff2 diff2 = Diff2(depotClient, haveFileSpec, headFileSpec);
1179+
if (diff2.get())
1180+
{
1181+
diff2stat->Append(diff2->TagList());
1182+
}
1183+
}
1184+
1185+
return diff2stat;
1186+
}
1187+
11621188
DepotResultDiff2
11631189
DepotOperations::Diff2(
11641190
DepotClient& depotClient,

source/P4VFS.Core/Source/DepotResult.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,20 @@ const DepotString& FDepotResult::GetTagValue(const DepotString& tagKey) const
185185
return StringInfo::EmptyA();
186186
}
187187

188+
void FDepotResult::Append(const FDepotResult& src)
189+
{
190+
Append(src.m_TagList);
191+
Append(src.m_TextList);
192+
}
193+
194+
void FDepotResult::Append(const Array<DepotResultTag>& srcTagList)
195+
{
196+
Algo::Append(m_TagList, srcTagList);
197+
}
198+
199+
void FDepotResult::Append(const Array<DepotResultText>& srcTextList)
200+
{
201+
Algo::Append(m_TextList, srcTextList);
202+
}
203+
188204
}}}

0 commit comments

Comments
 (0)