rugged 0.25.0b5 → 0.25.0b6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged_patch.c +77 -17
  3. data/lib/rugged/version.rb +1 -1
  4. data/vendor/libgit2/CMakeLists.txt +8 -6
  5. data/vendor/libgit2/include/git2/checkout.h +7 -0
  6. data/vendor/libgit2/include/git2/common.h +1 -0
  7. data/vendor/libgit2/include/git2/diff.h +54 -7
  8. data/vendor/libgit2/include/git2/errors.h +2 -1
  9. data/vendor/libgit2/include/git2/index.h +25 -0
  10. data/vendor/libgit2/include/git2/pack.h +4 -4
  11. data/vendor/libgit2/include/git2/repository.h +20 -1
  12. data/vendor/libgit2/include/git2/submodule.h +11 -3
  13. data/vendor/libgit2/include/git2/sys/odb_backend.h +11 -0
  14. data/vendor/libgit2/src/apply.c +369 -0
  15. data/vendor/libgit2/src/apply.h +21 -0
  16. data/vendor/libgit2/src/array.h +0 -1
  17. data/vendor/libgit2/src/blame_git.c +18 -8
  18. data/vendor/libgit2/src/buffer.c +252 -20
  19. data/vendor/libgit2/src/buffer.h +8 -0
  20. data/vendor/libgit2/src/checkout.c +7 -1
  21. data/vendor/libgit2/src/clone.c +0 -8
  22. data/vendor/libgit2/src/common.h +1 -1
  23. data/vendor/libgit2/src/crlf.c +1 -0
  24. data/vendor/libgit2/src/delta.c +238 -62
  25. data/vendor/libgit2/src/delta.h +79 -58
  26. data/vendor/libgit2/src/diff.c +32 -1547
  27. data/vendor/libgit2/src/diff.h +12 -122
  28. data/vendor/libgit2/src/diff_driver.c +1 -2
  29. data/vendor/libgit2/src/diff_file.c +3 -0
  30. data/vendor/libgit2/src/diff_generate.c +1611 -0
  31. data/vendor/libgit2/src/diff_generate.h +123 -0
  32. data/vendor/libgit2/src/diff_parse.c +105 -0
  33. data/vendor/libgit2/src/diff_print.c +259 -142
  34. data/vendor/libgit2/src/diff_stats.c +3 -2
  35. data/vendor/libgit2/src/diff_tform.c +1 -0
  36. data/vendor/libgit2/src/diff_tform.h +22 -0
  37. data/vendor/libgit2/src/diff_xdiff.c +9 -9
  38. data/vendor/libgit2/src/diff_xdiff.h +5 -5
  39. data/vendor/libgit2/src/fileops.c +13 -0
  40. data/vendor/libgit2/src/fileops.h +6 -0
  41. data/vendor/libgit2/src/global.c +9 -8
  42. data/vendor/libgit2/src/ignore.c +45 -16
  43. data/vendor/libgit2/src/index.c +161 -47
  44. data/vendor/libgit2/src/index.h +2 -0
  45. data/vendor/libgit2/src/merge.c +2 -0
  46. data/vendor/libgit2/src/mwindow.c +8 -19
  47. data/vendor/libgit2/src/mwindow.h +1 -2
  48. data/vendor/libgit2/src/odb.c +46 -10
  49. data/vendor/libgit2/src/odb_loose.c +19 -1
  50. data/vendor/libgit2/src/odb_pack.c +27 -4
  51. data/vendor/libgit2/src/pack-objects.c +106 -77
  52. data/vendor/libgit2/src/pack-objects.h +13 -12
  53. data/vendor/libgit2/src/pack.c +4 -3
  54. data/vendor/libgit2/src/pack.h +2 -0
  55. data/vendor/libgit2/src/patch.c +207 -0
  56. data/vendor/libgit2/src/patch.h +66 -0
  57. data/vendor/libgit2/src/{diff_patch.c → patch_generate.c} +171 -359
  58. data/vendor/libgit2/src/patch_generate.h +66 -0
  59. data/vendor/libgit2/src/patch_parse.c +1121 -0
  60. data/vendor/libgit2/src/patch_parse.h +54 -0
  61. data/vendor/libgit2/src/path.c +19 -0
  62. data/vendor/libgit2/src/path.h +6 -0
  63. data/vendor/libgit2/src/pool.h +5 -0
  64. data/vendor/libgit2/src/remote.c +15 -80
  65. data/vendor/libgit2/src/repository.c +227 -39
  66. data/vendor/libgit2/src/settings.c +11 -5
  67. data/vendor/libgit2/src/stash.c +1 -0
  68. data/vendor/libgit2/src/status.c +1 -0
  69. data/vendor/libgit2/src/stransport_stream.c +14 -9
  70. data/vendor/libgit2/src/submodule.c +16 -4
  71. data/vendor/libgit2/src/sysdir.c +41 -47
  72. data/vendor/libgit2/src/sysdir.h +0 -5
  73. data/vendor/libgit2/src/thread-utils.h +5 -51
  74. data/vendor/libgit2/src/transport.c +3 -5
  75. data/vendor/libgit2/src/transports/http.c +2 -3
  76. data/vendor/libgit2/src/transports/smart_pkt.c +1 -0
  77. data/vendor/libgit2/src/transports/smart_protocol.c +11 -0
  78. data/vendor/libgit2/src/transports/winhttp.c +16 -2
  79. data/vendor/libgit2/src/unix/pthread.h +54 -0
  80. data/vendor/libgit2/src/util.c +23 -5
  81. data/vendor/libgit2/src/util.h +10 -0
  82. data/vendor/libgit2/src/varint.c +44 -0
  83. data/vendor/libgit2/src/varint.h +15 -0
  84. data/vendor/libgit2/src/vector.c +42 -0
  85. data/vendor/libgit2/src/vector.h +3 -0
  86. data/vendor/libgit2/src/win32/precompiled.h +1 -1
  87. data/vendor/libgit2/src/win32/{pthread.c → thread.c} +50 -80
  88. data/vendor/libgit2/src/win32/thread.h +62 -0
  89. data/vendor/libgit2/src/zstream.c +36 -7
  90. data/vendor/libgit2/src/zstream.h +8 -1
  91. metadata +20 -9
  92. data/vendor/libgit2/src/delta-apply.c +0 -166
  93. data/vendor/libgit2/src/delta-apply.h +0 -62
  94. data/vendor/libgit2/src/diff_patch.h +0 -83
  95. data/vendor/libgit2/src/win32/pthread.h +0 -92
