rugged 1.6.2 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_allocator.c +0 -54
  3. data/lib/rugged/version.rb +1 -1
  4. data/vendor/libgit2/CMakeLists.txt +3 -8
  5. data/vendor/libgit2/cmake/CheckPrototypeDefinitionSafe.cmake +16 -0
  6. data/vendor/libgit2/cmake/SelectGSSAPI.cmake +3 -3
  7. data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +21 -2
  8. data/vendor/libgit2/cmake/SelectHashes.cmake +4 -0
  9. data/vendor/libgit2/cmake/SelectXdiff.cmake +9 -0
  10. data/vendor/libgit2/deps/pcre/LICENCE +5 -5
  11. data/vendor/libgit2/deps/pcre/pcre.h +2 -2
  12. data/vendor/libgit2/deps/pcre/pcre_compile.c +6 -3
  13. data/vendor/libgit2/deps/pcre/pcre_exec.c +2 -2
  14. data/vendor/libgit2/deps/xdiff/CMakeLists.txt +28 -0
  15. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/git-xdiff.h +4 -1
  16. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.c +19 -18
  17. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiffi.h +2 -4
  18. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.c +3 -3
  19. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xhistogram.c +7 -18
  20. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmacros.h +18 -1
  21. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xmerge.c +24 -22
  22. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xpatience.c +21 -30
  23. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.c +13 -30
  24. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.c +18 -1
  25. data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xutils.h +2 -1
  26. data/vendor/libgit2/include/git2/common.h +26 -1
  27. data/vendor/libgit2/include/git2/diff.h +41 -3
  28. data/vendor/libgit2/include/git2/errors.h +4 -2
  29. data/vendor/libgit2/include/git2/index.h +9 -0
  30. data/vendor/libgit2/include/git2/oid.h +1 -1
  31. data/vendor/libgit2/include/git2/remote.h +18 -0
  32. data/vendor/libgit2/include/git2/repository.h +12 -2
  33. data/vendor/libgit2/include/git2/sys/alloc.h +0 -34
  34. data/vendor/libgit2/include/git2/sys/commit_graph.h +12 -2
  35. data/vendor/libgit2/include/git2/sys/midx.h +5 -1
  36. data/vendor/libgit2/include/git2/sys/stream.h +16 -2
  37. data/vendor/libgit2/include/git2/sys/transport.h +20 -2
  38. data/vendor/libgit2/include/git2/version.h +4 -4
  39. data/vendor/libgit2/include/git2/worktree.h +3 -1
  40. data/vendor/libgit2/src/CMakeLists.txt +34 -11
  41. data/vendor/libgit2/src/cli/CMakeLists.txt +0 -1
  42. data/vendor/libgit2/src/cli/cmd_clone.c +22 -6
  43. data/vendor/libgit2/src/cli/progress.c +9 -8
  44. data/vendor/libgit2/src/cli/progress.h +4 -4
  45. data/vendor/libgit2/src/libgit2/CMakeLists.txt +1 -20
  46. data/vendor/libgit2/src/libgit2/annotated_commit.c +2 -2
  47. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  48. data/vendor/libgit2/src/libgit2/apply.c +4 -3
  49. data/vendor/libgit2/src/libgit2/blame.c +23 -16
  50. data/vendor/libgit2/src/libgit2/blame_git.c +0 -1
  51. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  52. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  53. data/vendor/libgit2/src/libgit2/clone.c +3 -1
  54. data/vendor/libgit2/src/libgit2/commit.c +31 -9
  55. data/vendor/libgit2/src/libgit2/commit_graph.c +110 -43
  56. data/vendor/libgit2/src/libgit2/commit_graph.h +20 -4
  57. data/vendor/libgit2/src/libgit2/commit_list.c +12 -5
  58. data/vendor/libgit2/src/libgit2/commit_list.h +1 -0
  59. data/vendor/libgit2/src/libgit2/config.c +5 -2
  60. data/vendor/libgit2/src/libgit2/config_file.c +14 -8
  61. data/vendor/libgit2/src/libgit2/describe.c +10 -7
  62. data/vendor/libgit2/src/libgit2/diff.c +16 -7
  63. data/vendor/libgit2/src/libgit2/diff.h +6 -6
  64. data/vendor/libgit2/src/libgit2/diff_file.c +7 -7
  65. data/vendor/libgit2/src/libgit2/diff_generate.c +36 -15
  66. data/vendor/libgit2/src/libgit2/diff_parse.c +20 -4
  67. data/vendor/libgit2/src/libgit2/diff_print.c +26 -7
  68. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -4
  69. data/vendor/libgit2/src/libgit2/diff_xdiff.h +1 -1
  70. data/vendor/libgit2/src/libgit2/email.c +4 -3
  71. data/vendor/libgit2/src/libgit2/errors.c +73 -18
  72. data/vendor/libgit2/src/libgit2/fetch.c +37 -9
  73. data/vendor/libgit2/src/libgit2/fetch.h +0 -2
  74. data/vendor/libgit2/src/libgit2/fetchhead.c +11 -9
  75. data/vendor/libgit2/src/libgit2/grafts.c +272 -0
  76. data/vendor/libgit2/src/libgit2/grafts.h +36 -0
  77. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  78. data/vendor/libgit2/src/libgit2/index.c +325 -123
  79. data/vendor/libgit2/src/libgit2/index.h +14 -1
  80. data/vendor/libgit2/src/libgit2/indexer.c +10 -3
  81. data/vendor/libgit2/src/libgit2/iterator.c +20 -5
  82. data/vendor/libgit2/src/libgit2/iterator.h +3 -0
  83. data/vendor/libgit2/src/libgit2/libgit2.c +39 -0
  84. data/vendor/libgit2/src/libgit2/merge.c +14 -9
  85. data/vendor/libgit2/src/libgit2/merge_file.c +0 -2
  86. data/vendor/libgit2/src/libgit2/midx.c +66 -37
  87. data/vendor/libgit2/src/libgit2/midx.h +13 -3
  88. data/vendor/libgit2/src/libgit2/notes.c +9 -8
  89. data/vendor/libgit2/src/libgit2/object.c +40 -15
  90. data/vendor/libgit2/src/libgit2/object.h +6 -0
  91. data/vendor/libgit2/src/libgit2/odb.c +30 -5
  92. data/vendor/libgit2/src/libgit2/odb_pack.c +16 -3
  93. data/vendor/libgit2/src/libgit2/oid.c +7 -1
  94. data/vendor/libgit2/src/libgit2/oidarray.c +49 -3
  95. data/vendor/libgit2/src/libgit2/oidarray.h +5 -1
  96. data/vendor/libgit2/src/libgit2/pack-objects.c +19 -12
  97. data/vendor/libgit2/src/libgit2/pack-objects.h +5 -2
  98. data/vendor/libgit2/src/libgit2/pack.c +7 -8
  99. data/vendor/libgit2/src/libgit2/parse.c +7 -4
  100. data/vendor/libgit2/src/libgit2/parse.h +1 -1
  101. data/vendor/libgit2/src/libgit2/patch.h +7 -1
  102. data/vendor/libgit2/src/libgit2/patch_generate.c +24 -5
  103. data/vendor/libgit2/src/libgit2/patch_parse.c +16 -8
  104. data/vendor/libgit2/src/libgit2/push.c +2 -2
  105. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  106. data/vendor/libgit2/src/libgit2/rebase.c +72 -84
  107. data/vendor/libgit2/src/libgit2/refdb_fs.c +22 -13
  108. data/vendor/libgit2/src/libgit2/refs.c +8 -1
  109. data/vendor/libgit2/src/libgit2/remote.c +15 -6
  110. data/vendor/libgit2/src/libgit2/remote.h +1 -0
  111. data/vendor/libgit2/src/libgit2/repository.c +580 -301
  112. data/vendor/libgit2/src/libgit2/repository.h +17 -2
  113. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  114. data/vendor/libgit2/src/libgit2/revert.c +8 -11
  115. data/vendor/libgit2/src/libgit2/revwalk.c +26 -4
  116. data/vendor/libgit2/src/libgit2/stash.c +9 -8
  117. data/vendor/libgit2/src/libgit2/streams/mbedtls.c +0 -1
  118. data/vendor/libgit2/src/libgit2/streams/openssl.c +8 -16
  119. data/vendor/libgit2/src/libgit2/streams/schannel.c +715 -0
  120. data/vendor/libgit2/src/libgit2/streams/schannel.h +28 -0
  121. data/vendor/libgit2/src/libgit2/streams/socket.c +237 -51
  122. data/vendor/libgit2/src/libgit2/streams/socket.h +3 -1
  123. data/vendor/libgit2/src/libgit2/streams/stransport.c +40 -12
  124. data/vendor/libgit2/src/libgit2/streams/tls.c +5 -0
  125. data/vendor/libgit2/src/libgit2/submodule.h +3 -3
  126. data/vendor/libgit2/src/libgit2/sysdir.h +2 -0
  127. data/vendor/libgit2/src/libgit2/threadstate.c +15 -2
  128. data/vendor/libgit2/src/libgit2/threadstate.h +1 -3
  129. data/vendor/libgit2/src/libgit2/transports/auth.h +1 -2
  130. data/vendor/libgit2/src/libgit2/transports/{auth_negotiate.c → auth_gssapi.c} +32 -32
  131. data/vendor/libgit2/src/libgit2/transports/auth_negotiate.h +1 -1
  132. data/vendor/libgit2/src/libgit2/transports/auth_ntlm.h +1 -1
  133. data/vendor/libgit2/src/libgit2/transports/{auth_ntlm.c → auth_ntlmclient.c} +12 -12
  134. data/vendor/libgit2/src/libgit2/transports/auth_sspi.c +341 -0
  135. data/vendor/libgit2/src/libgit2/transports/git.c +7 -8
  136. data/vendor/libgit2/src/libgit2/transports/http.c +7 -2
  137. data/vendor/libgit2/src/libgit2/transports/httpclient.c +5 -0
  138. data/vendor/libgit2/src/libgit2/transports/local.c +13 -4
  139. data/vendor/libgit2/src/libgit2/transports/smart.c +33 -27
  140. data/vendor/libgit2/src/libgit2/transports/smart.h +23 -8
  141. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +135 -15
  142. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +154 -47
  143. data/vendor/libgit2/src/libgit2/transports/ssh.c +3 -3
  144. data/vendor/libgit2/src/libgit2/transports/winhttp.c +14 -15
  145. data/vendor/libgit2/src/libgit2/tree-cache.c +26 -16
  146. data/vendor/libgit2/src/libgit2/tree-cache.h +5 -3
  147. data/vendor/libgit2/src/libgit2/tree.c +1 -1
  148. data/vendor/libgit2/src/libgit2/worktree.c +25 -10
  149. data/vendor/libgit2/src/util/CMakeLists.txt +0 -1
  150. data/vendor/libgit2/src/util/alloc.c +65 -6
  151. data/vendor/libgit2/src/util/alloc.h +34 -9
  152. data/vendor/libgit2/src/util/allocators/failalloc.c +0 -60
  153. data/vendor/libgit2/src/util/allocators/failalloc.h +0 -6
  154. data/vendor/libgit2/src/util/allocators/stdalloc.c +2 -105
  155. data/vendor/libgit2/src/util/allocators/win32_leakcheck.c +0 -68
  156. data/vendor/libgit2/src/util/array.h +6 -1
  157. data/vendor/libgit2/src/util/cc-compat.h +2 -0
  158. data/vendor/libgit2/src/util/filebuf.c +6 -1
  159. data/vendor/libgit2/src/util/filebuf.h +19 -6
  160. data/vendor/libgit2/src/util/fs_path.c +1 -1
  161. data/vendor/libgit2/src/util/futils.c +8 -5
  162. data/vendor/libgit2/src/util/git2_features.h.in +9 -3
  163. data/vendor/libgit2/src/util/net.c +308 -157
  164. data/vendor/libgit2/src/util/net.h +25 -0
  165. data/vendor/libgit2/src/util/posix.c +54 -0
  166. data/vendor/libgit2/src/util/posix.h +22 -0
  167. data/vendor/libgit2/src/util/rand.c +6 -4
  168. data/vendor/libgit2/src/util/staticstr.h +66 -0
  169. data/vendor/libgit2/src/util/util.c +15 -10
  170. data/vendor/libgit2/src/util/util.h +24 -16
  171. data/vendor/libgit2/src/util/win32/error.c +1 -1
  172. data/vendor/libgit2/src/util/win32/path_w32.c +8 -8
  173. data/vendor/libgit2/src/util/win32/posix_w32.c +1 -1
  174. data/vendor/libgit2/src/util/win32/utf-conv.c +73 -75
  175. data/vendor/libgit2/src/util/win32/utf-conv.h +81 -14
  176. data/vendor/libgit2/src/util/win32/w32_util.c +1 -1
  177. metadata +29 -23
  178. data/vendor/libgit2/cmake/SelectWinHTTP.cmake +0 -17
  179. data/vendor/libgit2/src/libgit2/netops.c +0 -124
  180. data/vendor/libgit2/src/libgit2/netops.h +0 -68
  181. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xdiff.h +0 -0
  182. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xemit.h +0 -0
  183. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xinclude.h +0 -0
  184. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xprepare.h +0 -0
  185. /data/vendor/libgit2/{src/libgit2 → deps}/xdiff/xtypes.h +0 -0
