MatrixBerryCore
gitgethash.m
Go to the documentation of this file.
1 function hashStr=gitgethash(pathStr)
2 import mxberry.core.throwerror;
3 persistent mp
4 GIT_HASH_LENGTH=40;
5 GIT_HASH_CMD='log -1 HEAD --pretty=format:%H';
6 if isempty(mp)
7  mp=containers.Map();
8 end
9 if mp.isKey(pathStr)
10  hashStr=mp(pathStr);
11 else
12  if nargin==0
13  pathStr=fileparts(mfilename('fullpath'));
14  end
15  [hashStr,StMsg]=mxberry.dev.scm.git.gitcall(GIT_HASH_CMD,pathStr);
16  %
17  if isempty(StMsg)
18  hashStr=[hashStr{:}];
19  hashStr=strtrim(hashStr);
20  nHashSymb=numel(hashStr);
21  if nHashSymb>GIT_HASH_LENGTH
22  %on unix hash string can contain a garbage tail like in
23  %dc6698d793bde0c84d3137dd0641d7a7bce1cdd1
24  hashStr=hashStr(1:GIT_HASH_LENGTH);
25  elseif nHashSymb>GIT_HASH_LENGTH
26  throwerror('wrongState',...
27  'hash string returned by %s command is too short',GIT_HASH_CMD);
28  end
29  else
30  if iscell(hashStr)&&isempty(hashStr)
31  error(StMsg);
32  elseif strcmp(StMsg.identifier,'GIT:versioningProblem')&&...
33  strncmp(hashStr,'fatal: Not a git repository',...
34  numel('fatal: Not a git repository'))
35  hashStr='unversioned';
36  else
37  error(StMsg);
38  end
39  end
40  mp(pathStr)=hashStr;
41 end
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function hash(in inpArr, in methodName)
OBJECTHASH counts the hash of input object/array.
function gitgethash(in pathStr)