2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc.
3 * See COPYING file for license information
10 #include <cbtcommon/debug.h>
11 #include <cbtcommon/text_util.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
)
31 if (!(ret
= check_cvs_version(1,11,1)))
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
);
45 debug(DEBUG_APPERROR
, "unknown cvs capability check %d", cap
);
52 static void get_version_external()
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");
65 if (!fgets(client_version
, BUFSIZ
, cvsfp
))
67 debug(DEBUG_APPMSG1
, "WARNING: malformed CVS version: no data");
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");
84 server_version
[0] = 0;
91 int check_cvs_version(int req_major
, int req_minor
, int req_extra
)
93 if (!client_version
[0])
96 cvs_version(cvs_direct_ctx
, client_version
, server_version
);
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
)
108 int major
, minor
, extra
;
111 p
= strstr(str
, "(CVS) ");
114 p
= strstr(str
, "(CVSNT)");
120 debug(DEBUG_APPMSG1
, "WARNING: malformed CVS version str: %s", str
);
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
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
);
139 return (major
> req_major
||
140 (major
== req_major
&& minor
> req_minor
) ||
141 (major
== req_major
&& minor
== req_minor
&& extra
>= req_extra
));