@@ -433,6 +433,7 @@ int git_pkt_parse_line(
433
433
  * line?
434
434
  */
435
435
  if (len == PKT_LEN_SIZE) {
436
+ *head = NULL;
436
437
  *out = line;
437
438
  return 0;
438
439
  }
@@ -759,6 +759,14 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt,
759
759
  line_len -= (line_end - line);
760
760
  line = line_end;
761
761
 
762
+ /* When a valid packet with no content has been
763
+ * read, git_pkt_parse_line does not report an
764
+ * error, but the pkt pointer has not been set.
765
+ * Handle this by skipping over empty packets.
766
+ */
767
+ if (pkt == NULL)
768
+ continue;
769
+
762
770
  error = add_push_report_pkt(push, pkt);
763
771
 
764
772
  git_pkt_free(pkt);
@@ -813,6 +821,9 @@ static int parse_report(transport_smart *transport, git_push *push)
813
821
 
814
822
  error = 0;
815
823
 
824
+ if (pkt == NULL)
825
+ continue;
826
+
816
827
  switch (pkt->type) {
817
828
  case GIT_PKT_DATA:
818
829
  /* This is a sideband packet which contains other packets */
@@ -400,11 +400,17 @@ static int winhttp_stream_connect(winhttp_stream *s)
400
400
  return -1;
401
401
  }
402
402
 
403
+ gitno_connection_data_free_ptrs(&t->proxy_connection_data);
404
+
403
405
  if ((error = gitno_extract_url_parts(&t->proxy_connection_data.host, &t->proxy_connection_data.port, NULL,
404
406
  &t->proxy_connection_data.user, &t->proxy_connection_data.pass, proxy_url, NULL)) < 0)
405
407
  goto on_error;
406
408
 
407
409
  if (t->proxy_connection_data.user && t->proxy_connection_data.pass) {
410
+ if (t->proxy_cred) {
411
+ t->proxy_cred->free(t->proxy_cred);
412
+ }
413
+
408
414
  if ((error = git_cred_userpass_plaintext_new(&t->proxy_cred, t->proxy_connection_data.user, t->proxy_connection_data.pass)) < 0)
409
415
  goto on_error;
410
416
  }
@@ -425,10 +431,11 @@ static int winhttp_stream_connect(winhttp_stream *s)
425
431
  }
