Commit f663e4f9 authored by jayd1860's avatar jayd1860
Browse files

-- Change syncSubmodules to not use version numbers any more and rely on dates instead

parent d6477dad
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
function [date, dateS] = getLastRevisionDate(repo)
date = 0;
dateS = '';
if ~exist('repo','var') || isempty(repo)
    repo = pwd;
end
repoFull = filesepStandard_startup(repo, 'full');

f1 = findTypeFiles(repoFull, '.m');
f2 = findTypeFiles(repoFull, '.txt');
f3 = findTypeFiles(repoFull, '.numberfiles');
f = [f1; f2; f3];

for ii = 1:length(f)
    pathrel = pathsubtract(f{ii}, repoFull);
    try
    [d, ds] = gitLastRevDate(repoFull, pathrel);
    if d>date
        date = d;
        dateS = ds;
    end
    catch
        d=1;
    end
end

+28 −0
Original line number Diff line number Diff line
function [date, datestr] = gitLastRevDate(repo, file)
date = 0;

if ~exist('repo','var') || isempty(repo)
    repo = pwd;
end
repoFull = filesepStandard_startup(repo, 'full');
currdir = pwd;

ii = 1;
cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
cmds{ii,1} = sprintf('git log -1 --format=%%ci --date=short %s', file);
[errs, msgs] = exeShellCmds(cmds, false, true);
if all(errs==0)
    c = str2cell(msgs{2}, ' ');
    dateS = c{1};
    timeS = c{2};
    dateS(dateS=='-')='';
    timeS(timeS==':')='';    
    
    time = str2num(timeS);
    date = str2num(dateS) + time/1e6;
    
    datestr = [c{1}, ' ', c{2}];
end

cd(currdir)
+12 −12
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ function [cmds, errs, msgs] = syncSubmodules(repo, options, preview)
%                          sync the two libraries
%               Default if argument not supplied is 'init'
%
%   preview:    The parent repository. This is the repo that has the built-in
%               copy of the libraries
%   preview:    Boolean argument: if true, does not make any changes
%               
%
% Examples:
%
@@ -58,11 +58,11 @@ fprintf('\n');

cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
for jj = 1:size(submodules,1)
    [repo1, repo2, submodulename] = getRepos(submodules, jj, repoFull);
    [repo1, repo2, date1, date2, submodulename] = getRepos(submodules, jj, repoFull);
    
    fprintf('Synching "%s" library:\n', submodulename);
    fprintf('Repo1:  %s, v%s\n', repo1, getVernum(submodulename, repo1(1:end-1)));
    fprintf('Repo2:  %s, v%s\n', repo2, getVernum(submodulename, repo2(1:end-1)));
    fprintf('Repo1:  %s, %s\n', repo1, date1);
    fprintf('Repo2:  %s, %s\n', repo2, date2);
    fprintf('====================================================================\n');
    
    identical(1) = sync(repo1, repo2, false, preview);
@@ -170,7 +170,7 @@ end


% -----------------------------------------------------------------------------------
function [repo1, repo2, submodulename] = getRepos(submodules, jj, repoFull)
function [repo1, repo2, dateS1, dateS2, submodulename] = getRepos(submodules, jj, repoFull)
[~, f, e] = fileparts(submodules{jj,1});
submodulename = [f, e];

@@ -184,14 +184,14 @@ if r2(end)=='\' || r2(end)=='/'
    r2 = r2(1:end-1);
end

verstr1 = getVernum(submodulename, r1);
verstr2 = getVernum(submodulename, r2);
[date1, dateS1] = getLastRevisionDate(r1);
[date2, dateS2] = getLastRevisionDate(r2);

if compareVersions(verstr1, verstr2) < 1
    repo1 = [r1, '/'];
    repo2 = [r2, '/'];
else
if date1 > date2
    repo1 = [r2, '/'];
    repo2 = [r1, '/'];
else
    repo1 = [r1, '/'];
    repo2 = [r2, '/'];
end