rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -191,9 +191,9 @@ PATTERNS("php",
191
191
  "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
192
192
 
193
193
  PATTERNS("javascript",
194
- "^[ \t]*(function[ \t][a-zA-Z_][^\\{]*)\n"
195
- "^[ \t]*(var[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*function[ \t\\(][^\\{]*)\n"
196
- "^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*[ \t]*:[ \t]*function[ \t\\(][^\\{]*)",
194
+ "([a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z0-9_$]+)*[ \t]*=[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n"
195
+ "([a-zA-Z_$][a-zA-Z0-9_$]*[ \t]*:[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n"
196
+ "[^a-zA-Z0-9_\\$](function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)",
197
197
  /* -- */
198
198
  "[a-zA-Z_][a-zA-Z0-9_]*"
199
199
  "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
@@ -250,21 +250,6 @@ int git__prefixcmp_icase(const char *str, const char *prefix)
250
250
  return strncasecmp(str, prefix, strlen(prefix));
251
251
  }
252
252
 
253
- int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix)
254
- {
255
- int s, p;
256
-
257
- while(str_n--) {
258
- s = (unsigned char)tolower(*str++);
259
- p = (unsigned char)tolower(*prefix++);
260
-
261
- if (s != p)
262
- return s - p;
263
- }
264
-
265
- return (0 - *prefix);
266
- }
267
-
268
253
  int git__suffixcmp(const char *str, const char *suffix)
269
254
  {
270
255
  size_t a = strlen(str);
@@ -628,7 +613,8 @@ void git__qsort_r(
628
613
  defined(__OpenBSD__) || defined(__NetBSD__) || \
629
614
  defined(__gnu_hurd__) || defined(__ANDROID_API__) || \
630
615
  defined(__sun) || defined(__CYGWIN__) || \
631
- (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8)
616
+ (__GLIBC__ == 2 && __GLIBC_MINOR__ < 8) || \
617
+ (defined(_MSC_VER) && _MSC_VER < 1500)
632
618
  git__insertsort_r(els, nel, elsize, NULL, cmp, payload);
633
619
  #elif defined(GIT_WIN32)
634
620
  git__qsort_r_glue glue = { cmp, payload };
@@ -663,79 +649,3 @@ void git__insertsort_r(
663
649
  if (freeswap)
664
650
  git__free(swapel);
665
651
  }
666
-
667
- static const int8_t utf8proc_utf8class[256] = {
668
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
669
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
670
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
671
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
672
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
673
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
674
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
675
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
676
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
677
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
678
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
679
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
680
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
681
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
682
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
683
- 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0
684
- };
685
-
686
- int git__utf8_charlen(const uint8_t *str, int str_len)
687
- {
688
- int length, i;
689
-
690
- length = utf8proc_utf8class[str[0]];
691
- if (!length)
692
- return -1;
693
-
694
- if (str_len >= 0 && length > str_len)
695
- return -str_len;
696
-
697
- for (i = 1; i < length; i++) {
698
- if ((str[i] & 0xC0) != 0x80)
699
- return -i;
700
- }
701
-
702
- return length;
703
- }
704
-
705
- int git__utf8_iterate(const uint8_t *str, int str_len, int32_t *dst)
706
- {
707
- int length;
708
- int32_t uc = -1;
709
-
710
- *dst = -1;
711
- length = git__utf8_charlen(str, str_len);
712
- if (length < 0)
713
- return -1;
714
-
715
- switch (length) {
716
- case 1:
717
- uc = str[0];
718
- break;
719
- case 2:
720
- uc = ((str[0] & 0x1F) << 6) + (str[1] & 0x3F);
721
- if (uc < 0x80) uc = -1;
722
- break;
723
- case 3:
724
- uc = ((str[0] & 0x0F) << 12) + ((str[1] & 0x3F) << 6)
725
- + (str[2] & 0x3F);
726
- if (uc < 0x800 || (uc >= 0xD800 && uc < 0xE000) ||
727
- (uc >= 0xFDD0 && uc < 0xFDF0)) uc = -1;
728
- break;
729
- case 4:
730
- uc = ((str[0] & 0x07) << 18) + ((str[1] & 0x3F) << 12)
731
- + ((str[2] & 0x3F) << 6) + (str[3] & 0x3F);
732
- if (uc < 0x10000 || uc >= 0x110000) uc = -1;
733
- break;
734
- }
735
-
736
- if (uc < 0 || ((uc & 0xFFFF) >= 0xFFFE))
737
- return -1;
738
-
739
- *dst = uc;
740
- return length;
741
- }
@@ -106,7 +106,6 @@ GIT_INLINE(void) git__free(void *ptr)
106
106
 
107
107
  extern int git__prefixcmp(const char *str, const char *prefix);
108
108
  extern int git__prefixcmp_icase(const char *str, const char *prefix);
109
- extern int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix);
110
109
  extern int git__suffixcmp(const char *str, const char *suffix);
111
110
 
112
111
  GIT_INLINE(int) git__signum(int val)
@@ -367,17 +366,6 @@ extern int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date);
367
366
  */