426
432
 
427
433
  /* Convert URL to wide characters */
428
- if ((error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr)) < 0)
434
+ error = git__utf8_to_16_alloc(&proxy_wide, processed_url.ptr);
435
+ git_buf_free(&processed_url);
436
+ if (error < 0)
429
437
  goto on_error;
430
438
 
431
-
432
439
  proxy_info.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
433
440
  proxy_info.lpszProxy = proxy_wide;
434
441
  proxy_info.lpszProxyBypass = NULL;
@@ -1481,12 +1488,19 @@ static int winhttp_close(git_smart_subtransport *subtransport)
1481
1488
 
1482
1489
  gitno_connection_data_free_ptrs(&t->connection_data);
1483
1490
  memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1491
+ gitno_connection_data_free_ptrs(&t->proxy_connection_data);
1492
+ memset(&t->proxy_connection_data, 0x0, sizeof(gitno_connection_data));
1484
1493
 
1485
1494
  if (t->cred) {
1486
1495
  t->cred->free(t->cred);
1487
1496
  t->cred = NULL;
1488
1497
  }
1489
1498
 
1499
+ if (t->proxy_cred) {
1500
+ t->proxy_cred->free(t->proxy_cred);
1501
+ t->proxy_cred = NULL;
1502
+ }
1503
+
1490
1504
  if (t->url_cred) {
1491
1505
  t->url_cred->free(t->url_cred);
1492
1506
  t->url_cred = NULL;
@@ -0,0 +1,54 @@
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
+
8
+ #ifndef INCLUDE_unix_pthread_h__
9
+ #define INCLUDE_unix_pthread_h__
10
+
11
+ typedef struct {
12
+ pthread_t thread;
13
+ } git_thread;
14
+
15
+ #define git_threads_init() (void)0
16
+ #define git_thread_create(git_thread_ptr, start_routine, arg) \
17
+ pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg)
18
+ #define git_thread_join(git_thread_ptr, status) \
19
+ pthread_join((git_thread_ptr)->thread, status)
20
+
21
+ /* Git Mutex */
22
+ #define git_mutex pthread_mutex_t
23
+ #define git_mutex_init(a) pthread_mutex_init(a, NULL)
24
+ #define git_mutex_lock(a) pthread_mutex_lock(a)
25
+ #define git_mutex_unlock(a) pthread_mutex_unlock(a)
26
+ #define git_mutex_free(a) pthread_mutex_destroy(a)
27
+
28
+ /* Git condition vars */
29
+ #define git_cond pthread_cond_t
30
+ #define git_cond_init(c) pthread_cond_init(c, NULL)
31
+ #define git_cond_free(c) pthread_cond_destroy(c)
32
+ #define git_cond_wait(c, l) pthread_cond_wait(c, l)
33
+ #define git_cond_signal(c) pthread_cond_signal(c)
34
+ #define git_cond_broadcast(c) pthread_cond_broadcast(c)
35
+
36
+ /* Pthread (-ish) rwlock
37
+ *
38
+ * This differs from normal pthreads rwlocks in two ways:
39
+ * 1. Separate APIs for releasing read locks and write locks (as
40
+ * opposed to the pure POSIX API which only has one unlock fn)
41
+ * 2. You should not use recursive read locks (i.e. grabbing a read
42
+ * lock in a thread that already holds a read lock) because the
43
+ * Windows implementation doesn't support it
44
+ */
45
+ #define git_rwlock pthread_rwlock_t
46
+ #define git_rwlock_init(a) pthread_rwlock_init(a, NULL)
47
+ #define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a)
48
+ #define git_rwlock_rdunlock(a) pthread_rwlock_unlock(a)
49
+ #define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a)
50
+ #define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a)
51
+ #define git_rwlock_free(a) pthread_rwlock_destroy(a)
52
+ #define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER
53
+
54
+ #endif /* INCLUDE_unix_pthread_h__ */
@@ -65,6 +65,12 @@ int git_strarray_copy(git_strarray *tgt, const git_strarray *src)
65
65
  }
