-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathfile_data.cc
More file actions
210 lines (190 loc) · 4.57 KB
/
file_data.cc
File metadata and controls
210 lines (190 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
* Copyright (c) 2022 Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
#include "file_data.h"
FileDataStore::FileDataStore()
: actionCategory(FileAction::FileAdd)
, isContentsSet(false)
, isContentsPendingDownload(false)
{
}
FileData::FileData(std::string& depotFile, std::string& revision, std::string& action, std::string& type)
: m_data(std::make_shared<FileDataStore>())
{
m_data->depotFile = depotFile;
m_data->revision = revision;
m_data->SetAction(action);
m_data->type = type;
m_data->isContentsSet = false;
m_data->isContentsPendingDownload = false;
}
FileData::FileData(const FileData& copy)
: m_data(copy.m_data)
{
}
FileData& FileData::operator=(FileData& other)
{
if (this == &other)
{
// guard...
return *this;
}
m_data = other.m_data;
return *this;
}
void FileData::SetFromDepotFile(const std::string& fromDepotFile, const std::string& fromRevision)
{
m_data->fromDepotFile = fromDepotFile;
if (STDHelpers::StartsWith(fromRevision, "#"))
{
m_data->fromRevision = fromRevision.substr(1);
}
else
{
m_data->fromRevision = fromRevision;
}
}
void FileData::MoveContentsOnceFrom(const std::vector<char>& contents)
{
// TODO double-check the thread logic here. It needs to be thread safe.
if (m_data->isContentsSet)
{
// Do not set the contents. Assume that
// they were already set or, worst case, are currently being set.
return;
}
m_data->isContentsSet = true;
m_data->contents = std::move(contents);
m_data->isContentsPendingDownload = false;
}
void FileData::SetPendingDownload()
{
if (!m_data->isContentsSet)
{
m_data->isContentsPendingDownload = true;
}
}
void FileData::SetRelativeDepotPath(const std::string& relativePath)
{
m_data->relativePath = relativePath;
}
bool FileData::IsBinary() const
{
return STDHelpers::Contains(m_data->type, "binary");
}
bool FileData::IsExecutable() const
{
return STDHelpers::Contains(m_data->type, "+x");
}
FileAction extrapolateFileAction(std::string& action);
void FileDataStore::SetAction(std::string fileAction)
{
action = fileAction;
actionCategory = extrapolateFileAction(fileAction);
switch (actionCategory)
{
case FileAction::FileBranch:
case FileAction::FileMoveAdd:
case FileAction::FileIntegrate:
case FileAction::FileImport:
isIntegrated = true;
isDeleted = false;
break;
case FileAction::FileDelete:
case FileAction::FileMoveDelete:
case FileAction::FilePurge:
// Note: not including FileAction::FileArchive
isDeleted = true;
isIntegrated = false;
break;
case FileAction::FileIntegrateDelete:
// This is the source of the integration,
// so even though this causes a delete to happen,
// as a source, there isn't something merging into this
// change.
isIntegrated = false;
isDeleted = true;
break;
default:
isIntegrated = false;
isDeleted = false;
}
}
void FileDataStore::Clear()
{
depotFile.clear();
revision.clear();
action.clear();
type.clear();
fromDepotFile.clear();
fromRevision.clear();
contents.clear();
relativePath.clear();
}
FileAction extrapolateFileAction(std::string& action)
{
if ("add" == action)
{
return FileAction::FileAdd;
}
if ("edit" == action)
{
return FileAction::FileEdit;
}
if ("delete" == action)
{
return FileAction::FileDelete;
}
if ("branch" == action)
{
return FileAction::FileBranch;
}
if ("move/add" == action)
{
return FileAction::FileMoveAdd;
}
if ("move/delete" == action)
{
return FileAction::FileMoveDelete;
}
if ("integrate" == action)
{
return FileAction::FileIntegrate;
}
if ("import" == action)
{
return FileAction::FileImport;
}
if ("purge" == action)
{
return FileAction::FilePurge;
}
if ("archive" == action)
{
return FileAction::FileArchive;
}
if (FAKE_INTEGRATION_DELETE_ACTION_NAME == action)
{
return FileAction::FileIntegrateDelete;
}
// That's all the actions known at the time of writing.
// An unknown type, probably some future Perforce version with a new kind of action.
if (STDHelpers::Contains(action, "delete"))
{
// Looks like a delete.
WARN("Found an unsupported action " << action << "; assuming delete");
return FileAction::FileDelete;
}
if (STDHelpers::Contains(action, "move/"))
{
// Looks like a new kind of integrate.
WARN("Found an unsupported action " << action << "; assuming move/add");
return FileAction::FileMoveAdd;
}
// assume an edit, as it's the safe bet.
WARN("Found an unsupported action " << action << "; assuming edit");
return FileAction::FileEdit;
}