2 * Copyright © 2006 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 #define min(a,b) ((a) < (b) ? (a) : (b))
23 #define max(a,b) ((a) > (b) ? (a) : (b))
26 cvs_is_head (cvs_number
*n
)
28 assert (n
->c
<= CVS_MAX_DEPTH
);
29 return (n
->c
> 2 && (n
->c
& 1) == 0 && n
->n
[n
->c
-2] == 0);
33 cvs_same_branch (cvs_number
*a
, cvs_number
*b
)
43 return cvs_same_branch (&t
, b
);
48 return cvs_same_branch (a
, &t
);
53 * Everything on x.y is trunk
58 for (i
= 0; i
< n
- 1; i
++) {
62 * deal with n.m.0.p branch numbering
65 if (an
== 0) an
= a
->n
[i
+1];
66 if (bn
== 0) bn
= b
->n
[i
+1];
75 cvs_number_compare (cvs_number
*a
, cvs_number
*b
)
77 int n
= min (a
->c
, b
->c
);
80 for (i
= 0; i
< n
; i
++) {
81 if (a
->n
[i
] < b
->n
[i
])
83 if (a
->n
[i
] > b
->n
[i
])
94 cvs_number_compare_n (cvs_number
*a
, cvs_number
*b
, int l
)
96 int n
= min (l
, min (a
->c
, b
->c
));
99 for (i
= 0; i
< n
; i
++) {
100 if (a
->n
[i
] < b
->n
[i
])
102 if (a
->n
[i
] > b
->n
[i
])
113 cvs_is_branch_of (cvs_number
*trunk
, cvs_number
*branch
)
120 return cvs_same_branch (trunk
, &n
);
126 cvs_number_degree (cvs_number
*n
)
135 * Place vendor branch between trunk and other branches
137 if (cvs_is_vendor (&four
))
143 cvs_previous_rev (cvs_number
*n
)
149 for (i
= 0; i
< n
->c
- 1; i
++)
155 p
.n
[i
] = n
->n
[i
] - 1;
160 cvs_master_rev (cvs_number
*n
)
170 * Find the newest revision along a specific branch
174 cvs_branch_head (cvs_file
*f
, cvs_number
*branch
)
180 /* Check for magic branch format */
181 if ((n
.c
& 1) == 0 && n
.n
[n
.c
-2] == 0) {
182 n
.n
[n
.c
-2] = n
.n
[n
.c
-1];
185 for (v
= f
->versions
; v
; v
= v
->next
) {
186 if (cvs_same_branch (&n
, &v
->number
) &&
187 cvs_number_compare (&n
, &v
->number
) > 0)
194 cvs_branch_parent (cvs_file
*f
, cvs_number
*branch
)
201 for (v
= f
->versions
; v
; v
= v
->next
) {
202 if (cvs_same_branch (&n
, &v
->number
) &&
203 cvs_number_compare (branch
, &v
->number
) < 0 &&
204 cvs_number_compare (&n
, &v
->number
) >= 0)
211 cvs_find_version (cvs_file
*cvs
, cvs_number
*number
)
214 cvs_version
*nv
= NULL
;
216 for (cv
= cvs
->versions
; cv
; cv
= cv
->next
) {
217 if (cvs_same_branch (number
, &cv
->number
) &&
218 cvs_number_compare (&cv
->number
, number
) > 0 &&
219 (!nv
|| cvs_number_compare (&nv
->number
, &cv
->number
) > 0))
222 return nv
? nv
->node
: NULL
;
226 cvs_is_trunk (cvs_number
*number
)
228 return number
->c
== 2;
232 * Import branches are of the form 1.1.x where x is odd
235 cvs_is_vendor (cvs_number
*number
)
237 if (number
->c
!= 4) return 0;
238 if (number
->n
[0] != 1)
240 if (number
->n
[1] != 1)
242 if ((number
->n
[2] & 1) != 1)
248 cvs_symbol_free (cvs_symbol
*symbol
)
252 while ((s
= symbol
)) {
259 cvs_branch_free (cvs_branch
*branch
)
263 while ((b
= branch
)) {
270 cvs_version_free (cvs_version
*version
)
274 while ((v
= version
)) {
276 cvs_branch_free (v
->branches
);
282 cvs_patch_free (cvs_patch
*patch
)
286 while ((v
= patch
)) {
294 cvs_file_free (cvs_file
*cvs
)
296 cvs_symbol_free (cvs
->symbols
);
297 cvs_version_free (cvs
->versions
);
298 cvs_patch_free (cvs
->patches
);
304 cvs_number_string (cvs_number
*n
, char *str
)
310 for (i
= 0; i
< n
->c
; i
++) {
311 snprintf (r
, 10, "%d", n
->n
[i
]);