66
66
 
67
67
  int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int base)
68
+ {
69
+
70
+ return git__strntol64(result, nptr, (size_t)-1, endptr, base);
71
+ }
72
+
73
+ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base)
68
74
  {
69
75
  const char *p;
70
76
  int64_t n, nn;
@@ -111,7 +117,7 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba
111
117
  /*
112
118
  * Non-empty sequence of digits
113
119
  */
114
- for (;; p++,ndig++) {
120
+ for (; nptr_len > 0; p++,ndig++,nptr_len--) {
115
121
  c = *p;
116
122
  v = base;
117
123
  if ('0'<=c && c<='9')
@@ -122,8 +128,8 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba
122
128
  v = c - 'A' + 10;
123
129
  if (v >= base)
124
130
  break;
125
- nn = n*base + v;
126
- if (nn < n)
131
+ nn = n * base + (neg ? -v : v);
132
+ if ((!neg && nn < n) || (neg && nn > n))
127
133
  ovfl = 1;
128
134
  n = nn;
129
135
  }
@@ -142,17 +148,23 @@ Return:
142
148
  return -1;
143
149
  }
144
150
 
145
- *result = neg ? -n : n;
151
+ *result = n;
146
152
  return 0;
147
153
  }
148
154
 
149
155
  int git__strtol32(int32_t *result, const char *nptr, const char **endptr, int base)
156
+ {
157
+
158
+ return git__strntol32(result, nptr, (size_t)-1, endptr, base);
159
+ }
160
+
161
+ int git__strntol32(int32_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base)
150
162
  {
151
163
  int error;
152
164
  int32_t tmp_int;
153
165
  int64_t tmp_long;
154
166
 
155
- if ((error = git__strtol64(&tmp_long, nptr, endptr, base)) < 0)
167
+ if ((error = git__strntol64(&tmp_long, nptr, nptr_len, endptr, base)) < 0)
156
168
  return error;
157
169
 
158
170
  tmp_int = tmp_long & 0xFFFFFFFF;
@@ -321,6 +333,12 @@ char *git__strsep(char **end, const char *sep)
321
333
  return NULL;
322
334
  }
323
335
 
336
+ size_t git__linenlen(const char *buffer, size_t buffer_len)
337
+ {
338
+ char *nl = memchr(buffer, '\n', buffer_len);
339
+ return nl ? (size_t)(nl - buffer) + 1 : buffer_len;
340
+ }
341
+
324
342
  void git__hexdump(const char *buffer, size_t len)
325
343
  {
326
344
  static const size_t LINE_WIDTH = 16;
@@ -263,7 +263,10 @@ GIT_INLINE(int) git__signum(int val)
263
263
  }
264
264
 
265
265
  extern int git__strtol32(int32_t *n, const char *buff, const char **end_buf, int base);
266
+ extern int git__strntol32(int32_t *n, const char *buff, size_t buff_len, const char **end_buf, int base);
266
267
  extern int git__strtol64(int64_t *n, const char *buff, const char **end_buf, int base);
268
+ extern int git__strntol64(int64_t *n, const char *buff, size_t buff_len, const char **end_buf, int base);
269
+
267
270
 
268
271
  extern void git__hexdump(const char *buffer, size_t n);
269
272
  extern uint32_t git__hash(const void *key, int len, uint32_t seed);
@@ -290,6 +293,8 @@ GIT_INLINE(int) git__tolower(int c)
290
293
  # define git__tolower(a) tolower(a)
