Skip to content

Commit

Permalink
- embed git commit in snippet and print the git info when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Sep 17, 2024
1 parent 73b8ddd commit 694571c
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 50 deletions.
2 changes: 1 addition & 1 deletion currentGitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
88855207086c850b13d2f4479791532d76b9adb7
73b8ddd08adf0d86ab70dcf464adaf9d5c604e41
66 changes: 65 additions & 1 deletion hi_backend/backend/BackendApplicationCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,32 @@ void BackendCommandTarget::Actions::loadSnippet(BackendRootWindow* bpe, const St

if (v.isValid())
{
auto hash = v["Hash"].toString();

WeakReference<Processor> safeP(bpe->getMainSynthChain());

if(hash.isNotEmpty())
{
GitHashManager::checkHash(hash, [safeP](const var& commitObj)
{
String message;

auto hash = commitObj["sha"].toString();

auto date = commitObj["commit"]["author"]["date"].toString();

auto d = Time::fromISO8601(date);

message << "Snippet loaded that was created with git commit \n";
message << "> hash: " << hash.substring(0, 8) << "\n";
message << "> date: " << d.toString(true, true, false, true) << "\n";
message << "> message: " << commitObj["commit"]["message"].toString() << "\n";
message << "> url: " << "https://github.com/christophhart/HISE/commit/" << hash;

debugToConsole(safeP, message);
});
}

bpe->loadNewContainer(v);
}
}
Expand Down Expand Up @@ -1687,7 +1713,9 @@ String BackendCommandTarget::Actions::exportFileAsSnippet(BackendRootWindow* bpe
MainController::ScopedEmbedAllResources sd(bp);

ValueTree v = bp->getMainSynthChain()->exportAsValueTree();


v.setProperty("Hash", String(PREVIOUS_HISE_COMMIT), nullptr);

auto scriptRootFolder = bp->getCurrentFileHandler().getSubDirectory(FileHandlerBase::Scripts);
auto snexRootFolder = BackendDllManager::getSubFolder(bp, BackendDllManager::FolderSubType::CodeLibrary);

Expand Down Expand Up @@ -3381,4 +3409,40 @@ String XmlBackupFunctions::getSanitiziedName(const String &id)
return id.removeCharacters(" .()");
}

void GitHashManager::checkHash(const String& hashToUse,
const std::function<void(const var&)>& finishCallbackWithNextHash)
{
Thread::launch([hashToUse, finishCallbackWithNextHash]()
{
var json;

URL u("https://api.github.com/repos/christoph-hart/HISE/commits");

auto s = u.readEntireTextStream();

auto ok = JSON::parse(s, json);

if(auto list = json.getArray())
{
for(int i = 0; i < list->size(); i++)
{
auto thisSha = list->getUnchecked(i)["sha"].toString();

if(thisSha == hashToUse)
{
auto nextIndex = i-1;

if(nextIndex >= 0 && isPositiveAndBelow(nextIndex, list->size()))
{
finishCallbackWithNextHash(list->getUnchecked(nextIndex));
}

break;
}
}
}
});


}
} // namespace hise
5 changes: 5 additions & 0 deletions hi_backend/backend/BackendApplicationCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ struct XmlBackupFunctions
static String getSanitiziedName(const String &id);
};

struct GitHashManager
{
static void checkHash(const String& hashToUse, const std::function<void(const var&)>& finishCallbackWithNextHash);
};

} // namespace hise

#endif // BACKENDAPPLICATIONCOMMANDS_H_INCLUDED
2 changes: 1 addition & 1 deletion hi_backend/backend/currentGit.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PREVIOUS_HISE_COMMIT "88855207086c850b13d2f4479791532d76b9adb7"
#define PREVIOUS_HISE_COMMIT "73b8ddd08adf0d86ab70dcf464adaf9d5c604e41"
79 changes: 32 additions & 47 deletions hi_backend/backend/dialog_library/dialog_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,60 +312,45 @@ var ExportSetupWizard::onPost(const var::NativeFunctionArgs& args)
return var();
}



var AboutWindow::initValues(const var::NativeFunctionArgs& args)
{
#define set(X) state->globalState.getDynamicObject()->setProperty(Identifier(#X), X);
#define setXY(X, Y) state->globalState.getDynamicObject()->setProperty(Identifier(#X), Y);

auto hiseRoot = GET_HISE_SETTING(getMainController()->getMainSynthChain(), HiseSettings::Compiler::HisePath).toString();


String buildHash(PREVIOUS_HISE_COMMIT);

state->globalState.getDynamicObject()->setProperty("commitHash", "load current hash...");

WeakReference<AboutWindow> safeThis(this);

GitHashManager::checkHash(buildHash, [safeThis](const var& commitObj)
{
if(safeThis.get() != nullptr)
{
auto nextHash = commitObj["sha"].toString();
auto shortHash = nextHash.substring(0, 8);

safeThis->state->globalState.getDynamicObject()->setProperty("commitHash", shortHash);

if(auto pb = safeThis->dialog->findPageBaseForID("commitHash"))
{
MessageManagerLock mm;
pb->postInit();
}

String link;
link << "https://github.com/christophhart/HISE/commit/";
link << nextHash;

safeThis->commitLink = URL(link);
}
});


if(hiseRoot.isNotEmpty() && File::isAbsolutePath(hiseRoot))
{
auto codeHash = File(hiseRoot).getChildFile("currentGitHash.txt").loadFileAsString().trim();

String buildHash(PREVIOUS_HISE_COMMIT);

URL u("https://api.github.com/repos/christoph-hart/HISE/commits");

auto s = u.readEntireTextStream();

var json;

auto ok = JSON::parse(s, json);

if(auto list = json.getArray())
{
for(int i = 0; i < list->size(); i++)
{
auto thisSha = list->getUnchecked(i)["sha"].toString();

if(thisSha == buildHash)
{
auto nextIndex = i-1;

if(nextIndex >= 0 && isPositiveAndBelow(nextIndex, list->size()))
{
auto nextSHA = list->getUnchecked(nextIndex)["sha"].toString();

auto shortHash = nextSHA.substring(0, 8);

state->globalState.getDynamicObject()->setProperty("commitHash", shortHash);

String link;
link << "https://github.com/christophhart/HISE/commit/";
link << nextSHA;

commitLink = URL(link);
}

break;
}
}

}
}


String Version = hise::PresetHandler::getVersionString();

Expand Down
2 changes: 2 additions & 0 deletions hi_backend/backend/dialog_library/dialog_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ struct AboutWindow: public multipage::EncodedDialogBase
var showCommit(const var::NativeFunctionArgs& args);

URL commitLink;

JUCE_DECLARE_WEAK_REFERENCEABLE(AboutWindow);
};

struct NewProjectCreator: public ImporterBase,
Expand Down

0 comments on commit 694571c

Please sign in to comment.