@@ -9,6 +9,23 @@
9
9
 
10
10
  #include "git2_util.h"
11
11
 
12
+ /*
13
+ * Hostname handling
14
+ */
15
+
16
+ /*
17
+ * See if a given hostname matches a certificate name pattern, according
18
+ * to RFC2818 rules (which specifies HTTP over TLS). Mainly, an asterisk
19
+ * matches anything, but is limited to a single url component.
20
+ */
21
+ extern bool git_net_hostname_matches_cert(
22
+ const char *hostname,
23
+ const char *pattern);
24
+
25
+ /*
26
+ * URL handling
27
+ */
28
+
12
29
  typedef struct git_net_url {
13
30
  char *scheme;
14
31
  char *host;
@@ -40,6 +57,14 @@ extern int git_net_url_parse_scp(git_net_url *url, const char *str);
40
57
  */
41
58
  extern int git_net_url_parse_standard_or_scp(git_net_url *url, const char *str);
42
59
 
60
+ /**
61
+ * Parses a string containing an HTTP endpoint that may not be a
62
+ * well-formed URL. For example, "localhost" or "localhost:port".
63
+ */
64
+ extern int git_net_url_parse_http(
65
+ git_net_url *url,
66
+ const char *str);
67
+
43
68
  /** Appends a path and/or query string to the given URL */
44
69
  extern int git_net_url_joinpath(
45
70
  git_net_url *out,
@@ -301,3 +301,57 @@ int p_munmap(git_map *map)
301
301
  }
302
302
 
303
303
  #endif
304
+
305
+ #if defined(GIT_IO_POLL) || defined(GIT_IO_WSAPOLL)
306
+
307
+ /* Handled by posix.h; this test simplifies the final else */
308
+
309
+ #elif defined(GIT_IO_SELECT)
310
+
311
+ int p_poll(struct pollfd *fds, unsigned int nfds, int timeout_ms)
312
+ {
313
+ fd_set read_fds, write_fds, except_fds;
314
+ struct timeval timeout = { 0, 0 };
315
+ unsigned int i;
316
+ int max_fd = -1, ret;
317
+
318
+ FD_ZERO(&read_fds);
319
+ FD_ZERO(&write_fds);
320
+ FD_ZERO(&except_fds);
321
+
322
+ for (i = 0; i < nfds; i++) {
323
+ if ((fds[i].events & POLLIN))
324
+ FD_SET(fds[i].fd, &read_fds);
325
+
326
+ if ((fds[i].events & POLLOUT))
327
+ FD_SET(fds[i].fd, &write_fds);
328
+
329
+ if ((fds[i].events & POLLPRI))
330
+ FD_SET(fds[i].fd, &except_fds);
331
+
332
+ max_fd = MAX(max_fd, fds[i].fd);
333
+ }
334
+
335
+ if (timeout_ms > 0) {
336
+ timeout.tv_sec = timeout_ms / 1000;
337
+ timeout.tv_usec = (timeout_ms % 1000) * 1000;
338
+ }
339
+
340
+ if ((ret = select(max_fd + 1, &read_fds, &write_fds, &except_fds,
341
+ timeout_ms < 0 ? NULL : &timeout)) < 0)
342
+ goto done;
343
+
344
+ for (i = 0; i < nfds; i++) {
345
+ fds[i].revents = 0 |
346
+ FD_ISSET(fds[i].fd, &read_fds) ? POLLIN : 0 |
347
+ FD_ISSET(fds[i].fd, &write_fds) ? POLLOUT : 0 |
348
+ FD_ISSET(fds[i].fd, &except_fds) ? POLLPRI : 0;
349
+ }
350
+
351
+ done:
352
+ return ret;
353
+ }
354
+
355
+ #else
356
+ # error no poll compatible implementation
357
+ #endif
@@ -195,4 +195,26 @@ extern const char *p_gai_strerror(int ret);
195
195
  # define p_gai_strerror(c) gai_strerror(c)
196
196
  #endif /* NO_ADDRINFO */
197
197
 
198
+ #ifdef GIT_IO_POLL
199
+ # include <poll.h>
200
+ # define p_poll poll
201
+ #elif GIT_IO_WSAPOLL
202
+ # include <winsock2.h>
203
+ # define p_poll WSAPoll
204
+ #else
205
+ # define POLLIN 0x01
206
+ # define POLLPRI 0x02
207
+ # define POLLOUT 0x04
208
+ # define POLLERR 0x08
209
+ # define POLLHUP 0x10
210
+
211
+ struct pollfd {
212
+ int fd;
213
+ short events;
214
+ short revents;
215
+ };
216
+
217
+ extern int p_poll(struct pollfd *fds, unsigned int nfds, int timeout);
218
+ #endif
219
+
198
220
  #endif
@@ -32,7 +32,6 @@ GIT_INLINE(int) getseed(uint64_t *seed)
32
32
  HCRYPTPROV provider;
33
33
  SYSTEMTIME systemtime;
34
34
  FILETIME filetime, idletime, kerneltime, usertime;
35
- bits convert;
36
35
 
37
36
  if (CryptAcquireContext(&provider, 0, 0, PROV_RSA_FULL,
38
37
  CRYPT_VERIFYCONTEXT|CRYPT_SILENT)) {
@@ -67,7 +66,7 @@ GIT_INLINE(int) getseed(uint64_t *seed)
67
66
  *seed ^= ((uint64_t)GetCurrentProcessId() << 32);
68
67
  *seed ^= ((uint64_t)GetCurrentThreadId() << 48);
69
68
 
70
- convert.f = git__timer(); *seed ^= (convert.d);
69
+ *seed ^= git_time_monotonic();
71
70
 
72
71
  /* Mix in the addresses of some functions and variables */
73
72
  *seed ^= (((uint64_t)((uintptr_t)seed) << 32));
@@ -82,9 +81,12 @@ GIT_INLINE(int) getseed(uint64_t *seed)
82
81
  {
83
82
  struct timeval tv;
84
83
  double loadavg[3];
85
- bits convert;
86
84
  int fd;
87
85
 
86
+ # if defined(GIT_RAND_GETLOADAVG)
87
+ bits convert;
88
+ # endif
89
+
88
90
  # if defined(GIT_RAND_GETENTROPY)
89
91
  GIT_UNUSED((fd = 0));
90
92
 
@@ -131,7 +133,7 @@ GIT_INLINE(int) getseed(uint64_t *seed)
131
133
  GIT_UNUSED(loadavg[0]);
132
134
  # endif
133
135
 
134
- convert.f = git__timer(); *seed ^= (convert.d);
136
+ *seed ^= git_time_monotonic();
135
137
 
136
138
  /* Mix in the addresses of some variables */
137
139
  *seed ^= ((uint64_t)((size_t)((void *)seed)) << 32);
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_stackstr_h__
8
+ #define INCLUDE_stackstr_h__
9
+
10
+ #include "git2_util.h"
11
+
12
+ typedef struct {
13
+ /* Length of / number of bytes used by `data`. */
14
+ size_t len;
15
+
16
+ /* Size of the allocated `data` buffer. */
17
+ size_t size;
18
+
19
+ /* The actual string buffer data. */
20
+ char data[GIT_FLEX_ARRAY];
21
+ } git_staticstr;
22
+
23
+ #define git_staticstr_with_size(__size) \
24
+ struct { \
25
+ size_t len; \
26
+ size_t size; \
27
+ char data[__size]; \
28
+ }
29
+
30
+ #define git_staticstr_init(__str, __size) \
31
+ do { \
32
+ (__str)->len = 0; \
33
+ (__str)->size = __size; \
34
+ (__str)->data[0] = '\0'; \
35
+ } while(0)
36
+
37
+ #define git_staticstr_offset(__str) \
38
+ ((__str)->data + (__str)->len)
39
+
40
+ #define git_staticstr_remain(__str) \
41
+ ((__str)->len > (__str)->size ? 0 : ((__str)->size - (__str)->len))
42
+
43
+ #define git_staticstr_increase(__str, __len) \
44
+ do { ((__str)->len += __len); } while(0)
45
+
46
+ #define git_staticstr_consume_bytes(__str, __len) \
47
+ do { git_staticstr_consume(__str, (__str)->data + __len); } while(0)
48
+
49
+ #define git_staticstr_consume(__str, __end) \
50
+ do { \
51
+ if (__end > (__str)->data && \
52
+ __end <= (__str)->data + (__str)->len) { \
53
+ size_t __consumed = __end - (__str)->data; \
54
+ memmove((__str)->data, __end, (__str)->len - __consumed); \
55
+ (__str)->len -= __consumed; \
56
+ (__str)->data[(__str)->len] = '\0'; \
57
+ } \
58
+ } while(0)
59
+
60
+ #define git_staticstr_clear(__str) \
61
+ do { \
62
+ (__str)->len = 0; \
63
+ (__str)->data[0] = 0; \
64
+ } while(0)
65
+
66
+ #endif
@@ -18,7 +18,7 @@
18
18
  # endif
19
19
  # include <windows.h>
20
20
 
21
- # ifdef GIT_QSORT_S
21
+ # ifdef GIT_QSORT_MSC
22
22
  # include <search.h>
23
23
  # endif
24
24
  #endif
@@ -673,7 +673,7 @@ size_t git__unescape(char *str)
673
673
  return (pos - str);
674
674
  }
675
675
 
676
- #if defined(GIT_QSORT_S) || defined(GIT_QSORT_R_BSD)
676
+ #if defined(GIT_QSORT_MSC) || defined(GIT_QSORT_BSD)
677
677
  typedef struct {
678
678
  git__sort_r_cmp cmp;
679
679
  void *payload;
@@ -688,9 +688,11 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp(
688
688
  #endif
689
689
 
690
690
 
691
- #if !defined(GIT_QSORT_R_BSD) && \
692
- !defined(GIT_QSORT_R_GNU) && \
693
- !defined(GIT_QSORT_S)
691
+ #if !defined(GIT_QSORT_BSD) && \
692
+ !defined(GIT_QSORT_GNU) && \
693
+ !defined(GIT_QSORT_C11) && \
694
+ !defined(GIT_QSORT_MSC)
695
+
694
696
  static void swap(uint8_t *a, uint8_t *b, size_t elsize)
695
697
  {
696
698
  char tmp[256];
@@ -716,17 +718,20 @@ static void insertsort(
716
718
  for (j = i; j > base && cmp(j, j - elsize, payload) < 0; j -= elsize)
717
719
  swap(j, j - elsize, elsize);
718
720
  }
721
+
719
722
  #endif
720
723
 
721
724
  void git__qsort_r(
722
725
  void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload)
723
726
  {
724
- #if defined(GIT_QSORT_R_BSD)
727
+ #if defined(GIT_QSORT_GNU)
728
+ qsort_r(els, nel, elsize, cmp, payload);
729
+ #elif defined(GIT_QSORT_C11)
730
+ qsort_s(els, nel, elsize, cmp, payload);
731
+ #elif defined(GIT_QSORT_BSD)
725
732
  git__qsort_r_glue glue = { cmp, payload };
726
733
  qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp);
727
- #elif defined(GIT_QSORT_R_GNU)
728
- qsort_r(els, nel, elsize, cmp, payload);
729
- #elif defined(GIT_QSORT_S)
734
+ #elif defined(GIT_QSORT_MSC)
730
735
  git__qsort_r_glue glue = { cmp, payload };
731
736
  qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue);
732
737
  #else
@@ -743,7 +748,7 @@ int git__getenv(git_str *out, const char *name)
743
748
 
744
749
  git_str_clear(out);
745
750
 
746
- if (git__utf8_to_16_alloc(&wide_name, name) < 0)
751
+ if (git_utf8_to_16_alloc(&wide_name, name) < 0)
747
752
  return -1;
748
753
 
749
754
  if ((value_len = GetEnvironmentVariableW(wide_name, NULL, 0)) > 0) {
@@ -319,59 +319,67 @@ GIT_INLINE(void) git__memzero(void *data, size_t size)
319
319
 
320
320
  #ifdef GIT_WIN32
321
321
 
322
- GIT_INLINE(double) git__timer(void)
322
+ GIT_INLINE(uint64_t) git_time_monotonic(void)
323
323
  {
324
324
  /* GetTickCount64 returns the number of milliseconds that have
325
325
  * elapsed since the system was started. */
326
- return (double) GetTickCount64() / (double) 1000;
326
+ return GetTickCount64();
327
327
  }
328
328
 
329
329
  #elif __APPLE__
330
330
 
331
331
  #include <mach/mach_time.h>
332
+ #include <sys/time.h>
332
333
 
333
- GIT_INLINE(double) git__timer(void)
334
+ GIT_INLINE(uint64_t) git_time_monotonic(void)
334
335
  {
335
- uint64_t time = mach_absolute_time();
336
- static double scaling_factor = 0;
336
+ static double scaling_factor = 0;
337
+
338
+ if (scaling_factor == 0) {
339
+ mach_timebase_info_data_t info;
337
340
 
338
- if (scaling_factor == 0) {
339
- mach_timebase_info_data_t info;
340
- (void)mach_timebase_info(&info);
341
- scaling_factor = (double)info.numer / (double)info.denom;
342
- }
341
+ scaling_factor = mach_timebase_info(&info) == KERN_SUCCESS ?
342
+ ((double)info.numer / (double)info.denom) / 1.0E6 :
343
+ -1;
344
+ } else if (scaling_factor < 0) {
345
+ struct timeval tv;
346
+
347
+ /* mach_timebase_info failed; fall back to gettimeofday */
348
+ gettimeofday(&tv, NULL);
349
+ return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
350
+ }
343
351
 
344
- return (double)time * scaling_factor / 1.0E9;
352
+ return (uint64_t)(mach_absolute_time() * scaling_factor);
345
353
  }
346
354
 
347
355
  #elif defined(__amigaos4__)
348
356
 
349
357
  #include <proto/timer.h>
350
358
 
351
- GIT_INLINE(double) git__timer(void)
359
+ GIT_INLINE(uint64_t) git_time_monotonic(void)
352
360
  {
353
361
  struct TimeVal tv;
354
362
  ITimer->GetUpTime(&tv);
355
- return (double)tv.Seconds + (double)tv.Microseconds / 1.0E6;
363
+ return (tv.Seconds * 1000) + (tv.Microseconds / 1000);
356
364
  }
357
365
 
358
366
  #else
359
367
 
360
368
  #include <sys/time.h>
361
369
 
362
- GIT_INLINE(double) git__timer(void)
370
+ GIT_INLINE(uint64_t) git_time_monotonic(void)
363
371
  {
364
372
  struct timeval tv;
365
373
 
366
374
  #ifdef CLOCK_MONOTONIC
367
375
  struct timespec tp;
368
376
  if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
369
- return (double) tp.tv_sec + (double) tp.tv_nsec / 1.0E9;
377
+ return (tp.tv_sec * 1000) + (tp.tv_nsec / 1.0E6);
370
378
  #endif
371
379
 
372
380
  /* Fall back to using gettimeofday */
373
381
  gettimeofday(&tv, NULL);
374
- return (double)tv.tv_sec + (double)tv.tv_usec / 1.0E6;
382
+ return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
375
383
  }
376
384
 
377
385
  #endif
@@ -43,7 +43,7 @@ char *git_win32_get_error_message(DWORD error_code)
43
43
  (LPWSTR)&lpMsgBuf, 0, NULL)) {
44
44
  /* Convert the message to UTF-8. If this fails, we will
45
45
  * return NULL, which is a condition expected by the caller */
46
- if (git__utf16_to_8_alloc(&utf8_msg, lpMsgBuf) < 0)
46
+ if (git_utf8_from_16_alloc(&utf8_msg, lpMsgBuf) < 0)
47
47
  utf8_msg = NULL;
48
48
 
49
49
  LocalFree(lpMsgBuf);
@@ -336,13 +336,13 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
336
336
 
337
337
  /* See if this is an absolute path (beginning with a drive letter) */
338
338
  if (git_fs_path_is_absolute(src)) {
339
- if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src) < 0)
339
+ if (git_utf8_to_16(dest, GIT_WIN_PATH_MAX, src) < 0)
340
340
  goto on_error;
341
341
  }
342
342
  /* File-prefixed NT-style paths beginning with \\?\ */
343
343
  else if (path__is_nt_namespace(src)) {
344
344
  /* Skip the NT prefix, the destination already contains it */
345
- if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src + PATH__NT_NAMESPACE_LEN) < 0)
345
+ if (git_utf8_to_16(dest, GIT_WIN_PATH_MAX, src + PATH__NT_NAMESPACE_LEN) < 0)
346
346
  goto on_error;
347
347
  }
