mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
ADDED: VCSHASH and VCSSHORTHASH
Right now, git hashes only resolved by the variables ${VCSHASH} or ${VCSSHORTHASH}
This commit is contained in:
parent
5952c2fb9a
commit
c64f99c57a
@ -24,6 +24,9 @@
|
|||||||
#include "project_git_utils.h"
|
#include "project_git_utils.h"
|
||||||
#include "git_backend.h"
|
#include "git_backend.h"
|
||||||
|
|
||||||
|
#include <wx/string.h>
|
||||||
|
#include <string_utils.h>
|
||||||
|
|
||||||
namespace KIGIT
|
namespace KIGIT
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -43,4 +46,34 @@ bool PROJECT_GIT_UTILS::RemoveVCS( git_repository*& aRepo, const wxString& aProj
|
|||||||
return GetGitBackend()->RemoveVCS( aRepo, aProjectPath, aRemoveGitDir, aErrors );
|
return GetGitBackend()->RemoveVCS( aRepo, aProjectPath, aRemoveGitDir, aErrors );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString PROJECT_GIT_UTILS::GetCurrentHash( const wxString& aProjectFile, bool aShort )
|
||||||
|
{
|
||||||
|
wxString result = wxT( "no hash" );
|
||||||
|
git_repository* repo = PROJECT_GIT_UTILS::GetRepositoryForFile( TO_UTF8( aProjectFile ) );
|
||||||
|
|
||||||
|
if( repo )
|
||||||
|
{
|
||||||
|
git_reference* head = nullptr;
|
||||||
|
|
||||||
|
if( git_repository_head( &head, repo ) == 0 )
|
||||||
|
{
|
||||||
|
const git_oid* oid = git_reference_target( head );
|
||||||
|
|
||||||
|
if( oid )
|
||||||
|
{
|
||||||
|
char buf[41];
|
||||||
|
size_t len = aShort ? 8 : 41;
|
||||||
|
git_oid_tostr( buf, len, oid );
|
||||||
|
result = wxString::FromUTF8( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
git_reference_free( head );
|
||||||
|
}
|
||||||
|
|
||||||
|
git_repository_free( repo );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace KIGIT
|
} // namespace KIGIT
|
||||||
|
@ -51,6 +51,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
static int CreateBranch( git_repository* aRepo, const wxString& aBranchName );
|
static int CreateBranch( git_repository* aRepo, const wxString& aBranchName );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current HEAD commit hash for the repository containing aProjectFile.
|
||||||
|
*
|
||||||
|
* @param aProjectFile Absolute path to any file within the repository (typically the
|
||||||
|
* project file path).
|
||||||
|
* @param aShort If true, return the short (8 char) hash, otherwise full hash.
|
||||||
|
* @return wxString containing the hash or "no hash" if unavailable.
|
||||||
|
*/
|
||||||
|
static wxString GetCurrentHash( const wxString& aProjectFile, bool aShort );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove version control from a directory by freeing the repository and
|
* Remove version control from a directory by freeing the repository and
|
||||||
* optionally removing the .git directory.
|
* optionally removing the .git directory.
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#include <kiway.h>
|
#include <kiway.h>
|
||||||
#include <lockfile.h>
|
#include <lockfile.h>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
|
#include <git/project_git_utils.h>
|
||||||
|
#include <git2.h>
|
||||||
#include <project.h>
|
#include <project.h>
|
||||||
#include <project/project_file.h>
|
#include <project/project_file.h>
|
||||||
#include <trace_helpers.h>
|
#include <trace_helpers.h>
|
||||||
@ -45,6 +47,7 @@
|
|||||||
#include <title_block.h>
|
#include <title_block.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PROJECT::PROJECT() :
|
PROJECT::PROJECT() :
|
||||||
m_readOnly( false ),
|
m_readOnly( false ),
|
||||||
m_textVarsTicker( 0 ),
|
m_textVarsTicker( 0 ),
|
||||||
@ -85,6 +88,16 @@ bool PROJECT::TextVarResolver( wxString* aToken ) const
|
|||||||
*aToken = TITLE_BLOCK::GetCurrentDate();
|
*aToken = TITLE_BLOCK::GetCurrentDate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if( aToken->IsSameAs( wxT( "VCSHASH" ) ) )
|
||||||
|
{
|
||||||
|
*aToken = KIGIT::PROJECT_GIT_UTILS::GetCurrentHash( GetProjectFullName(), false );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if( aToken->IsSameAs( wxT( "VCSSHORTHASH" ) ) )
|
||||||
|
{
|
||||||
|
*aToken = KIGIT::PROJECT_GIT_UTILS::GetCurrentHash( GetProjectFullName(), true );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if( GetTextVars().count( *aToken ) > 0 )
|
else if( GetTextVars().count( *aToken ) > 0 )
|
||||||
{
|
{
|
||||||
*aToken = GetTextVars().at( *aToken );
|
*aToken = GetTextVars().at( *aToken );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user