This repository was archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpsom_version_svn.m
155 lines (126 loc) · 4.85 KB
/
psom_version_svn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function [svn]= psom_version_svn(verbose)
% Retrieve the svn version of all root library in the matlab PATH
%
% SYNTAX :
% VERSIONS = PSOM_VERSION_SVN( VERBOSE )
%
% _________________________________________________________________________
% INPUTS :
% VERBOSE (boolean) (default false if output detected)
%
% _________________________________________________________________________
% OUTPUTS:
%
% VERSIONS
% (structure) SVN.NAME Name of the svn lib.
% SVN.VERSION version number of the lib.
% SVN.PATH path of the svn root lib.
% SVN.INFO information from the function svnversion.
%
% _________________________________________________________________________
% COMMENTS :
%
%
% Copyright (c) Christian L. Dansereau, Centre de recherche de l'Institut universitaire de gériatrie de Montréal, 2011.
% Maintainer : [email protected]
% See licensing information in the code.
% Keywords : svn,version
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
if (nargout == 0) && ~exist('verbose','var')
verbose = true;
elseif ~exist('verbose','var')
verbose = false;
end
%%%%%%%%%%%%%%%%%
%% SVN %%
%%%%%%%%%%%%%%%%%
svn = struct()
if verbose, tic,end
k=0;
output=path;
svn_repositories=[];
idx_line = strfind(output,':');
for nb_line=1:size(idx_line,2)
if nb_line == 1
str_path = output(1:idx_line(nb_line)-1);
else
str_path = output(idx_line(nb_line-1)+1:idx_line(nb_line)-1);
end
% Check if it is not a hiden path
if isempty(strfind(str_path,'/.svn'))
% Remove any filesep at the end of the path
if strcmp(str_path(end),filesep)
str_path = str_path(1:end-1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
% put all paths in cells %
%%%%%%%%%%%%%%%%%%%%%%%%%%
k=k+1;
path_list{k}=str_path;
end
end
n_root=0;
for nb_line=1:size(path_list,2)
str_path = path_list{nb_line};
% Look if the path contain a .svn folder
if (exist(cat(2,str_path,filesep,'.svn'),'dir') == 7)
% Look if it's the root svn folder
[parent_pathstr,parent_name,ext] = fileparts(str_path);
if (exist(cat(2,parent_pathstr,filesep,'.svn'),'dir') == 7)
% Do nothing!
for idx=1:size(path_list,2)
detect_shortest_path(idx) = ~isempty(strmatch(path_list{idx},parent_pathstr));
end
if sum(detect_shortest_path) == 0
% Find the real root dir
ppath = parent_pathstr;
flag_root = true;
while flag_root
% Look if it's the root svn folder
[ppath,pname,ext] = fileparts(ppath);
parent_name = cat(2,pname,'-',parent_name);
if (exist(cat(2,ppath,filesep,'.svn'),'dir') == 0)
flag_root = false;
end
end
n_root=n_root+1;
svn(n_root) = get_info_svndir(str_path,parent_name,verbose);
end
else
n_root=n_root+1;
svn(n_root) = get_info_svndir(str_path,parent_name,verbose);
end
end
end
if verbose, toc,end
end
%% sub function
function [svn]=get_info_svndir(rootpath,parent_name,verbose)
[status,version]=system(cat(2,'svnversion ',rootpath,' 2>&1'));
[status,info]=system(cat(2,'svn info ',rootpath,' 2>&1'));
svn.name = parent_name;
svn.version = version;
svn.path = rootpath;
svn.info = info;
if verbose
tmp_msg = cat(2,svn.name,': ',svn.version);
tmp_msg(regexp(tmp_msg,'\n')) = '';
fprintf('%s\n',tmp_msg);
end
end