291
294
  #endif
292
295
 
296
+ extern size_t git__linenlen(const char *buffer, size_t buffer_len);
297
+
293
298
  GIT_INLINE(const char *) git__next_line(const char *s)
294
299
  {
295
300
  while (*s && *s != '\n') s++;
@@ -466,6 +471,11 @@ GIT_INLINE(bool) git__iswildcard(int c)
466
471
  return (c == '*' || c == '?' || c == '[');
467
472
  }
468
473
 
474
+ GIT_INLINE(bool) git__isxdigit(int c)
475
+ {
476
+ return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
477
+ }
478
+
469
479
  /*
470
480
  * Parse a string value as a boolean, just like Core Git does.
471
481
  *
@@ -0,0 +1,44 @@
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
+
8
+ #include "common.h"
9
+ #include "varint.h"
10
+
11
+ uintmax_t git_decode_varint(const unsigned char *bufp, size_t *varint_len)
12
+ {
13
+ const unsigned char *buf = bufp;
14
+ unsigned char c = *buf++;
15
+ uintmax_t val = c & 127;
16
+ while (c & 128) {
17
+ val += 1;
18
+ if (!val || MSB(val, 7)) {
19
+ /* This is not a valid varint_len, so it signals
20
+ the error */
21
+ *varint_len = 0;
22
+ return 0; /* overflow */
23
+ }
24
+ c = *buf++;
25
+ val = (val << 7) + (c & 127);
26
+ }
27
+ *varint_len = buf - bufp;
28
+ return val;
29
+ }
30
+
31
+ int git_encode_varint(unsigned char *buf, size_t bufsize, uintmax_t value)
32
+ {
33
+ unsigned char varint[16];
34
+ unsigned pos = sizeof(varint) - 1;
35
+ varint[pos] = value & 127;
36
+ while (value >>= 7)
37
+ varint[--pos] = 128 | (--value & 127);
38
+ if (buf) {
39
+ if (bufsize < pos)
40
+ return -1;
41
+ memcpy(buf, varint + pos, sizeof(varint) - pos);
42
+ }
43
+ return sizeof(varint) - pos;
44
+ }
@@ -0,0 +1,15 @@
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_varint_h__
8
+ #define INCLUDE_varint_h__
9
+
10
+ #include <stdint.h>
11
+
12
+ extern int git_encode_varint(unsigned char *, size_t, uintmax_t);
13
+ extern uintmax_t git_decode_varint(const unsigned char *, size_t *);
14
+
15
+ #endif
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include "common.h"
9
9
  #include "vector.h"
10
+ #include "integer.h"
10
11
 
11
12
  /* In elements, not bytes */
12
13
  #define MIN_ALLOCSIZE 8
@@ -330,6 +331,47 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
330
331
  return 0;
331
332
  }
332
333
 
334
+ int git_vector_insert_null(git_vector *v, size_t idx, size_t insert_len)
335
+ {
336
+ size_t new_length;
337
+
338
+ assert(insert_len > 0 && idx <= v->length);
339
+
340
+ GITERR_CHECK_ALLOC_ADD(&new_length, v->length, insert_len);
341
+
342
+ if (new_length > v->_alloc_size && resize_vector(v, new_length) < 0)
343
+ return -1;
344
+
345
+ memmove(&v->contents[idx + insert_len], &v->contents[idx],
346
+ sizeof(void *) * (v->length - idx));
347
+ memset(&v->contents[idx], 0, sizeof(void *) * insert_len);
348
+
349
+ v->length = new_length;
350
+ return 0;
351
+ }
352
+
353
+ int git_vector_remove_range(git_vector *v, size_t idx, size_t remove_len)
354
+ {
355
+ size_t new_length = v->length - remove_len;
356
+ size_t end_idx = 0;
357
+
358
+ assert(remove_len > 0);
359
+
360
+ if (git__add_sizet_overflow(&end_idx, idx, remove_len))
361
+ assert(0);
362
+
363
+ assert(end_idx <= v->length);
364
+
365
+ if (end_idx < v->length)
366
+ memmove(&v->contents[idx], &v->contents[end_idx],
367
+ sizeof(void *) * (v->length - end_idx));
368
+
369
+ memset(&v->contents[new_length], 0, sizeof(void *) * remove_len);
370
+
371
+ v->length = new_length;
372
+ return 0;
373
+ }
374
+
333
375
  int git_vector_set(void **old, git_vector *v, size_t position, void *value)