368
367
  extern size_t git__unescape(char *str);
369
368
 
370
- /*
371
- * Iterate through an UTF-8 string, yielding one
372
- * codepoint at a time.
373
- *
374
- * @param str current position in the string
375
- * @param str_len size left in the string; -1 if the string is NULL-terminated
376
- * @param dst pointer where to store the current codepoint
377
- * @return length in bytes of the read codepoint; -1 if the codepoint was invalid
378
- */
379
- extern int git__utf8_iterate(const uint8_t *str, int str_len, int32_t *dst);
380
-
381
369
  /*
382
370
  * Safely zero-out memory, making sure that the compiler
383
371
  * doesn't optimize away the operation.
@@ -431,7 +419,7 @@ GIT_INLINE(double) git__timer(void)
431
419
  scaling_factor = (double)info.numer / (double)info.denom;
432
420
  }
433
421
 
434
- return (double)time * scaling_factor / 1.0E-9;
422
+ return (double)time * scaling_factor / 1.0E9;
435
423
  }
436
424
 
437
425
  #else
@@ -443,13 +431,13 @@ GIT_INLINE(double) git__timer(void)
443
431
  struct timespec tp;
444
432
 
445
433
  if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
446
- return (double) tp.tv_sec + (double) tp.tv_nsec / 1E-9;
434
+ return (double) tp.tv_sec + (double) tp.tv_nsec / 1.0E9;
447
435
  } else {
448
436
  /* Fall back to using gettimeofday */
449
437
  struct timeval tv;
450
438
  struct timezone tz;
451
439
  gettimeofday(&tv, &tz);
452
- return (double)tv.tv_sec + (double)tv.tv_usec / 1E-6;
440
+ return (double)tv.tv_sec + (double)tv.tv_usec / 1.0E6;
453
441
  }
454
442
  }
455
443
 
@@ -5,7 +5,6 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
 
8
- #include "path_w32.h"
9
8
  #include "utf-conv.h"
10
9
  #include "path.h"
11
10
  #include "findfile.h"
@@ -23,9 +23,10 @@ static DWORD get_page_size(void)
23
23
  return page_size;
24
24
  }
25
25
 
26
- long git__page_size(void)
26
+ int git__page_size(size_t *page_size)
27
27
  {
28
- return (long)get_page_size();
28
+ *page_size = get_page_size();
29
+ return 0;
29
30
  }
30
31
 
31
32
  int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
@@ -9,18 +9,11 @@
9
9
 
10
10
  #if defined(__MINGW32__)
11
11
 
12
- /* use a 64-bit file offset type */
13
- # undef lseek
14
- # define lseek _lseeki64
15
- # undef stat
16
- # define stat _stati64
17
- # undef fstat
18
- # define fstat _fstati64
19
-
20
- /* stat: file mode type testing macros */
21
- # define _S_IFLNK 0120000
22
- # define S_IFLNK _S_IFLNK
23
- # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
12
+ #if _WIN32_WINNT >= 0x0601
13
+ #define stat __stat64
14
+ #else
15
+ #define stat _stati64
16
+ #endif
24
17
 
25
18
  #endif
26
19
 
@@ -9,41 +9,12 @@
9
9
 
10
10
  #if defined(_MSC_VER)
11
11
 