348
348
  /* UNC paths */
@@ -351,7 +351,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
351
351
  dest += 4;
352
352
 
353
353
  /* Skip the leading "\\" */
354
- if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX - 2, src + 2) < 0)
354
+ if (git_utf8_to_16(dest, GIT_WIN_PATH_MAX - 2, src + 2) < 0)
355
355
  goto on_error;
356
356
  }
357
357
  /* Absolute paths omitting the drive letter */
@@ -365,7 +365,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
365
365
  }
366
366
 
367
367
  /* Skip the drive letter specification ("C:") */
368
- if (git__utf8_to_16(dest + 2, GIT_WIN_PATH_MAX - 2, src) < 0)
368
+ if (git_utf8_to_16(dest + 2, GIT_WIN_PATH_MAX - 2, src) < 0)
369
369
  goto on_error;
370
370
  }
371
371
  /* Relative paths */
@@ -377,7 +377,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
377
377
 
378
378
  dest[cwd_len++] = L'\\';
379
379
 
380
- if (git__utf8_to_16(dest + cwd_len, GIT_WIN_PATH_MAX - cwd_len, src) < 0)
380
+ if (git_utf8_to_16(dest + cwd_len, GIT_WIN_PATH_MAX - cwd_len, src) < 0)
381
381
  goto on_error;
