Skip to content

Commit

Permalink
#5662: Display the VCS revision in the merge dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 18, 2021
1 parent 5dacca8 commit a766479
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
9 changes: 8 additions & 1 deletion include/imapmerge.h
Expand Up @@ -132,14 +132,21 @@ class IConflictResolutionAction :
};

// A MergeOperation groups one or more merge actions
// together in order to apply a set of changes from source => base
// together in order to apply a set of changes from source => target
class IMergeOperation
{
public:
using Ptr = std::shared_ptr<IMergeOperation>;

virtual ~IMergeOperation() {}

// Returns the name/path of the source scene (or a string resembling it)
virtual std::string getSourcePath() = 0;

// Returns the name/path of the base scene (or a string resembling it)
// Will return an empty string if there is no base scene defined
virtual std::string getBasePath() = 0;

// Executes all active actions defined in this operation
virtual void applyActions() = 0;

Expand Down
10 changes: 10 additions & 0 deletions libs/scene/merge/MergeOperation.cpp
Expand Up @@ -54,6 +54,16 @@ MergeOperation::Ptr MergeOperation::CreateFromComparisonResult(const ComparisonR
return operation;
}

std::string MergeOperation::getSourcePath()
{
return _sourceRoot->getRootNode()->name();
}

std::string MergeOperation::getBasePath()
{
return std::string(); // no base
}

void MergeOperation::applyActions()
{
MergeOperationBase::applyActions();
Expand Down
3 changes: 3 additions & 0 deletions libs/scene/merge/MergeOperation.h
Expand Up @@ -40,6 +40,9 @@ class MergeOperation :
// The operation will (on application) change the base map such that it matches the source map.
static Ptr CreateFromComparisonResult(const ComparisonResult& comparisonResult);

std::string getSourcePath() override;
std::string getBasePath() override;

// Executes all active actions defined in this operation
void applyActions() override;

Expand Down
10 changes: 10 additions & 0 deletions libs/scene/merge/ThreeWayMergeOperation.cpp
Expand Up @@ -391,6 +391,16 @@ void ThreeWayMergeOperation::adjustSourceEntitiesWithNameConflicts()
_targetRoot->getNamespace()->ensureNoConflicts(_sourceRoot, sourceEntitiesToBeRenamed);
}

std::string ThreeWayMergeOperation::getSourcePath()
{
return _sourceRoot->getRootNode()->name();
}

std::string ThreeWayMergeOperation::getBasePath()
{
return _baseRoot->getRootNode()->name();
}

void ThreeWayMergeOperation::applyActions()
{
MergeOperationBase::applyActions();
Expand Down
3 changes: 3 additions & 0 deletions libs/scene/merge/ThreeWayMergeOperation.h
Expand Up @@ -57,6 +57,9 @@ class ThreeWayMergeOperation :
return _targetRoot;
}

std::string getSourcePath() override;
std::string getBasePath() override;

void applyActions() override;

private:
Expand Down
30 changes: 25 additions & 5 deletions radiant/ui/merge/MergeControlDialog.cpp
Expand Up @@ -376,8 +376,28 @@ void MergeControlDialog::updateControls()

auto selectedMergeNodes = scene::merge::getSelectedMergeNodes();
bool mergeInProgress = GlobalMapModule().getEditMode() == IMap::EditMode::Merge;
auto baseMapPath = findNamedObject<wxutil::PathEntry>(this, "BaseMapFilename")->getValue();
auto sourceMapPath = findNamedObject<wxutil::PathEntry>(this, "MergeMapFilename")->getValue();

auto baseMapPathEntry = findNamedObject<wxutil::PathEntry>(this, "BaseMapFilename");
auto sourceMapPathEntry = findNamedObject<wxutil::PathEntry>(this, "MergeMapFilename");

auto baseMapPath = baseMapPathEntry->getValue();
auto sourceMapPath = sourceMapPathEntry->getValue();

// Fill in the map names in case the merge operation has already been started by the time the dialog is shown
if (mergeInProgress)
{
if (baseMapPath.empty() && GlobalMapModule().getActiveMergeOperation())
{
baseMapPath = GlobalMapModule().getActiveMergeOperation()->getBasePath();
baseMapPathEntry->setValue(baseMapPath);
}

if (sourceMapPath.empty() && GlobalMapModule().getActiveMergeOperation())
{
sourceMapPath = GlobalMapModule().getActiveMergeOperation()->getSourcePath();
sourceMapPathEntry->setValue(sourceMapPath);
}
}

findNamedObject<wxWindow>(this, "TwoWayMode")->Enable(!mergeInProgress);
findNamedObject<wxWindow>(this, "ThreeWayMode")->Enable(!mergeInProgress);
Expand All @@ -387,8 +407,8 @@ void MergeControlDialog::updateControls()
findNamedObject<wxButton>(this, "LoadAndCompareButton")->Enable(!mergeInProgress && !sourceMapPath.empty() &&
(!isInThreeWayMergeMode() || !baseMapPath.empty()));
findNamedObject<wxWindow>(this, "SummaryPanel")->Enable(mergeInProgress);
findNamedObject<wxWindow>(this, "BaseMapFilename")->Enable(!mergeInProgress);
findNamedObject<wxWindow>(this, "MergeMapFilename")->Enable(!mergeInProgress);
baseMapPathEntry->Enable(!mergeInProgress);
sourceMapPathEntry->Enable(!mergeInProgress);

auto actionDescriptionPanel = findNamedObject<wxPanel>(this, "ActionDescriptionPanel");

Expand Down Expand Up @@ -490,7 +510,7 @@ void MergeControlDialog::OnMapEditModeChanged(IMap::EditMode mode)
{
// When switching to merge mode, make sure the dialog is shown

if (!InstancePtr() && mode == IMap::EditMode::Merge)
if (mode == IMap::EditMode::Merge && (!InstancePtr() || !Instance().IsShown()))
{
Instance().Show();
return;
Expand Down
16 changes: 16 additions & 0 deletions radiantcore/map/VcsMapResource.cpp
Expand Up @@ -5,6 +5,7 @@
#include "VersionControlLib.h"
#include "stream/VcsMapResourceStream.h"
#include "os/fs.h"
#include <fmt/format.h>

namespace map
{
Expand All @@ -29,6 +30,21 @@ VcsMapResource::VcsMapResource(const std::string& mapFileUri) :
_infoFileUri = vcs::constructVcsFileUri(prefix, vcs::getVcsRevision(_mapFileUri), infoFilePath);
}

bool VcsMapResource::load()
{
auto result = MapResource::load();

if (result)
{
// Set the name string to contain the revision of the map
auto mapName = fmt::format("{0}@{1}", os::getFilename(vcs::getVcsFilePath(_mapFileUri)),
vcs::getVcsRevision(_mapFileUri).substr(0, 7));
getRootNode()->setName(mapName);
}

return result;
}

bool VcsMapResource::isReadOnly()
{
return true;
Expand Down
1 change: 1 addition & 0 deletions radiantcore/map/VcsMapResource.h
Expand Up @@ -19,6 +19,7 @@ class VcsMapResource :
public:
VcsMapResource(const std::string& mapFileUri);

virtual bool load() override;
virtual bool isReadOnly() override;
virtual void save(const MapFormatPtr& mapFormat = MapFormatPtr()) override;

Expand Down

0 comments on commit a766479

Please sign in to comment.