12
- /* access() mode parameter #defines */
13
- # define F_OK 0 /* existence check */
14
- # define W_OK 2 /* write mode check */
15
- # define R_OK 4 /* read mode check */
12
+ /* 64-bit stat information, regardless of USE_32BIT_TIME_T define */
13
+ #define stat __stat64
16
14
 
17
- # define lseek _lseeki64
18
- # define stat _stat64
19
- # define fstat _fstat64
20
-
21
- /* stat: file mode type testing macros */
22
- # define _S_IFLNK 0120000
23
- # define S_IFLNK _S_IFLNK
24
- # define S_IXUSR 00100
25
-
26
- # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
27
- # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
28
- # define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
29
- # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
30
-
31
- # define mode_t unsigned short
32
-
33
- /* case-insensitive string comparison */
34
- # define strcasecmp _stricmp
35
- # define strncasecmp _strnicmp
36
-
37
- /* MSVC doesn't define ssize_t at all */
15
+ typedef unsigned short mode_t;
38
16
  typedef SSIZE_T ssize_t;
39
17
 
40
- /* define snprintf using variadic macro support if available */
41
- #if _MSC_VER >= 1400
42
- # define snprintf(BUF, SZ, FMT, ...) _snprintf_s(BUF, SZ, _TRUNCATE, FMT, __VA_ARGS__)
43
- #else
44
- # define snprintf _snprintf
45
- #endif
46
-
47
18
  #endif
48
19
 
49
20
  #define GIT_STDLIB_CALL __cdecl
@@ -9,53 +9,38 @@
9
9
 
10
10
  #include "common.h"
11
11
  #include "../posix.h"
12
- #include "path_w32.h"
13
12
  #include "utf-conv.h"
14
13
  #include "dir.h"
15
14
 
16
- /* define some standard errnos that the runtime may be missing. for example,
17
- * mingw lacks EAFNOSUPPORT. */
15
+ typedef SOCKET GIT_SOCKET;
18
16
 
19
- #ifndef EAFNOSUPPORT
20
- # define EAFNOSUPPORT (INT_MAX-1)
21
- #endif
22
-
23
- #ifdef _MSC_VER
24
- # define p_ftruncate(fd, sz) _chsize_s(fd, sz)
25
- #else /* MinGW */
26
- # define p_ftruncate(fd, sz) _chsize(fd, sz)
27
- #endif
28
-
29
- GIT_INLINE(int) p_link(const char *old, const char *new)
30
- {
31
- GIT_UNUSED(old);
32
- GIT_UNUSED(new);
33
- errno = ENOSYS;
34
- return -1;
35
- }
36
-
37
- extern int p_mkdir(const char *path, mode_t mode);
38
- extern int p_unlink(const char *path);
17
+ #define p_lseek(f,n,w) _lseeki64(f, n, w)
18
+ #define p_fstat(f,b) _fstat64(f, b)
39
19
  extern int p_lstat(const char *file_name, struct stat *buf);
20
+ extern int p_stat(const char* path, struct stat* buf);
21
+
40
22
  extern int p_readlink(const char *path, char *buf, size_t bufsiz);
41
23
  extern int p_symlink(const char *old, const char *new);
24
+ extern int p_link(const char *old, const char *new);
25
+ extern int p_unlink(const char *path);
26
+ extern int p_mkdir(const char *path, mode_t mode);
27
+ extern int p_fsync(int fd);
42
28
  extern char *p_realpath(const char *orig_path, char *buffer);
29
+
30
+ extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
31
+ extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
32
+ extern int p_inet_pton(int af, const char* src, void* dst);
33
+
34
+ #define strcasecmp(s1, s2) _stricmp(s1, s2)
35
+ #define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c)
43
36
  extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
44
37
  extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4);
45
38
  extern int p_mkstemp(char *tmp_path);
46
- extern int p_stat(const char* path, struct stat* buf);
47
39
  extern int p_chdir(const char* path);
48
40
  extern int p_chmod(const char* path, mode_t mode);
49
41
  extern int p_rmdir(const char* path);
50
42
  extern int p_access(const char* path, mode_t mode);