382
382
  }
383
383
 
@@ -404,7 +404,7 @@ int git_win32_path_relative_from_utf8(git_win32_path out, const char *src)
404
404
  return git_win32_path_from_utf8(out, src);
405
405
  }
406
406
 
407
- if ((len = git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src)) < 0)
407
+ if ((len = git_utf8_to_16(dest, GIT_WIN_PATH_MAX, src)) < 0)
408
408
  return -1;
409
409
 
410
410
  for (p = dest; p < (dest + len); p++) {
@@ -433,7 +433,7 @@ int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src)
433
433
  }
434
434
  }
435
435
 
436
- if ((len = git__utf16_to_8(out, GIT_WIN_PATH_UTF8, src)) < 0)
436
+ if ((len = git_utf8_from_16(out, GIT_WIN_PATH_UTF8, src)) < 0)
437
437
  return len;
438
438
 
439
439
  git_fs_path_mkposix(dest);
@@ -471,7 +471,7 @@ char *git_win32_path_8dot3_name(const char *path)
471
471
  if (namelen > 12 || (shortname = git__malloc(namelen + 1)) == NULL)
472
472
  return NULL;
473
473
 
474
- if ((len = git__utf16_to_8(shortname, namelen + 1, start)) < 0)
474
+ if ((len = git_utf8_from_16(shortname, namelen + 1, start)) < 0)
475
475
  return NULL;
