Add test about issue with no commit on a branch
[cvsps-hv.git] / cap.c
bloba1927dfc5b6d16cb7fd798361dafedf1486747b1
1 /*
2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #include <cbtcommon/debug.h>
11 #include <cbtcommon/text_util.h>
13 #include "cap.h"
14 #include "cvs_direct.h"
16 extern CvsServerCtx * cvs_direct_ctx;
18 static char client_version[BUFSIZ];
19 static char server_version[BUFSIZ];
21 static int check_cvs_version(int, int, int);
22 static int check_version_string(const char *, int, int, int);
24 int cvs_check_cap(int cap)
26 int ret;
28 switch(cap)
30 case CAP_HAVE_RLOG:
31 if (!(ret = check_cvs_version(1,11,1)))
33 debug(DEBUG_APPERROR,
34 "WARNING: Your CVS client version:\n[%s]\n"
35 "and/or server version:\n[%s]\n"
36 "are too old to properly support the rlog command. \n"
37 "This command was introduced in 1.11.1. Cvsps\n"
38 "will use log instead, but PatchSet numbering\n"
39 "may become unstable due to pruned empty\n"
40 "directories.\n", client_version, server_version);
42 break;
44 default:
45 debug(DEBUG_APPERROR, "unknown cvs capability check %d", cap);
46 exit(1);
49 return ret;
52 static void get_version_external()
54 FILE * cvsfp;
56 strcpy(client_version, "(UNKNOWN CLIENT)");
57 strcpy(server_version, "(UNKNOWN SERVER)");
59 if (!(cvsfp = popen("cvs version 2>/dev/null", "r")))
61 debug(DEBUG_APPERROR, "cannot popen cvs version. exiting");
62 exit(1);
65 if (!fgets(client_version, BUFSIZ, cvsfp))
67 debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: no data");
68 goto out;
71 chop(client_version);
73 if (strncmp(client_version, "Client", 6) == 0)
75 if (!fgets(server_version, BUFSIZ, cvsfp))
77 debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: no server data");
78 goto out;
80 chop(server_version);
82 else
84 server_version[0] = 0;
87 out:
88 pclose(cvsfp);
91 int check_cvs_version(int req_major, int req_minor, int req_extra)
93 if (!client_version[0])
95 if (cvs_direct_ctx)
96 cvs_version(cvs_direct_ctx, client_version, server_version);
97 else
98 get_version_external();
101 return (check_version_string(client_version, req_major, req_minor, req_extra) &&
102 (!server_version[0] || check_version_string(server_version, req_major, req_minor, req_extra)));
105 int check_version_string(const char * str, int req_major, int req_minor, int req_extra)
107 char * p;
108 int major, minor, extra;
109 int skip = 6;
111 p = strstr(str, "(CVS) ");
113 if (!p) {
114 p = strstr(str, "(CVSNT)");
115 skip = 8;
118 if (!p)
120 debug(DEBUG_APPMSG1, "WARNING: malformed CVS version str: %s", str);
121 return 0;
124 /* We might have encountered a FreeBSD system which
125 * has a mucked up version string of:
126 * Concurrent Versions System (CVS) '1.11.17'-FreeBSD (client/server)
127 * so re-test just in case
129 p += skip;
130 if (sscanf(p, "%d.%d.%d", &major, &minor, &extra) != 3)
132 if (sscanf(p, "'%d.%d.%d'", &major, &minor, &extra) != 3)
134 debug(DEBUG_APPMSG1, "WARNING: malformed CVS version: %s", str);
135 return 0;
139 return (major > req_major ||
140 (major == req_major && minor > req_minor) ||
141 (major == req_major && minor == req_minor && extra >= req_extra));