51
- extern int p_fsync(int fd);
52
- extern int p_open(const char *path, int flags, ...);
53
- extern int p_creat(const char *path, mode_t mode);
54
- extern int p_getcwd(char *buffer_out, size_t size);
55
- extern int p_rename(const char *from, const char *to);
56
- extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
57
- extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
58
- extern int p_inet_pton(int af, const char* src, void* dst);
43
+ extern int p_ftruncate(int fd, long size);
59
44
 
60
45
  /* p_lstat is almost but not quite POSIX correct. Specifically, the use of
61
46
  * ENOTDIR is wrong, in that it does not mean precisely that a non-directory
@@ -65,4 +50,7 @@ extern int p_inet_pton(int af, const char* src, void* dst);
65
50
  */
66
51
  extern int p_lstat_posixly(const char *filename, struct stat *buf);
67
52
 
53
+ extern struct tm * p_localtime_r (const time_t *timer, struct tm *result);
54
+ extern struct tm * p_gmtime_r (const time_t *timer, struct tm *result);
55
+
68
56
  #endif
@@ -7,7 +7,6 @@
7
7
  #include "../posix.h"
8
8
  #include "../fileops.h"
9
9
  #include "path.h"
10
- #include "path_w32.h"
11
10
  #include "utf-conv.h"
12
11
  #include "repository.h"
13
12
  #include "reparse.h"
@@ -20,6 +19,10 @@
20
19
  # define FILE_NAME_NORMALIZED 0
21
20
  #endif
22
21
 
22
+ #ifndef IO_REPARSE_TAG_SYMLINK
23
+ #define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
24
+ #endif
25
+
23
26
  /* Options which we always provide to _wopen.
24
27
  *
25
28
  * _O_BINARY - Raw access; no translation of CR or LF characters
@@ -32,24 +35,57 @@
32
35
  /* GetFinalPathNameByHandleW signature */
33
36
  typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
34
37
 
38
+ /* Helper function which converts UTF-8 paths to UTF-16.
39
+ * On failure, errno is set. */
40
+ static int utf8_to_16_with_errno(git_win32_path dest, const char *src)
41
+ {
42
+ int len = git_win32_path_from_utf8(dest, src);
43
+
44
+ if (len < 0) {
45
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
46
+ errno = ENAMETOOLONG;
47
+ else
48
+ errno = EINVAL; /* Bad code point, presumably */
49
+ }
50
+
51
+ return len;
52
+ }
53
+
54
+ int p_ftruncate(int fd, long size)
55
+ {
56
+ #if defined(_MSC_VER) && _MSC_VER >= 1500
57
+ return _chsize_s(fd, size);
58
+ #else
59
+ return _chsize(fd, size);
60
+ #endif
61
+ }
62
+
35
63
  int p_mkdir(const char *path, mode_t mode)
36
64
  {
37
65
  git_win32_path buf;
38
66
 
39
67
  GIT_UNUSED(mode);
40
68
 
41
- if (git_win32_path_from_utf8(buf, path) < 0)
69
+ if (utf8_to_16_with_errno(buf, path) < 0)
42
70
  return -1;
43
71
 
44
72
  return _wmkdir(buf);
45
73
  }
46
74
 
75
+ int p_link(const char *old, const char *new)
76
+ {
77
+ GIT_UNUSED(old);
78
+ GIT_UNUSED(new);
79
+ errno = ENOSYS;
80
+ return -1;
81
+ }
82
+
47
83
  int p_unlink(const char *path)