476
476
 
477
477
  return shortname;
@@ -649,7 +649,7 @@ int p_getcwd(char *buffer_out, size_t size)
649
649
  git_win32_path_remove_namespace(cwd, wcslen(cwd));
650
650
 
651
651
  /* Convert the working directory back to UTF-8 */
652
- if (git__utf16_to_8(buffer_out, size, cwd) < 0) {
652
+ if (git_utf8_from_16(buffer_out, size, cwd) < 0) {
653
653
  DWORD code = GetLastError();
654
654
 
655
655
  if (code == ERROR_INSUFFICIENT_BUFFER)
@@ -15,108 +15,114 @@ GIT_INLINE(void) git__set_errno(void)
15
15
  errno = EINVAL;
16
16
  }
17
17
 
18
- /**
19
- * Converts a UTF-8 string to wide characters.
20
- *
21
- * @param dest The buffer to receive the wide string.
22
- * @param dest_size The size of the buffer, in characters.
23
- * @param src The UTF-8 string to convert.
24
- * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
25
- */
26
- int git__utf8_to_16(wchar_t *dest, size_t dest_size, const char *src)
18
+ int git_utf8_to_16(wchar_t *dest, size_t dest_size, const char *src)
19
+ {
20
+ /* Length of -1 indicates NULL termination of the input string. */
21
+ return git_utf8_to_16_with_len(dest, dest_size, src, -1);
22
+ }
23
+
24
+ int git_utf8_to_16_with_len(
25
+ wchar_t *dest,
26
+ size_t _dest_size,
27
+ const char *src,
28
+ int src_len)
27
29
  {
30
+ int dest_size = (int)min(_dest_size, INT_MAX);
28
31
  int len;
29
32
 
30
- /* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to
31
- * turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's
32
- * length. MultiByteToWideChar never returns int's minvalue, so underflow is not possible */
33
- if ((len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, dest, (int)dest_size) - 1) < 0)
33
+ /*
34
+ * Subtract 1 from the result to turn 0 into -1 (an error code) and
35
+ * to not count the NULL terminator as part of the string's length.
36
+ * MultiByteToWideChar never returns int's minvalue, so underflow
37
+ * is not possible.
38
+ */
39
+ len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
40
+ src, src_len, dest, dest_size) - 1;
41
+
42
+ if (len < 0)
34
43
  git__set_errno();
