Code covered by the BSD License  

Highlights from
SVN Profiling

SVN Profiling

by

 

10 Aug 2011 (Updated )

Read data from files tagged with an SVN keyword

build_svn_profile(folders,keywords,strs,rec)
function [svn_profile,svn_str] = build_svn_profile(folders,keywords,strs,rec)
% Read data from files tagged with SVN keywords
% 
%   svn_profile = build_svn_profile(folders,keywords)
%   svn_profile = build_svn_profile(folders,keywords,strs)
%   ... = build_svn_profile(folders,keywords,strs,rec)
%   [svn_profile,svn_str] = build_svn_profile(...)
% 
%   This function extracts SVN keyword data from specified
%   files, and returns the filename, path and keyword data
%   to a cell array (and optional char array).
%   
%   Keyword data are placed in files automatically by
%   Subversion at each commit using the 'keyword' function.
%   The data can be useful in maintaining an audit trail, or
%   establishing the version used to generate a particular
%   set of results.
%   
%   svn_profile = build_svn_profile(folders,keywords)
%   returns a cell array svn_profile containing data
%   associated with the SVN keywords. The function will
%   search through files contained in folders.
%   
%   svn_profile is a two dimensional cell array; there is
%   one row for each file found in folders, and N columns:
%   one each for the full path for the file, and appended
%   columns for each specified keyword. Data is only
%   returned for files that contain the specified
%   keyword(s). An empty cell array, 0-by-2, is returned if
%   no keywords are found.
%   
%   svn_profile = build_svn_profile(folders,keywords,strs)
%   allows additional filter strings strs to be specified.
%   See GET_CONTENTS for details of permitted filter
%   strings.
%   
%   ... = build_svn_profile(folders,keywords,strs,rec), with
%   rec = true, allows folders to be searched recursively
%   (default is false).
%   
%   [svn_profile,svn_str] = build_svn_profile(...) outputs a
%   char array svn_str of the profile, with columns
%   concatenated to produce continuous lines. Spaces are
%   inserted to ensure that columns are aligned (in a
%   monospaced font). The array is appropriate for printing
%   or embedding in a PostScript file, for example. This
%   char array can be written to a text file with the
%   following command:
%   
%   dlmwrite('svn_profile.txt',svn_str,'delimiter','')
%   
%   folders, keywords,and strs may be a char array
%   specifying a single occurrence, or a cell array of
%   strings specifying multiple occurrences.
%   
%   See also READ_SVN_KEYWORD, GET_CONTENTS,
%   ADD_PS_COMMENTS.

% !---
% ==========================================================
% Last changed:     $Date: 2013-04-25 10:15:52 +0100 (Thu, 25 Apr 2013) $
% Last committed:   $Revision: 241 $
% Last changed by:  $Author: ch0022 $
% ==========================================================
% !---

if ischar(folders)
    folders = cellstr(folders);
end

if ischar(keywords)
    keywords = cellstr(keywords);
end

if nargin > 2
    if ischar(strs)
        strs = cellstr(strs);
    end
else
    strs = {'files'};
end

% add subfolders if recursion is requested
if nargin > 3
    if rec
        for f = folders
            folders = [folders; get_contents(char(f),'filter','folders','rec',true,'path','full')]; %#ok<AGROW>
        end
    end
end

keydata = cell(0,1+length(keywords)); % empty cell array to be appended
n = 1;
for f = 1:length(folders)
    folder = folders{f};
    for s = 1:length(strs)
        str = strs{s};
        [files,dirflag] = get_contents(folder,'filter',str,'path','full'); % find relevant files
        files = files(~dirflag); % ignore directories
        if ~isempty(files)
            for h = 1:length(files)
                file = files{h};
                % extract keyword data from file
                for k = 1:length(keywords)
                    keyword = keywords{k};
                    keydata{n,1} = file;
                    keydata{n,1+k} = read_svn_keyword(file,keyword);
                end
                n = n+1;
            end
        end
    end
end

 % remove files where no keyword is found
IX = true(size(keydata(:,2)));
for k = 1:length(keywords)
    IX = IX & cellfun(@isempty,keydata(:,1+k));
end
svn_profile = keydata(~IX,:);

% Build char array version of data
space = repmat('  ',size(svn_profile(:,1))); % spaces to insert between columns
svn_str = char(svn_profile(:,1)); % first column (file path)
% append keyword columns:
for k = 1:length(keywords)
        svn_str = [svn_str space char(svn_profile(:,1+k))]; %#ok<AGROW>
end

% [EOF]

Contact us