334
376
  {
335
377
  if (position + 1 > v->length) {
@@ -93,6 +93,9 @@ void git_vector_remove_matching(
93
93
  void *payload);
94
94
 
95
95
  int git_vector_resize_to(git_vector *v, size_t new_length);
96
+ int git_vector_insert_null(git_vector *v, size_t idx, size_t insert_len);
97
+ int git_vector_remove_range(git_vector *v, size_t idx, size_t remove_len);
98
+
96
99
  int git_vector_set(void **old, git_vector *v, size_t position, void *value);
97
100
 
98
101
  /** Check if vector is sorted */
@@ -16,7 +16,7 @@
16
16
  #include <io.h>
17
17
  #include <direct.h>
18
18
  #ifdef GIT_THREADS
19
- #include "win32/pthread.h"
19
+ #include "win32/thread.h"
20
20
  #endif
21
21
 
22
22
  #include "git2.h"
@@ -5,18 +5,26 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
 
8
- #include "pthread.h"
8
+ #include "thread.h"
9
9
  #include "../global.h"
10
10
 
11
11
  #define CLEAN_THREAD_EXIT 0x6F012842
12
12
 
13
+ typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
14
+
15
+ static win32_srwlock_fn win32_srwlock_initialize;
16
+ static win32_srwlock_fn win32_srwlock_acquire_shared;
17
+ static win32_srwlock_fn win32_srwlock_release_shared;
18
+ static win32_srwlock_fn win32_srwlock_acquire_exclusive;
19
+ static win32_srwlock_fn win32_srwlock_release_exclusive;
20
+
13
21
  /* The thread procedure stub used to invoke the caller's procedure
14
22
  * and capture the return value for later collection. Windows will
15
23
  * only hold a DWORD, but we need to be able to store an entire
16
24
  * void pointer. This requires the indirection. */
17
25
  static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
18
26
  {
19
- git_win32_thread *thread = lpParameter;
27
+ git_thread *thread = lpParameter;
20
28
 
21
29
  thread->result = thread->proc(thread->param);
22
30
 
@@ -25,14 +33,31 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
25
33
  return CLEAN_THREAD_EXIT;
26
34
  }
27
35
 
28
- int git_win32__thread_create(
29
- git_win32_thread *GIT_RESTRICT thread,
30
- const pthread_attr_t *GIT_RESTRICT attr,
36
+ int git_threads_init(void)
37
+ {
38
+ HMODULE hModule = GetModuleHandleW(L"kernel32");
39
+
40
+ if (hModule) {
41
+ win32_srwlock_initialize = (win32_srwlock_fn)
42
+ GetProcAddress(hModule, "InitializeSRWLock");
43
+ win32_srwlock_acquire_shared = (win32_srwlock_fn)
44
+ GetProcAddress(hModule, "AcquireSRWLockShared");
45
+ win32_srwlock_release_shared = (win32_srwlock_fn)
46
+ GetProcAddress(hModule, "ReleaseSRWLockShared");
47
+ win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
48
+ GetProcAddress(hModule, "AcquireSRWLockExclusive");
49
+ win32_srwlock_release_exclusive = (win32_srwlock_fn)
50
+ GetProcAddress(hModule, "ReleaseSRWLockExclusive");
51
+ }
52
+
53
+ return 0;
54
+ }
55
+
56
+ int git_thread_create(
57
+ git_thread *GIT_RESTRICT thread,
31
58
  void *(*start_routine)(void*),
32
59
  void *GIT_RESTRICT arg)
33
60
  {
34
- GIT_UNUSED(attr);
35
-
36
61
  thread->result = NULL;
37
62
  thread->param = arg;
38
63
  thread->proc = start_routine;
@@ -42,8 +67,8 @@ int git_win32__thread_create(
42
67
  return thread->thread ? 0 : -1;
43
68
  }
44
69
 
45
- int git_win32__thread_join(
46
- git_win32_thread *thread,
70
+ int git_thread_join(
71
+ git_thread *thread,
47
72
  void **value_ptr)
48
73
  {
49
74
  DWORD exit;
@@ -70,39 +95,32 @@ int git_win32__thread_join(
70
95
  return 0;
71
96
  }
72
97
 
73
- int pthread_mutex_init(
74
- pthread_mutex_t *GIT_RESTRICT mutex,
75
- const pthread_mutexattr_t *GIT_RESTRICT mutexattr)
98
+ int git_mutex_init(git_mutex *GIT_RESTRICT mutex)
76
99
  {
77
- GIT_UNUSED(mutexattr);
78
100
  InitializeCriticalSection(mutex);
79
101
  return 0;
80
102
  }
81
103
 
82
- int pthread_mutex_destroy(pthread_mutex_t *mutex)
104
+ int git_mutex_free(git_mutex *mutex)
83
105
  {
84
106
  DeleteCriticalSection(mutex);
85
107
  return 0;
86
108
  }
87
109
 
88
- int pthread_mutex_lock(pthread_mutex_t *mutex)
110
+ int git_mutex_lock(git_mutex *mutex)
89
111
  {
90
112
  EnterCriticalSection(mutex);
91
113
  return 0;
92
114
  }
93
115
 
94
- int pthread_mutex_unlock(pthread_mutex_t *mutex)
116
+ int git_mutex_unlock(git_mutex *mutex)
95
117
  {
96
118
  LeaveCriticalSection(mutex);
97
119
  return 0;
98
120
  }
99
121
 
100
- int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
122
+ int git_cond_init(git_cond *cond)
101
123
  {
102
- /* We don't support non-default attributes. */
103
- if (attr)
104
- return EINVAL;
105
-
106
124
  /* This is an auto-reset event. */
107
125
  *cond = CreateEventW(NULL, FALSE, FALSE, NULL);
108
126
  assert(*cond);
@@ -112,7 +130,7 @@ int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
112
130
  return *cond ? 0 : ENOMEM;
113
131
  }
114
132
 
115
- int pthread_cond_destroy(pthread_cond_t *cond)
133
+ int git_cond_free(git_cond *cond)
116
134
  {
117
135
  BOOL closed;
118
136
 
@@ -127,7 +145,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
127
145
  return 0;
128
146
  }
129
147
 
130
- int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
148
+ int git_cond_wait(git_cond *cond, git_mutex *mutex)
131
149
  {
132
150
  int error;
133
151
  DWORD wait_result;
@@ -136,7 +154,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
136
154
  return EINVAL;
137
155
 
138
156
  /* The caller must be holding the mutex. */
139
- error = pthread_mutex_unlock(mutex);
157
+ error = git_mutex_unlock(mutex);
140
158
 
141
159
  if (error)
142
160
  return error;
@@ -145,10 +163,10 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
145
163
  assert(WAIT_OBJECT_0 == wait_result);
146
164
  GIT_UNUSED(wait_result);
147
165
 
148
- return pthread_mutex_lock(mutex);
166
+ return git_mutex_lock(mutex);
149
167
  }
150
168
 
151
- int pthread_cond_signal(pthread_cond_t *cond)
169
+ int git_cond_signal(git_cond *cond)
152
170
  {
153
171
  BOOL signaled;
154
172
 
@@ -162,36 +180,8 @@ int pthread_cond_signal(pthread_cond_t *cond)
162
180
  return 0;
163
181
  }
164
182
 
165
- /* pthread_cond_broadcast is not implemented because doing so with just
166
- * Win32 events is quite complicated, and no caller in libgit2 uses it
167
- * yet.
168
- */
169
- int pthread_num_processors_np(void)
170
- {
171
- DWORD_PTR p, s;
172
- int n = 0;
173
-
174
- if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s))
175
- for (; p; p >>= 1)
176
- n += p&1;
177
-
178
- return n ? n : 1;
179
- }
180
-
181
- typedef void (WINAPI *win32_srwlock_fn)(GIT_SRWLOCK *);
182
-
183
- static win32_srwlock_fn win32_srwlock_initialize;
184
- static win32_srwlock_fn win32_srwlock_acquire_shared;
185
- static win32_srwlock_fn win32_srwlock_release_shared;
186
- static win32_srwlock_fn win32_srwlock_acquire_exclusive;
187
- static win32_srwlock_fn win32_srwlock_release_exclusive;
188
-
189
- int pthread_rwlock_init(
190
- pthread_rwlock_t *GIT_RESTRICT lock,
191
- const pthread_rwlockattr_t *GIT_RESTRICT attr)
183
+ int git_rwlock_init(git_rwlock *GIT_RESTRICT lock)
192
184
  {
193
- GIT_UNUSED(attr);
194
-
195
185
  if (win32_srwlock_initialize)
196
186
  win32_srwlock_initialize(&lock->native.srwl);
197
187
  else
@@ -200,7 +190,7 @@ int pthread_rwlock_init(
200
190
  return 0;
201
191
  }
202
192
 
203
- int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
193
+ int git_rwlock_rdlock(git_rwlock *lock)
204
194
  {
205
195
  if (win32_srwlock_acquire_shared)
206
196
  win32_srwlock_acquire_shared(&lock->native.srwl);
@@ -210,7 +200,7 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
210
200
  return 0;
211
201
  }
212
202
 
213
- int pthread_rwlock_rdunlock(pthread_rwlock_t *lock)
203
+ int git_rwlock_rdunlock(git_rwlock *lock)
214
204
  {
215
205
  if (win32_srwlock_release_shared)
216
206
  win32_srwlock_release_shared(&lock->native.srwl);
@@ -220,7 +210,7 @@ int pthread_rwlock_rdunlock(pthread_rwlock_t *lock)
220
210
  return 0;
221
211
  }
222
212
 
223
- int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
213
+ int git_rwlock_wrlock(git_rwlock *lock)
224
214
  {
225
215
  if (win32_srwlock_acquire_exclusive)
226
216
  win32_srwlock_acquire_exclusive(&lock->native.srwl);
@@ -230,7 +220,7 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
230
220
  return 0;
231
221
  }
232
222
 
233
- int pthread_rwlock_wrunlock(pthread_rwlock_t *lock)
223
+ int git_rwlock_wrunlock(git_rwlock *lock)
234
224
  {
235
225
  if (win32_srwlock_release_exclusive)
236
226
  win32_srwlock_release_exclusive(&lock->native.srwl);
@@ -240,30 +230,10 @@ int pthread_rwlock_wrunlock(pthread_rwlock_t *lock)
240
230
  return 0;
241
231
  }
242
232
 
243
- int pthread_rwlock_destroy(pthread_rwlock_t *lock)
233
+ int git_rwlock_free(git_rwlock *lock)
244
234
  {
245
235
  if (!win32_srwlock_initialize)
246
236
  DeleteCriticalSection(&lock->native.csec);
247
237
  git__memzero(lock, sizeof(*lock));
248
238
  return 0;
249
239
  }
250
-
251
- int win32_pthread_initialize(void)
252
- {
253
- HMODULE hModule = GetModuleHandleW(L"kernel32");
254
-
255
- if (hModule) {
256
- win32_srwlock_initialize = (win32_srwlock_fn)
257
- GetProcAddress(hModule, "InitializeSRWLock");
258
- win32_srwlock_acquire_shared = (win32_srwlock_fn)
259
- GetProcAddress(hModule, "AcquireSRWLockShared");
260
- win32_srwlock_release_shared = (win32_srwlock_fn)
261
- GetProcAddress(hModule, "ReleaseSRWLockShared");
262
- win32_srwlock_acquire_exclusive = (win32_srwlock_fn)
263
- GetProcAddress(hModule, "AcquireSRWLockExclusive");
264
- win32_srwlock_release_exclusive = (win32_srwlock_fn)
265
- GetProcAddress(hModule, "ReleaseSRWLockExclusive");
266
- }
267
-
268
- return 0;
269
- }