Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions p4-fusion/commands/file_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ bool FileData::IsExecutable() const
return STDHelpers::Contains(m_data->type, "+x");
}

bool FileData::IsSymlink() const
{
return STDHelpers::Contains(m_data->type, "+l") || STDHelpers::Contains(m_data->type, "symlink");
}

FileAction extrapolateFileAction(std::string& action);

void FileDataStore::SetAction(std::string fileAction)
Expand Down
2 changes: 2 additions & 0 deletions p4-fusion/commands/file_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ struct FileData

bool IsBinary() const;
bool IsExecutable() const;
bool IsSymlink() const;


void Clear() { m_data->Clear(); };
};
32 changes: 24 additions & 8 deletions p4-fusion/git_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,36 @@ void GitAPI::CreateIndex()
}
}

void GitAPI::AddFileToIndex(const std::string& relativePath, const std::vector<char>& contents, const bool plusx)
void GitAPI::AddFileToIndex(const std::string& relativePath, const std::vector<char>& contents, const bool plusx, const bool isSymlink)
{
MTR_SCOPE("Git", __func__);

git_index_entry entry = {};
entry.mode = GIT_FILEMODE_BLOB;
if (plusx)

if (isSymlink)
{
entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE; // 0100755
entry.mode = GIT_FILEMODE_LINK; // 0120000

std::vector<char> cleanedContents = contents;
while (!cleanedContents.empty() && (cleanedContents.back() == '\n' || cleanedContents.back() == '\r'))
{
cleanedContents.pop_back();
}

entry.path = relativePath.c_str();
GIT2(git_index_add_from_buffer(m_Index, &entry, cleanedContents.data(), cleanedContents.size()));
}
else
{
entry.mode = GIT_FILEMODE_BLOB;
if (plusx)
{
entry.mode = GIT_FILEMODE_BLOB_EXECUTABLE; // 0100755
}

entry.path = relativePath.c_str();
GIT2(git_index_add_from_buffer(m_Index, &entry, contents.data(), contents.size()));
}

entry.path = relativePath.c_str();

GIT2(git_index_add_from_buffer(m_Index, &entry, contents.data(), contents.size()));
}

void GitAPI::RemoveFileFromIndex(const std::string& relativePath)
Expand Down
2 changes: 1 addition & 1 deletion p4-fusion/git_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GitAPI

void CreateIndex();
void SetActiveBranch(const std::string& branchName);
void AddFileToIndex(const std::string& relativePath, const std::vector<char>& contents, const bool plusx);
void AddFileToIndex(const std::string& relativePath, const std::vector<char>& contents, const bool plusx, const bool isSymlink = false);
void RemoveFileFromIndex(const std::string& relativePath);

std::string Commit(
Expand Down
2 changes: 1 addition & 1 deletion p4-fusion/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ int Main(int argc, char** argv)
}
else
{
git.AddFileToIndex(file.GetRelativePath(), file.GetContents(), file.IsExecutable());
git.AddFileToIndex(file.GetRelativePath(), file.GetContents(), file.IsExecutable(), file.IsSymlink());
}

// No use for keeping the contents in memory once it has been added
Expand Down