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)");
60 if (!(cvsfp
= popen("cvs version 2>nul", "r")))
62 if (!(cvsfp
= popen("cvs version 2>/dev/null", "r")))
65 debug(DEBUG_APPERROR
, "cannot popen cvs version. exiting");
69 if (!fgets(client_version
, BUFSIZ
, cvsfp
))
71 debug(DEBUG_APPMSG1
, "WARNING: malformed CVS version: no data");
77 if (strncmp(client_version
, "Client", 6) == 0)
79 if (!fgets(server_version
, BUFSIZ
, cvsfp
))
81 debug(DEBUG_APPMSG1
, "WARNING: malformed CVS version: no server data");
88 server_version
[0] = 0;
95 int check_cvs_version(int req_major
, int req_minor
, int req_extra
)
97 if (!client_version
[0])
100 cvs_version(cvs_direct_ctx
, client_version
, server_version
);
102 get_version_external();
105 return (check_version_string(client_version
, req_major
, req_minor
, req_extra
) &&
106 (!server_version
[0] || check_version_string(server_version
, req_major
, req_minor
, req_extra
)));
109 int check_version_string(const char * str
, int req_major
, int req_minor
, int req_extra
)
112 int major
, minor
, extra
;
115 p
= strstr(str
, "(CVS) ");
118 p
= strstr(str
, "(CVSNT)");
124 debug(DEBUG_APPMSG1
, "WARNING: malformed CVS version str: %s", str
);
129 if (sscanf(p
, "%d.%d.%d", &major
, &minor
, &extra
) != 3)
131 debug(DEBUG_APPMSG1
, "WARNING: malformed CVS version: %s", str
);
135 return (major
> req_major
||
136 (major
== req_major
&& minor
> req_minor
) ||
137 (major
== req_major
&& minor
== req_minor
&& extra
>= req_extra
));