summaryrefslogtreecommitdiffstats
path: root/contrib/cvs/src/subr.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cvs/src/subr.c')
-rw-r--r--contrib/cvs/src/subr.c84
1 files changed, 25 insertions, 59 deletions
diff --git a/contrib/cvs/src/subr.c b/contrib/cvs/src/subr.c
index 75f26cb..7a6acfb 100644
--- a/contrib/cvs/src/subr.c
+++ b/contrib/cvs/src/subr.c
@@ -403,9 +403,9 @@ gca (rev1, rev2)
const char *rev2;
{
int dots;
- char *gca;
- const char *p[2];
- int j[2];
+ char *gca, *g;
+ const char *p1, *p2;
+ int r1, r2;
char *retval;
if (rev1 == NULL || rev2 == NULL)
@@ -417,52 +417,27 @@ gca (rev1, rev2)
/* The greatest common ancestor will have no more dots, and numbers
of digits for each component no greater than the arguments. Therefore
this string will be big enough. */
- gca = xmalloc (strlen (rev1) + strlen (rev2) + 100);
+ g = gca = xmalloc (strlen (rev1) + strlen (rev2) + 100);
/* walk the strings, reading the common parts. */
- gca[0] = '\0';
- p[0] = rev1;
- p[1] = rev2;
+ p1 = rev1;
+ p2 = rev2;
do
{
- int i;
- char c[2];
- char *s[2];
-
- for (i = 0; i < 2; ++i)
- {
- /* swap out the dot */
- s[i] = strchr (p[i], '.');
- if (s[i] != NULL) {
- c[i] = *s[i];
- }
-
- /* read an int */
- j[i] = atoi (p[i]);
-
- /* swap back the dot... */
- if (s[i] != NULL) {
- *s[i] = c[i];
- p[i] = s[i] + 1;
- }
- else
- {
- /* or mark us at the end */
- p[i] = NULL;
- }
-
- }
+ r1 = strtol (p1, (char **) &p1, 10);
+ r2 = strtol (p2, (char **) &p2, 10);
/* use the lowest. */
- (void) sprintf (gca + strlen (gca), "%d.",
- j[0] < j[1] ? j[0] : j[1]);
-
- } while (j[0] == j[1]
- && p[0] != NULL
- && p[1] != NULL);
+ (void) sprintf (g, "%d.", r1 < r2 ? r1 : r2);
+ g += strlen (g);
+ if (*p1 == '.') ++p1;
+ else break;
+ if (*p2 == '.') ++p2;
+ else break;
+ } while (r1 == r2);
- /* back up over that last dot. */
- gca[strlen(gca) - 1] = '\0';
+ /* erase that last dot. */
+ *--g = '\0';
/* numbers differ, or we ran out of strings. we're done with the
common parts. */
@@ -472,12 +447,8 @@ gca (rev1, rev2)
{
/* revisions differ in trunk major number. */
- char *q;
- const char *s;
-
- s = (j[0] < j[1]) ? p[0] : p[1];
-
- if (s == NULL)
+ if (r2 < r1) p1 = p2;
+ if (*p1 == '\0')
{
/* we only got one number. this is strange. */
error (0, 0, "bad revisions %s or %s", rev1, rev2);
@@ -486,13 +457,10 @@ gca (rev1, rev2)
else
{
/* we have a minor number. use it. */
- q = gca + strlen (gca);
-
- *q++ = '.';
- for ( ; *s != '.' && *s != '\0'; )
- *q++ = *s++;
-
- *q = '\0';
+ *g++ = '.';
+ while (*p1 != '.' && *p1 != '\0')
+ *g++ = *p1++;
+ *g = '\0';
}
}
else if ((dots & 1) == 0)
@@ -500,10 +468,8 @@ gca (rev1, rev2)
/* if we have an even number of dots, then we have a branch.
remove the last number in order to make it a revision. */
- char *s;
-
- s = strrchr(gca, '.');
- *s = '\0';
+ g = strrchr (gca, '.');
+ *g = '\0';
}
retval = xstrdup (gca);
OpenPOWER on IntegriCloud