Skip to content

Commit f585b12

Browse files
committed
posix: remove superseded POSIX regex wrappers
The old POSIX regex wrappers have been superseded by our own regexp API that provides a higher-level abstraction. Remove the POSIX wrappers in favor of the new one.
1 parent 7aacf02 commit f585b12

File tree

6 files changed

+2
-219
lines changed

6 files changed

+2
-219
lines changed

cmake/Modules/FindPCRE2.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
2020

2121
# Look for the library.
2222
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8)
23-
FIND_LIBRARY(PCRE2_POSIX_LIBRARY NAMES pcre2-posix)
2423

2524
# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
2625
INCLUDE(FindPackageHandleStandardArgs)
27-
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_POSIX_LIBRARY PCRE2_INCLUDE_DIR)
26+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
2827

2928
# Copy the results to the output variables.
3029
IF(PCRE2_FOUND)
31-
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY} ${PCRE2_POSIX_LIBRARY})
30+
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
3231
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
3332
ELSE(PCRE2_FOUND)
3433
SET(PCRE2_LIBRARIES)

src/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
#include "git2/deprecated.h"
8989

9090
#include "posix.h"
91-
#include "posix_regex.h"
9291

9392
#define DEFAULT_BUFSIZE 65536
9493
#define FILEIO_BUFSIZE DEFAULT_BUFSIZE

src/errors.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,6 @@ void git_error_set_str(int error_class, const char *string)
110110
set_error_from_buffer(error_class);
111111
}
112112

113-
int git_error_set_regex(const p_regex_t *regex, int error_code)
114-
{
115-
char error_buf[1024];
116-
117-
assert(error_code);
118-
119-
p_regerror(error_code, regex, error_buf, sizeof(error_buf));
120-
git_error_set_str(GIT_ERROR_REGEX, error_buf);
121-
122-
if (error_code == P_REG_NOMATCH)
123-
return GIT_ENOTFOUND;
124-
125-
return GIT_EINVALIDSPEC;
126-
}
127-
128113
void git_error_clear(void)
129114
{
130115
if (GIT_GLOBAL->last_error != NULL) {

src/errors.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#ifndef INCLUDE_errors_h__
99
#define INCLUDE_errors_h__
1010

11-
#include "posix_regex.h"
1211
#include "common.h"
1312

1413
/*
@@ -17,12 +16,6 @@
1716
void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3);
1817
void git_error_vset(int error_class, const char *fmt, va_list ap);
1918

20-
/**
21-
* Set the error message for a regex failure, using the internal regex
22-
* error code lookup and return a libgit error code.
23-
*/
24-
int git_error_set_regex(const p_regex_t *regex, int error_code);
25-
2619
/**
2720
* Set error message for user callback if needed.
2821
*

src/posix_regex.h

Lines changed: 0 additions & 73 deletions
This file was deleted.

tests/core/posix.c

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,12 @@
99
# endif
1010
#endif
1111

12-
#include <locale.h>
13-
1412
#include "clar_libgit2.h"
1513
#include "futils.h"
1614
#include "posix.h"
17-
#include "userdiff.h"
18-
19-
#if LC_ALL > 0
20-
static const char *old_locales[LC_ALL];
21-
#endif
2215

2316
void test_core_posix__initialize(void)
2417
{
25-
#if LC_ALL > 0
26-
memset(&old_locales, 0, sizeof(old_locales));
27-
#endif
28-
2918
#ifdef GIT_WIN32
3019
/* on win32, the WSA context needs to be initialized
3120
* before any socket calls can be performed */
@@ -156,115 +145,6 @@ void test_core_posix__utimes(void)
156145
cl_must_pass(p_unlink("foo"));
157146
}
158147

159-
static void try_set_locale(int category)
160-
{
161-
#if LC_ALL > 0
162-
old_locales[category] = setlocale(category, NULL);
163-
#endif
164-
165-
if (!setlocale(category, "UTF-8") &&
166-
!setlocale(category, "c.utf8") &&
167-
!setlocale(category, "en_US.UTF-8"))
168-
cl_skip();
169-
170-
if (MB_CUR_MAX == 1)
171-
cl_fail("Expected locale to be switched to multibyte");
172-
}
173-
174-
void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
175-
{
176-
p_regex_t preg;
177-
178-
try_set_locale(LC_CTYPE);
179-
180-
cl_assert(!p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", P_REG_EXTENDED));
181-
182-
p_regfree(&preg);
183-
}
184-
185-
void test_core_posix__p_regcomp_ignores_global_locale_collate(void)
186-
{
187-
p_regex_t preg;
188-
189-
#ifdef GIT_WIN32
190-
cl_skip();
191-
#endif
192-
193-
try_set_locale(LC_COLLATE);
194-
cl_assert(!p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", P_REG_EXTENDED));
195-
196-
p_regfree(&preg);
197-
}
198-
199-
void test_core_posix__p_regcomp_matches_digits_with_locale(void)
200-
{
201-
p_regex_t preg;
202-
char c, str[2];
203-
204-
#ifdef GIT_WIN32
205-
cl_skip();
206-
#endif
207-
208-
try_set_locale(LC_COLLATE);
209-
try_set_locale(LC_CTYPE);
210-
211-
cl_assert(!p_regcomp(&preg, "[[:digit:]]", P_REG_EXTENDED));
212-
213-
str[1] = '\0';
214-
for (c = '0'; c <= '9'; c++) {
215-
str[0] = c;
216-
cl_assert(!p_regexec(&preg, str, 0, NULL, 0));
217-
}
218-
219-
p_regfree(&preg);
220-
}
221-
222-
void test_core_posix__p_regcomp_matches_alphabet_with_locale(void)
223-
{
224-
p_regex_t preg;
225-
char c, str[2];
226-
227-
#ifdef GIT_WIN32
228-
cl_skip();
229-
#endif
230-
231-
try_set_locale(LC_COLLATE);
232-
try_set_locale(LC_CTYPE);
233-
234-
cl_assert(!p_regcomp(&preg, "[[:alpha:]]", P_REG_EXTENDED));
235-
236-
str[1] = '\0';
237-
for (c = 'a'; c <= 'z'; c++) {
238-
str[0] = c;
239-
cl_assert(!p_regexec(&preg, str, 0, NULL, 0));
240-
}
241-
for (c = 'A'; c <= 'Z'; c++) {
242-
str[0] = c;
243-
cl_assert(!p_regexec(&preg, str, 0, NULL, 0));
244-
}
245-
246-
p_regfree(&preg);
247-
}
248-
249-
void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
250-
{
251-
size_t idx;
252-
253-
for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
254-
git_diff_driver_definition ddef = builtin_defs[idx];
255-
int error = 0;
256-
p_regex_t preg;
257-
258-
error = p_regcomp(&preg, ddef.fns, P_REG_EXTENDED | ddef.flags);
259-
p_regfree(&preg);
260-
cl_assert(!error);
261-
262-
error = p_regcomp(&preg, ddef.words, P_REG_EXTENDED);
263-
p_regfree(&preg);
264-
cl_assert(!error);
265-
}
266-
}
267-
268148
void test_core_posix__unlink_removes_symlink(void)
269149
{
270150
if (!git_path_supports_symlinks(clar_sandbox_path()))

0 commit comments

Comments
 (0)