48
84
  {
49
85
  git_win32_path buf;
50
86
  int error;
51
87
 
52
- if (git_win32_path_from_utf8(buf, path) < 0)
88
+ if (utf8_to_16_with_errno(buf, path) < 0)
53
89
  return -1;
54
90
 
55
91
  error = _wunlink(buf);
@@ -256,7 +292,7 @@ static int do_lstat(const char *path, struct stat *buf, bool posixly_correct)
256
292
  git_win32_path path_w;
257
293
  int len;
258
294
 
259
- if ((len = git_win32_path_from_utf8(path_w, path)) < 0)
295
+ if ((len = utf8_to_16_with_errno(path_w, path)) < 0)
260
296
  return -1;
261
297
 
262
298
  git_win32__path_trim_end(path_w, len);
@@ -287,7 +323,7 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
287
323
  * could occur in the middle of the encoding of a code point,
288
324
  * we need to buffer the result on the stack. */
289
325
 
290
- if (git_win32_path_from_utf8(path_w, path) < 0 ||
326
+ if (utf8_to_16_with_errno(path_w, path) < 0 ||
291
327
  readlink_w(target_w, path_w) < 0 ||
292
328
  (len = git_win32_path_to_utf8(target, target_w)) < 0)
293
329
  return -1;
@@ -311,7 +347,7 @@ int p_open(const char *path, int flags, ...)
311
347
  git_win32_path buf;
312
348
  mode_t mode = 0;
313
349
 
314
- if (git_win32_path_from_utf8(buf, path) < 0)
350
+ if (utf8_to_16_with_errno(buf, path) < 0)
315
351
  return -1;
316
352
 
317
353
  if (flags & O_CREAT) {
@@ -329,7 +365,7 @@ int p_creat(const char *path, mode_t mode)
329
365
  {
330
366
  git_win32_path buf;
331
367
 
332
- if (git_win32_path_from_utf8(buf, path) < 0)
368
+ if (utf8_to_16_with_errno(buf, path) < 0)
333
369
  return -1;
334
370
 
335
371
  return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS, mode);
@@ -427,7 +463,7 @@ int p_stat(const char* path, struct stat* buf)
427
463
  git_win32_path path_w;
428
464
  int len;
429
465
 
430
- if ((len = git_win32_path_from_utf8(path_w, path)) < 0)
466
+ if ((len = utf8_to_16_with_errno(path_w, path)) < 0)
431
467
  return -1;
432
468
 
433
469
  git_win32__path_trim_end(path_w, len);
@@ -447,7 +483,7 @@ int p_chdir(const char* path)
447
483
  {
448
484
  git_win32_path buf;
449
485
 
450
- if (git_win32_path_from_utf8(buf, path) < 0)
486
+ if (utf8_to_16_with_errno(buf, path) < 0)
451
487
  return -1;
452
488
 
453
489
  return _wchdir(buf);
@@ -457,7 +493,7 @@ int p_chmod(const char* path, mode_t mode)
457
493
  {
458
494
  git_win32_path buf;
459
495
 
460
- if (git_win32_path_from_utf8(buf, path) < 0)
496
+ if (utf8_to_16_with_errno(buf, path) < 0)
461
497
  return -1;
462
498
 
463
499
  return _wchmod(buf, mode);
@@ -468,7 +504,7 @@ int p_rmdir(const char* path)
468
504
  git_win32_path buf;
469
505
  int error;
470
506
 
471
- if (git_win32_path_from_utf8(buf, path) < 0)
507
+ if (utf8_to_16_with_errno(buf, path) < 0)
472
508
  return -1;
473
509
 
474
510
  error = _wrmdir(buf);
@@ -497,7 +533,7 @@ char *p_realpath(const char *orig_path, char *buffer)
497
533
  {
498
534
  git_win32_path orig_path_w, buffer_w;
499
535
 
500
- if (git_win32_path_from_utf8(orig_path_w, orig_path) < 0)
536
+ if (utf8_to_16_with_errno(orig_path_w, orig_path) < 0)
501
537
  return NULL;
502
538
 
503
539
  /* Note that if the path provided is a relative path, then the current directory
@@ -518,17 +554,20 @@ char *p_realpath(const char *orig_path, char *buffer)
518
554
  return NULL;
519
555
  }
520
556
 
521
- if (!buffer && !(buffer = git__malloc(GIT_WIN_PATH_UTF8))) {
522
- errno = ENOMEM;
523
- return NULL;
557
+ /* Convert the path to UTF-8. */
558
+ if (buffer) {
559
+ /* If the caller provided a buffer, then it is assumed to be GIT_WIN_PATH_UTF8
560
+ * characters in size. If it isn't, then we may overflow. */
561
+ if (git__utf16_to_8(buffer, GIT_WIN_PATH_UTF8, buffer_w) < 0)
562
+ return NULL;
563
+ } else {
564
+ /* If the caller did not provide a buffer, then we allocate one for the caller
565
+ * from the heap. */
566
+ if (git__utf16_to_8_alloc(&buffer, buffer_w) < 0)
567
+ return NULL;
524
568
  }
525
569
 
526
- /* Convert the path to UTF-8. If the caller provided a buffer, then it
527
- * is assumed to be GIT_WIN_PATH_UTF8 characters in size. If it isn't,
528
- * then we may overflow. */
529
- if (git_win32_path_to_utf8(buffer, buffer_w) < 0)
530
- return NULL;
531
-
570
+ /* Convert backslashes to forward slashes */
532
571
  git_path_mkposix(buffer);
533
572
 
534
573
  return buffer;
@@ -536,11 +575,19 @@ char *p_realpath(const char *orig_path, char *buffer)
536
575
 
537
576
  int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
538
577
  {
539
- #ifdef _MSC_VER
578
+ #if defined(_MSC_VER)
540
579
  int len;
541
580
 
542
- if (count == 0 ||
543
- (len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr)) < 0)
581
+ if (count == 0)
582
+ return _vscprintf(format, argptr);
583
+
584
+ #if _MSC_VER >= 1500
585
+ len = _vsnprintf_s(buffer, count, _TRUNCATE, format, argptr);
586
+ #else
587
+ len = _vsnprintf(buffer, count, format, argptr);
588
+ #endif
589
+
590
+ if (len < 0)
544
591
  return _vscprintf(format, argptr);
545
592
 
546
593
  return len;
@@ -561,10 +608,9 @@ int p_snprintf(char *buffer, size_t count, const char *format, ...)
561
608
  return r;
562
609
  }
563
610
 
564
- /* TODO: wut? */
565
611
  int p_mkstemp(char *tmp_path)
566
612
  {
567
- #if defined(_MSC_VER)
613
+ #if defined(_MSC_VER) && _MSC_VER >= 1500
568
614
  if (_mktemp_s(tmp_path, strlen(tmp_path) + 1) != 0)
569
615
  return -1;
570
616
  #else
@@ -579,12 +625,37 @@ int p_access(const char* path, mode_t mode)
579
625
  {
580
626
  git_win32_path buf;
581
627
 
582
- if (git_win32_path_from_utf8(buf, path) < 0)
628
+ if (utf8_to_16_with_errno(buf, path) < 0)
583
629
  return -1;
584
630
 
585
631
  return _waccess(buf, mode);
586
632
  }
587
633
 
634
+ static int ensure_writable(wchar_t *fpath)
635
+ {
636
+ DWORD attrs;
637
+
638
+ attrs = GetFileAttributesW(fpath);
639
+ if (attrs == INVALID_FILE_ATTRIBUTES) {
640
+ if (GetLastError() == ERROR_FILE_NOT_FOUND)
641
+ return 0;
642
+
643
+ giterr_set(GITERR_OS, "failed to get attributes");
644
+ return -1;
645
+ }
646
+
647
+ if (!(attrs & FILE_ATTRIBUTE_READONLY))
648
+ return 0;
649
+
650
+ attrs &= ~FILE_ATTRIBUTE_READONLY;
651
+ if (!SetFileAttributesW(fpath, attrs)) {
652
+ giterr_set(GITERR_OS, "failed to set attributes");
653
+ return -1;
654
+ }
655
+
656
+ return 0;
657
+ }
658
+
588
659
  int p_rename(const char *from, const char *to)
589
660
  {
590
661
  git_win32_path wfrom;
@@ -593,15 +664,16 @@ int p_rename(const char *from, const char *to)
593
664
  int rename_succeeded;
594
665
  int error;
595
666
 
596
- if (git_win32_path_from_utf8(wfrom, from) < 0 ||
597
- git_win32_path_from_utf8(wto, to) < 0)
667
+ if (utf8_to_16_with_errno(wfrom, from) < 0 ||
668
+ utf8_to_16_with_errno(wto, to) < 0)
598
669
  return -1;
599
-
670
+
600
671
  /* wait up to 50ms if file is locked by another thread or process */
601
672
  rename_tries = 0;
602
673
  rename_succeeded = 0;
603
674
  while (rename_tries < 10) {
604
- if (MoveFileExW(wfrom, wto, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) != 0) {
675
+ if (ensure_writable(wto) == 0 &&
676
+ MoveFileExW(wfrom, wto, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) != 0) {
605
677
  rename_succeeded = 1;
606
678
  break;
607
679
  }