This repository has been archived on 2021-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
Bookworm/Plugins/UE4GitPlugin-2.17-beta/Source/GitSourceControl/Private/GitSourceControlRevision.cpp

115 lines
3.0 KiB
C++
Raw Normal View History

2021-11-17 11:35:23 +00:00
// Copyright (c) 2014-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
//
// Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
// or copy at http://opensource.org/licenses/MIT)
#include "GitSourceControlRevision.h"
#include "HAL/FileManager.h"
#include "Misc/Paths.h"
#include "Modules/ModuleManager.h"
#include "GitSourceControlModule.h"
#include "GitSourceControlUtils.h"
#define LOCTEXT_NAMESPACE "GitSourceControl"
bool FGitSourceControlRevision::Get( FString& InOutFilename ) const
{
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
const FString PathToGitBinary = GitSourceControl.AccessSettings().GetBinaryPath();
const FString PathToRepositoryRoot = GitSourceControl.GetProvider().GetPathToRepositoryRoot();
// if a filename for the temp file wasn't supplied generate a unique-ish one
if(InOutFilename.Len() == 0)
{
// create the diff dir if we don't already have it (Git wont)
IFileManager::Get().MakeDirectory(*FPaths::DiffDir(), true);
// create a unique temp file name based on the unique commit Id
const FString TempFileName = FString::Printf(TEXT("%stemp-%s-%s"), *FPaths::DiffDir(), *CommitId, *FPaths::GetCleanFilename(Filename));
InOutFilename = FPaths::ConvertRelativePathToFull(TempFileName);
}
// Diff against the revision
const FString Parameter = FString::Printf(TEXT("%s:%s"), *CommitId, *Filename);
bool bCommandSuccessful;
if(FPaths::FileExists(InOutFilename))
{
bCommandSuccessful = true; // if the temp file already exists, reuse it directly
}
else
{
bCommandSuccessful = GitSourceControlUtils::RunDumpToFile(PathToGitBinary, PathToRepositoryRoot, Parameter, InOutFilename);
}
return bCommandSuccessful;
}
bool FGitSourceControlRevision::GetAnnotated( TArray<FAnnotationLine>& OutLines ) const
{
return false;
}
bool FGitSourceControlRevision::GetAnnotated( FString& InOutFilename ) const
{
return false;
}
const FString& FGitSourceControlRevision::GetFilename() const
{
return Filename;
}
int32 FGitSourceControlRevision::GetRevisionNumber() const
{
return RevisionNumber;
}
const FString& FGitSourceControlRevision::GetRevision() const
{
return ShortCommitId;
}
const FString& FGitSourceControlRevision::GetDescription() const
{
return Description;
}
const FString& FGitSourceControlRevision::GetUserName() const
{
return UserName;
}
const FString& FGitSourceControlRevision::GetClientSpec() const
{
static FString EmptyString(TEXT(""));
return EmptyString;
}
const FString& FGitSourceControlRevision::GetAction() const
{
return Action;
}
TSharedPtr<class ISourceControlRevision, ESPMode::ThreadSafe> FGitSourceControlRevision::GetBranchSource() const
{
// if this revision was copied/moved from some other revision
return BranchSource;
}
const FDateTime& FGitSourceControlRevision::GetDate() const
{
return Date;
}
int32 FGitSourceControlRevision::GetCheckInIdentifier() const
{
return CommitIdNumber;
}
int32 FGitSourceControlRevision::GetFileSize() const
{
return FileSize;
}
#undef LOCTEXT_NAMESPACE