diff --git a/src/tools_lgpl/matlab/quickplot/make_d3dmatlab.m b/src/tools_lgpl/matlab/quickplot/make_d3dmatlab.m index 16490bde..88c82761 100644 --- a/src/tools_lgpl/matlab/quickplot/make_d3dmatlab.m +++ b/src/tools_lgpl/matlab/quickplot/make_d3dmatlab.m @@ -140,13 +140,10 @@ function localmake(varargin) fstrrep([targetdir,filesep,'Contents.m'], '', release) fstrrep([targetdir,filesep,'Contents.m'], '', DateStr) % MATLAB toolboxes don't have a time stamp -fprintf('Stripping files ...\n'); -HeadURL_str = ['Source ', repo_url, ': ', hash]; -Id_str = ['Release ', release, ': ', DateTimeStr]; -svnstripfile(targetdir, HeadURL_str, Id_str) - -%fprintf('Pcoding files ...\n'); -%pmfile('dir',targetdir,targetdir,'-verbose') +fprintf('Add source information to all files ...\n'); +Keywords.HeadURL = ['Source ', repo_url, ': ', hash]; +Keywords.Id = ['Release ', release, ': ', DateTimeStr]; +process_keywords(targetdir, Keywords) fprintf('Cleaning up directory ...\n'); X = {'*.asv' @@ -170,7 +167,7 @@ function exportsrc(sourcedir,targetdir) target = [targetdir filesep d(i).name]; if d(i).isdir switch d(i).name - case {'.','..','.svn'} + case {'.','..'} % skip otherwise mkdir(target); diff --git a/src/tools_lgpl/matlab/quickplot/svnstripfile.m b/src/tools_lgpl/matlab/quickplot/process_keywords.m similarity index 68% rename from src/tools_lgpl/matlab/quickplot/svnstripfile.m rename to src/tools_lgpl/matlab/quickplot/process_keywords.m index 2b996e78..071b59fd 100644 --- a/src/tools_lgpl/matlab/quickplot/svnstripfile.m +++ b/src/tools_lgpl/matlab/quickplot/process_keywords.m @@ -1,14 +1,9 @@ -function svnstripfile(basedir, varargin) -%SVNSTRIPFILE Strip $-sign from SVN keywords in files. -% SVNSTRIPFILE(BaseDir) recursively processes all .m, .c and .cpp files in -% the directory BaseDir and below, stripping away the $-signs from the SVN -% keywords HeadURL and Id (more keywords can easily be added). -% -% This tool should be run after checking out source code maintained in one -% location before committing it to another subversion location for -% distribution. If the $-signs are not stripped, then there is a fair chance -% that the revision data is used from the second location rather than the -% information from the first location where the code is actually maintained. +function process_keywords(basedir, varargin) +%PROCESS_KEYWORDS Replace keywords by strings +% PROCESS_KEYWORDS(BaseDir,KeywordValues) recursively processes all .m, .c +% and .cpp files in the directory BaseDir and below, replacing the keywords +% specified as fields in KeywordValues by the string value assigned to those +% fields. %----- LGPL -------------------------------------------------------------------- % @@ -40,7 +35,6 @@ function svnstripfile(basedir, varargin) % $HeadURL$ % $Id$ -nstrings = length(varargin); d = dir(basedir); for i = 1:length(d) if d(i).isdir @@ -53,7 +47,7 @@ function svnstripfile(basedir, varargin) % % recursive processing of child directories % - svnstripfile([basedir filesep d(i).name],varargin{:}) + process_keywords([basedir filesep d(i).name],varargin{:}) else [p,f,e] = fileparts(d(i).name); if ~strcmp(e,'.m') && ~strcmp(e,'.c') && ~strcmp(e,'.cpp') && ~strcmp(e,'.ini') @@ -77,20 +71,18 @@ function svnstripfile(basedir, varargin) end fclose(fid); % - % filter lines + % process the keywords % - Keywords = {'HeadURL','Id'}; + ValueOf = varargin{1}; + Keywords = fieldnames(ValueOf); for l = 1:length(c) for k = 1:length(Keywords) - j = strfind(c{l},['$' Keywords{k}]); + keyword = Keywords{k}; + j = strfind(c{l},['$' keyword]); if ~isempty(j) j2 = strfind(c{l},'$'); j2 = min(j2(j2>j)); - if k > nstrings - c{l} = [c{l}(1:j-1) c{l}(j+1:j2-1) c{l}(j2+1:end)]; - else - c{l} = [c{l}(1:j-1) varargin{k} c{l}(j2+1:end)]; - end + c{l} = [c{l}(1:j-1) ValueOf.(keyword) c{l}(j2+1:end)]; end end end diff --git a/src/tools_lgpl/matlab/quickplot/progsrc/private/determine_revision.m b/src/tools_lgpl/matlab/quickplot/progsrc/private/determine_revision.m index d74cf569..4d3fce9f 100644 --- a/src/tools_lgpl/matlab/quickplot/progsrc/private/determine_revision.m +++ b/src/tools_lgpl/matlab/quickplot/progsrc/private/determine_revision.m @@ -1,11 +1,9 @@ function [revString,repoUrl,hash] = determine_revision(dirname,dbid) -%DETERMINE_REVISION Determine the Git hash or Subversion revision string. +%DETERMINE_REVISION Determine the Git hash string. % STR = DETERMINE_REVISION(DIR) determines a revision string representing -% the code status in the provided DIR using information from Subversion -% or Git. For Subversion the string consists of the highest revision -% number found in the folder and a flag indicating whether the code has -% been changed. For Git the revision number is replaced by the short hash -% and the flag. +% the code status in the provided DIR using information from Git. For Git the +% string consists of the short commit hash and a flag indicating whether the +% code has changes compared to that commit. %----- LGPL -------------------------------------------------------------------- % @@ -37,148 +35,67 @@ % $HeadURL$ % $Id$ -Id = '$Id$'; -repoUrl = '$HeadURL$'; -hash = 'N/A'; -if ~strcmp(Id(2:end-1),'Id') - % Subversion keyword expansion seems to be active. - % Use Subversion - iter = 1; - found = 0; - if nargin<2 - dbid = 1; - end - while ~found - switch iter - case 1 - if strncmp(computer,'PCWIN',5) - thisfile = mfilename('fullpath'); - tools = strfind(thisfile,'tools_lgpl'); - svnVersion = [thisfile(1:tools-1),'third_party_open/subversion/bin/win32/svnversion.exe']; - else - svnVersion = '/usr/bin/svnversion'; - end - case 2 - svnPath = getenv('SVN_BIN_PATH'); - svnVersion = [svnPath filesep 'svnversion.exe']; - case 3 - svnPath = 'c:\Program Files\Subversion\bin'; - svnVersion = [svnPath filesep 'svnversion.exe']; - case 4 - [s,svnVersion] = system_plain('which svnversion'); - if s~=0 - svnVersion = 'The WHICH command failed'; - end - case 5 - svnVersion = ''; - break - end - % - if exist(svnVersion,'file') - break - end - iter = iter+1; - end - - if ~isempty(svnVersion) - [s,revString] = system_plain(['"' svnVersion '" "' dirname '"']); - else - s = 0; - end - if s==0 - changed = ismember('M',revString); - rev = sscanf(revString,'%i:%i'); - if isempty(rev) %exported - revMin = 0; - revMax = 0; - changed = 1; - elseif length(rev)==1 - revMin = rev; - revMax = rev; - else - revMin = rev(1); - revMax = rev(2); - end +% get hash +cwd = pwd; +cd(dirname) +[a,b] = system_plain('git -P log -n 1 -v --decorate'); +% if we could remove -n 1, we could look for the latest hash available +% at the origin, but that triggers a pager to wait for keypresses. The +% option --no-pager before log seems to work on the command line, but +% not when called via system for some reason. This call returns +% something like: +%commit (HEAD -> , ) +%Author: ... author ... +%Date: ... date and time ... +% +% ... message ... +% +% Unfortunately, the branch names don't seem to appear on TeamCity ... +if a ~= 0 + revString = 'unknown'; + repoUrl = 'unknown'; + hash = 'unknown'; +else + [commit, b] = strtok(b); % takes the "commit" string + [hash, b] = strtok(b); % takes the + b = strsplit(b, local_newline); % splits to a cell string of which the first entry is the (HEAD ...) part + + teamcity_build_branch = getenv('TEAMCITY_BUILD_BRANCH'); + if ~isempty(teamcity_build_branch) + % running on TeamCity ... don't look for origin ... + hasLocalCommits = false; else - dprintf(dbid,'Unable to execute SVNVERSION program.\nUsing built-in implementation of svnversion.\n') - [revMin,revMax,changed] = svnversion(dirname,dbid); + hasLocalCommits = isempty(strfind(b{1}, 'origin/')); end - if revMax<0 - revString = '[unknown revision]'; - else - revString = sprintf('%05.5i',revMax); - if changed || revMin (HEAD -> , ) - %Author: ... author ... - %Date: ... date and time ... - % - % ... message ... - % - % Unfortunately, the branch names don't seem to appear on TeamCity ... - if a ~= 0 - revString = 'unknown'; - repoUrl = 'unknown'; - hash = 'unknown'; - else - [commit, b] = strtok(b); % takes the "commit" string - [hash, b] = strtok(b); % takes the - b = strsplit(b, local_newline); % splits to a cell string of which the first entry is the (HEAD ...) part - - teamcity_build_branch = getenv('TEAMCITY_BUILD_BRANCH'); - if ~isempty(teamcity_build_branch) - % running on TeamCity ... don't look for origin ... - hasLocalCommits = false; - else - hasLocalCommits = isempty(strfind(b{1}, 'origin/')); - end + % get status + [a, b] = system_plain(['git status "' dirname '"']); + b = strsplit(b, local_newline); - % get repository - [a, b] = system_plain('git remote -v'); - [origin, b] = strtok(b); - [repoUrl, b] = strtok(b); + hasStagedChanges = check_and_list_files(b, 'Changes to be committed:', 'Staged files:\n', false); - % git describe - %[a,b] = system_plain(['git describe "' dirname '"']); - % returns something like: DIMRset_2.23.05-4-ge3176daa1 - % but I don't want QUICKPLOT to refer to "DIMRset" tags - % however, neither should DIMRsets refer to QUICKPLOT tags. + hasUnstagedChanges = check_and_list_files(b, 'Changes not staged for commit:', 'Modified files:\n', false); - % get status - [a, b] = system_plain(['git status "' dirname '"']); - b = strsplit(b, local_newline); - - hasStagedChanges = check_and_list_files(b, 'Changes to be committed:', 'Staged files:\n', false); - - hasUnstagedChanges = check_and_list_files(b, 'Changes not staged for commit:', 'Modified files:\n', false); - - hasUntrackedChanges = check_and_list_files(b, 'Untracked files:', 'Untracked files:\n', true); + hasUntrackedChanges = check_and_list_files(b, 'Untracked files:', 'Untracked files:\n', true); - % we should also check if we have local commits to be pushed. - revString = hash(1:9); - if hasLocalCommits || hasStagedChanges || hasUnstagedChanges || hasUntrackedChanges - revString = [revString ' (changed)']; - end + % we should also check if we have local commits to be pushed. + revString = hash(1:9); + if hasLocalCommits || hasStagedChanges || hasUnstagedChanges || hasUntrackedChanges + revString = [revString ' (changed)']; end - cd(cwd) end +cd(cwd) function checkResult = check_and_list_files(b, checkString, printString, mexExcept) checkResult = false; @@ -219,120 +136,6 @@ end end - -function [min_update,max_update,changed] = svnversion(dirname,dbid) -min_update = inf; -max_update = -inf; -changed = 0; -d = dir(dirname); -for i = 1:length(d) - if ismember(d(i).name,{'.','..','.svn'}) - % do nothing - elseif d(i).isdir - [min1,max1,changed1] = svnversion(fullfile(dirname,d(i).name),dbid); - min_update = min(min_update,min1); - max_update = max(max_update,max1); - changed = changed | changed1; - end -end -entries = get_svn_entries(dirname); -ref = fullfile(dirname,'.svn/text-base'); -for i = 1:length(entries) - reffile = fullfile(ref,[entries(i).filename '.svn-base']); - newfile = fullfile(dirname,entries(i).filename); - min_update = min(min_update,entries(i).last_updated); - max_update = max(max_update,entries(i).last_updated); - if ~exist(newfile,'file') - % file has been removed - dprintf(dbid,'File removed: "%s"\n',newfile); - changed = 1; - else - changed = changed | is_file_modified(reffile,newfile,dbid); - end -end - -function entries = get_svn_entries(dirname) -entries = []; -fid = fopen(fullfile(dirname,'.svn','entries'),'r'); -if fid<0 - % no subversion directory - return -end -str = fread(fid,[1 inf],'*char'); -fclose(fid); -entry = strfind(str,char(12)); -% -substr = str(1:entry(1)-1); -lines = strfind(substr,local_newline); -updatestr = substr(lines(3)+1:lines(4)-1); -updatenr = str2double(updatestr); -% -j = 0; -for i=1:length(entry)-1 - substr = str(entry(i)+2:entry(i+1)-1); - lines = strfind(substr,local_newline); - if strcmp(substr(lines(1)+1:lines(2)-1),'file') - j = j+1; - entries(j).filename = substr(1:lines(1)-1); - revstr = substr(lines(9)+1:lines(10)-1); - entries(j).last_revised = str2double(revstr); - updatestr = substr(lines(2)+1:lines(3)-1); - if isempty(updatestr) - entries(j).last_updated = updatenr; - else - entries(j).last_updated = str2double(updatestr); - end - end -end - -function changed = is_file_modified(reffile,newfile,dbid) -fid = fopen(reffile,'r'); -file1 = fread(fid,[1 inf],'*char'); -fclose(fid); -% -fid = fopen(newfile,'r'); -file2 = fread(fid,[1 inf],'*char'); -fclose(fid); -% -changed = 1; -if isequal(file1,file2) - changed = 0; -else - Ids = []; - for keyw = {'Id','Date','Author','Revision','HeadURL'} - kw = keyw{1}; - Ids = cat(2,Ids,strfind(file1,['$' kw '$'])); - end - Ids = sort(Ids); - for i = 1:length(Ids) - kw = sscanf(file1(Ids(i)+1:end),'%[A-Za-z]'); - if ~strcmp(file2(Ids(i)+(0:length(kw))),['$' kw]) - break - else - Amp = strfind(file2(Ids(i)+1:end),'$'); - if isempty(Amp) - break - else - file2 = cat(2,file2(1:Ids(i)),kw,file2(Ids(i)+Amp(1):end)); - end - end - end - if isequal(file1,file2) - changed = 0; - end -end - -if changed - dprintf(dbid,'File changed: "%s"\n',newfile); -end - - -function dprintf(fid,varargin) -if fid~=0 - fprintf(fid,varargin{:}); -end - - function s = local_newline if matlabversionnumber > 9.01 s = newline;