35
44
 
36
45
  return len;
37
46
  }
38
47
 
39
- /**
40
- * Converts a wide string to UTF-8.
41
- *
42
- * @param dest The buffer to receive the UTF-8 string.
43
- * @param dest_size The size of the buffer, in bytes.
44
- * @param src The wide string to convert.
45
- * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure
46
- */
47
- int git__utf16_to_8(char *dest, size_t dest_size, const wchar_t *src)
48
+ int git_utf8_from_16(char *dest, size_t dest_size, const wchar_t *src)
48
49
  {
50
+ /* Length of -1 indicates NULL termination of the input string. */
51
+ return git_utf8_from_16_with_len(dest, dest_size, src, -1);
52
+ }
53
+
54
+ int git_utf8_from_16_with_len(
55
+ char *dest,
56
+ size_t _dest_size,
57
+ const wchar_t *src,
58
+ int src_len)
59
+ {
60
+ int dest_size = (int)min(_dest_size, INT_MAX);
49
61
  int len;
50
62
 
51
- /* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to
52
- * turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's
53
- * length. WideCharToMultiByte never returns int's minvalue, so underflow is not possible */
54
- if ((len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, dest, (int)dest_size, NULL, NULL) - 1) < 0)
63
+ /*
64
+ * Subtract 1 from the result to turn 0 into -1 (an error code) and
65
+ * to not count the NULL terminator as part of the string's length.
66
+ * WideCharToMultiByte never returns int's minvalue, so underflow
67
+ * is not possible.
68
+ */
69
+ len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
70
+ src, src_len, dest, dest_size, NULL, NULL) - 1;
71
+
72
+ if (len < 0)
55
73
  git__set_errno();
