Debian Codegraph @

test/private/VersionControlIdentifier.m

raw
1 function [formatted,treeish] = VersionControlIdentifier()
2 % This function gives the (git) commit ID of matlab2tikz
3 %
4 % This assumes the standard directory structure as used by Nico's master branch:
5 % SOMEPATH/src/matlab2tikz.m with a .git directory in SOMEPATH.
6 %
7 % The HEAD of that repository is determined from file system information only
8 % by following dynamic references (e.g. ref:refs/heds/master) in branch files
9 % until an absolute commit hash (e.g. 1a3c9d1...) is found.
10 % NOTE: Packed branch references are NOT supported by this approach
11 MAXITER = 10; % stop following dynamic references after a while
12 formatted = '';
13 REFPREFIX = 'ref:';
14 isReference = @(treeish)(any(strfind(treeish, REFPREFIX)));
15 treeish = [REFPREFIX 'HEAD'];
16 try
17 % get the matlab2tikz directory
18 privateDir = fileparts(mfilename('fullpath'));
19 gitDir = fullfile(privateDir,'..','..','.git');
20
21 nIter = 1;
22 while isReference(treeish)
23 refName = treeish(numel(REFPREFIX)+1:end);
24 branchFile = fullfile(gitDir, refName);
25
26 if exist(branchFile, 'file') && nIter < MAXITER
27 % The FID is reused in every iteration, so `onCleanup` cannot
28 % be used to `fclose(fid)`. But since there is very little that
29 % can go wrong in a single `fscanf`, it's probably best to leave
30 % this part as it is for the time being.
31 fid = fopen(branchFile,'r');
32 treeish = fscanf(fid,'%s');
33 fclose(fid);
34 nIter = nIter + 1;
35 else % no branch file or iteration limit reached
36 treeish = '';
37 return;
38 end
39 end
40 catch %#ok
41 treeish = '';
42 end
43 if ~isempty(treeish)
44 formatted = [' Commit & ' treeish ' \\\\ \n'];
45 end
46 %TODO: do the formatting somewhere else!
47 end