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

head_rev(folders,strs,rec)
function [rev,file] = head_rev(folders,strs,rec)
% Retrieve the head revision for specified files
%
%   rev = head_rev(folders)
%   rev = head_rev(folders,strs)
%   rev = head_rev(folders,strs,rec)
%   [rev,file] = head_rev(...)
% 
%   This function finds the most recently committed file in
%   the specified folders(s) and returns its revision and
%   filename. The files must contain the 'Revision' and
%   'Date' keywords.
% 
%   rev = head_rev(folders) returns the head revision (i.e.
%   the highest revision) for all files in folders.
%
%   rev = head_rev(folders,strs) allows additional filter
%   strings strs to be specified. See GET_CONTENTS for
%   details of permitted filter strings.
% 
%   rev = head_rev(folders,strs,rec), with rec = true,
%   allows folders to be searched recursively (default is
%   false).
%
%   [rev,file] = head_rev(...) returns the filename to file
%   of the file with the highest revision.
%
%   Folders and strs may be a string specifying a single
%   occurrence, or a cell array of strings specifying
%   multiple occurrences. This function requires that the
%   'Revision' keyword is used in the searched functions.
% 
%   Note that if the folders include files from an
%   externally-defined repository (which has been updated
%   more recently than the native repository), a misleading
%   revision number may be presented.
% 
%   See also BUILD_SVN_PROFILE, READ_SVN_KEYWORD.

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

keyword = 'Date'; % use this data to sort files (doubtful that any others would work, without considerable parsing)

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

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

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

% get revision info for files
svn_profile = build_svn_profile(folders,keyword,strs);

% remove the keyword and convert revision strings to numbers
svn_profile(:,2) = cellfun(@(x) (x(length(keyword)+3:end)),svn_profile(:,2),'uni',false);

% remove NaN (files that don't have the revision keyword)
IX1 = cellfun(@isempty,svn_profile(:,2));
svn_profile = svn_profile(~IX1,:);

% sort by revision number
[~,IX2] = sort(svn_profile(:,2));
svn_profile = svn_profile(IX2,:);

% get highest revision number
rev = read_svn_keyword(svn_profile{end,1},'Revision');

% return corresponding filename, if requested
if nargout>1
    file = svn_profile{end,1};
end

% [EOF]

Contact us