56
74
 
57
75
  return len;
58
76
  }
59
77
 
60
- /**
61
- * Converts a UTF-8 string to wide characters.
62
- * Memory is allocated to hold the converted string.
63
- * The caller is responsible for freeing the string with git__free.
64
- *
65
- * @param dest Receives a pointer to the wide string.
66
- * @param src The UTF-8 string to convert.
67
- * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure
68
- */
69
- int git__utf8_to_16_alloc(wchar_t **dest, const char *src)
78
+ int git_utf8_to_16_alloc(wchar_t **dest, const char *src)
79
+ {
80
+ /* Length of -1 indicates NULL termination of the input string. */
81
+ return git_utf8_to_16_alloc_with_len(dest, src, -1);
82
+ }
83
+
84
+ int git_utf8_to_16_alloc_with_len(wchar_t **dest, const char *src, int src_len)
70
85
  {
71
86
  int utf16_size;
72
87
 
73
88
  *dest = NULL;
74
89
 
75
- /* Length of -1 indicates NULL termination of the input string */
76
- utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, NULL, 0);
90
+ utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
91
+ src, src_len, NULL, 0);
77
92
 
78
93
  if (!utf16_size) {
79
94
  git__set_errno();
80
95
  return -1;
81
96
  }
82
97
 
83
- if (!(*dest = git__mallocarray(utf16_size, sizeof(wchar_t)))) {
84
- errno = ENOMEM;
85
- return -1;
86
- }
98
+ *dest = git__mallocarray(utf16_size, sizeof(wchar_t));
99
+ GIT_ERROR_CHECK_ALLOC(*dest);
87
100
 
88
- utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, *dest, utf16_size);
89
-
90
- if (!utf16_size) {
91
- git__set_errno();
101
+ utf16_size = git_utf8_to_16_with_len(*dest, (size_t)utf16_size,
102
+ src, src_len);
92
103
 
104
+ if (utf16_size < 0) {
93
105
  git__free(*dest);
94
106
  *dest = NULL;
95
107
  }
96
108
 
97
- /* Subtract 1 from the result to turn 0 into -1 (an error code) and to not count the NULL
98
- * terminator as part of the string's length. MultiByteToWideChar never returns int's minvalue,
99
- * so underflow is not possible */
100
- return utf16_size - 1;
109
+ return utf16_size;
101
110
  }
102
111
 
103
- /**
104
- * Converts a wide string to UTF-8.
105
- * Memory is allocated to hold the converted string.
106
- * The caller is responsible for freeing the string with git__free.
107
- *
108
- * @param dest Receives a pointer to the UTF-8 string.
109
- * @param src The wide string to convert.
110
- * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure
111
- */
112
- int git__utf16_to_8_alloc(char **dest, const wchar_t *src)
112
+ int git_utf8_from_16_alloc(char **dest, const wchar_t *src)
113
+ {
114
+ /* Length of -1 indicates NULL termination of the input string. */
115
+ return git_utf8_from_16_alloc_with_len(dest, src, -1);
116
+ }
117
+
118
+ int git_utf8_from_16_alloc_with_len(char **dest, const wchar_t *src, int src_len)
113
119
  {
114
120
  int utf8_size;
115
121
 
116
122
  *dest = NULL;
117
123
 
118
- /* Length of -1 indicates NULL termination of the input string */
119
- utf8_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, NULL, 0, NULL, NULL);
124
+ utf8_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
125
+ src, src_len, NULL, 0, NULL, NULL);
120
126
 
121
127
  if (!utf8_size) {
122
128
  git__set_errno();
@@ -124,23 +130,15 @@ int git__utf16_to_8_alloc(char **dest, const wchar_t *src)
124
130
  }
125
131
 
126
132
  *dest = git__malloc(utf8_size);
133
+ GIT_ERROR_CHECK_ALLOC(*dest);
127
134
 
128
- if (!*dest) {
129
- errno = ENOMEM;
130
- return -1;
131
- }
132
-
133
- utf8_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, *dest, utf8_size, NULL, NULL);
134
-
135
- if (!utf8_size) {
136
- git__set_errno();
135
+ utf8_size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS,
136
+ src, src_len, *dest, utf8_size, NULL, NULL);
137
137
 
138
+ if (utf8_size < 0) {
138
139
  git__free(*dest);
139
140
  *dest = NULL;
140
141
  }
141
142
 
142
- /* Subtract 1 from the result to turn 0 into -1 (an error code) and to not count the NULL
143
- * terminator as part of the string's length. MultiByteToWideChar never returns int's minvalue,
144
- * so underflow is not possible */
145
- return utf8_size - 1;
143
+ return utf8_size;
146
144
  }