rugged 0.26.3 → 0.26.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/CMakeLists.txt +1 -1
  4. data/vendor/libgit2/deps/winhttp/winhttp.h +6 -4
  5. data/vendor/libgit2/deps/zlib/adler32.c +14 -7
  6. data/vendor/libgit2/deps/zlib/crc32.c +29 -12
  7. data/vendor/libgit2/deps/zlib/deflate.c +499 -303
  8. data/vendor/libgit2/deps/zlib/deflate.h +18 -15
  9. data/vendor/libgit2/deps/zlib/gzguts.h +218 -0
  10. data/vendor/libgit2/deps/zlib/infback.c +2 -2
  11. data/vendor/libgit2/deps/zlib/inffast.c +34 -51
  12. data/vendor/libgit2/deps/zlib/inflate.c +86 -37
  13. data/vendor/libgit2/deps/zlib/inflate.h +7 -4
  14. data/vendor/libgit2/deps/zlib/inftrees.c +12 -14
  15. data/vendor/libgit2/deps/zlib/trees.c +38 -61
  16. data/vendor/libgit2/deps/zlib/zconf.h +499 -23
  17. data/vendor/libgit2/deps/zlib/zlib.h +298 -154
  18. data/vendor/libgit2/deps/zlib/zutil.c +27 -23
  19. data/vendor/libgit2/deps/zlib/zutil.h +35 -17
  20. data/vendor/libgit2/include/git2.h +1 -0
  21. data/vendor/libgit2/include/git2/sys/mempack.h +5 -4
  22. data/vendor/libgit2/include/git2/version.h +2 -2
  23. data/vendor/libgit2/src/checkout.c +34 -11
  24. data/vendor/libgit2/src/curl_stream.c +21 -0
  25. data/vendor/libgit2/src/curl_stream.h +1 -0
  26. data/vendor/libgit2/src/delta.c +30 -28
  27. data/vendor/libgit2/src/diff.c +0 -7
  28. data/vendor/libgit2/src/diff_file.c +3 -1
  29. data/vendor/libgit2/src/diff_generate.c +1 -1
  30. data/vendor/libgit2/src/diff_tform.c +3 -1
  31. data/vendor/libgit2/src/global.c +4 -2
  32. data/vendor/libgit2/src/hash/hash_openssl.h +18 -3
  33. data/vendor/libgit2/src/ignore.c +60 -36
  34. data/vendor/libgit2/src/index.c +59 -26
  35. data/vendor/libgit2/src/indexer.c +15 -2
  36. data/vendor/libgit2/src/merge.c +18 -8
  37. data/vendor/libgit2/src/odb_mempack.c +1 -0
  38. data/vendor/libgit2/src/oidarray.c +12 -0
  39. data/vendor/libgit2/src/oidarray.h +1 -0
  40. data/vendor/libgit2/src/openssl_stream.c +17 -4
  41. data/vendor/libgit2/src/pack.c +10 -7
  42. data/vendor/libgit2/src/path.c +180 -22
  43. data/vendor/libgit2/src/path.h +73 -0
  44. data/vendor/libgit2/src/posix.c +1 -1
  45. data/vendor/libgit2/src/posix.h +3 -0
  46. data/vendor/libgit2/src/proxy.c +6 -0
  47. data/vendor/libgit2/src/proxy.h +1 -0
  48. data/vendor/libgit2/src/push.c +3 -0
  49. data/vendor/libgit2/src/refdb_fs.c +2 -2
  50. data/vendor/libgit2/src/refs.c +7 -1
  51. data/vendor/libgit2/src/repository.c +9 -3
  52. data/vendor/libgit2/src/sha1_lookup.c +2 -2
  53. data/vendor/libgit2/src/signature.c +1 -0
  54. data/vendor/libgit2/src/socket_stream.c +1 -1
  55. data/vendor/libgit2/src/stransport_stream.c +3 -1
  56. data/vendor/libgit2/src/submodule.c +54 -7
  57. data/vendor/libgit2/src/submodule.h +13 -0
  58. data/vendor/libgit2/src/transports/smart_pkt.c +8 -2
  59. data/vendor/libgit2/src/transports/smart_protocol.c +6 -6
  60. data/vendor/libgit2/src/transports/winhttp.c +22 -0
  61. data/vendor/libgit2/src/tree.c +1 -1
  62. metadata +3 -2
@@ -623,6 +623,7 @@ extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or
623
623
  extern bool git_path_isvalid(
624
624
  git_repository *repo,
625
625
  const char *path,
626
+ uint16_t mode,
626
627
  unsigned int flags);
627
628
 
628
629
  /**
@@ -630,4 +631,76 @@ extern bool git_path_isvalid(
630
631
  */
631
632
  int git_path_normalize_slashes(git_buf *out, const char *path);
632
633
 
634
+ /**
635
+ * Check whether a path component corresponds to a .gitmodules file
636
+ *
637
+ * @param name the path component to check
638
+ * @param len the length of `name`
639
+ */
640
+ extern int git_path_is_dotgit_modules(const char *name, size_t len);
641
+
642
+ /**
643
+ * Check whether a path component corresponds to a .gitmodules file in NTFS
644
+ *
645
+ * @param name the path component to check
646
+ * @param len the length of `name`
647
+ */
648
+ extern int git_path_is_ntfs_dotgit_modules(const char *name, size_t len);
649
+
650
+ /**
651
+ * Check whether a path component corresponds to a .gitmodules file in HFS+
652
+ *
653
+ * @param name the path component to check
654
+ * @param len the length of `name`
655
+ */
656
+ extern int git_path_is_hfs_dotgit_modules(const char *name, size_t len);
657
+
658
+ /**
659
+ * Check whether a path component corresponds to a .gitignore file
660
+ *
661
+ * @param name the path component to check
662
+ * @param len the length of `name`
663
+ */
664
+ extern int git_path_is_dotgit_ignore(const char *name, size_t len);
665
+
666
+ /**
667
+ * Check whether a path component corresponds to a .gitignore file in NTFS
668
+ *
669
+ * @param name the path component to check
670
+ * @param len the length of `name`
671
+ */
672
+ extern int git_path_is_ntfs_dotgit_ignore(const char *name, size_t len);
673
+
674
+ /**
675
+ * Check whether a path component corresponds to a .gitignore file in HFS+
676
+ *
677
+ * @param name the path component to check
678
+ * @param len the length of `name`
679
+ */
680
+ extern int git_path_is_hfs_dotgit_ignore(const char *name, size_t len);
681
+
682
+ /**
683
+ * Check whether a path component corresponds to a .gitignore file
684
+ *
685
+ * @param name the path component to check
686
+ * @param len the length of `name`
687
+ */
688
+ extern int git_path_is_dotgit_attributes(const char *name, size_t len);
689
+
690
+ /**
691
+ * Check whether a path component corresponds to a .gitattributes file in NTFS
692
+ *
693
+ * @param name the path component to check
694
+ * @param len the length of `name`
695
+ */
696
+ extern int git_path_is_ntfs_dotgit_attributes(const char *name, size_t len);
697
+
698
+ /**
699
+ * Check whether a path component corresponds to a .gitattributes file in HFS+
700
+ *
701
+ * @param name the path component to check
702
+ * @param len the length of `name`
703
+ */
704
+ extern int git_path_is_hfs_dotgit_attributes(const char *name, size_t len);
705
+
633
706
  #endif
@@ -40,7 +40,7 @@ int p_getaddrinfo(
40
40
  if (ainfo->ai_servent)
41
41
  ainfo->ai_port = ainfo->ai_servent->s_port;
42
42
  else
43
- ainfo->ai_port = atol(port);
43
+ ainfo->ai_port = htons(atol(port));
44
44
 
45
45
  memcpy(&ainfo->ai_addr_in.sin_addr,
46
46
  ainfo->ai_hostent->h_addr_list[0],
@@ -59,6 +59,9 @@
59
59
  #ifndef O_CLOEXEC
60
60
  #define O_CLOEXEC 0
61
61
  #endif
62
+ #ifndef SOCK_CLOEXEC
63
+ #define SOCK_CLOEXEC 0
64
+ #endif
62
65
 
63
66
  /* access() mode parameter #defines */
64
67
  #ifndef F_OK
@@ -30,3 +30,9 @@ int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src)
30
30
 
31
31
  return 0;
32
32
  }
33
+
34
+ void git_proxy_options_clear(git_proxy_options *opts)
35
+ {
36
+ git__free((char *) opts->url);
37
+ opts->url = NULL;
38
+ }
@@ -10,5 +10,6 @@
10
10
  #include "git2/proxy.h"
11
11
 
12
12
  extern int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src);
13
+ extern void git_proxy_options_clear(git_proxy_options *opts);
13
14
 
14
15
  #endif
@@ -178,6 +178,9 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
178
178
  if (!fetch_spec)
179
179
  continue;
180
180
 
181
+ /* Clear the buffer which can be dirty from previous iteration */
182
+ git_buf_clear(&remote_ref_name);
183
+
181
184
  if ((error = git_refspec_transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
182
185
  goto on_error;
183
186
 
@@ -743,7 +743,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
743
743
 
744
744
  assert(file && backend && name);
745
745
 
746
- if (!git_path_isvalid(backend->repo, name, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
746
+ if (!git_path_isvalid(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
747
747
  giterr_set(GITERR_INVALID, "invalid reference name '%s'", name);
748
748
  return GIT_EINVALIDSPEC;
749
749
  }
@@ -1739,7 +1739,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
1739
1739
 
1740
1740
  repo = backend->repo;
1741
1741
 
1742
- if (!git_path_isvalid(backend->repo, refname, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1742
+ if (!git_path_isvalid(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1743
1743
  giterr_set(GITERR_INVALID, "invalid reference name '%s'", refname);
1744
1744
  return GIT_EINVALIDSPEC;
1745
1745
  }
@@ -1359,7 +1359,13 @@ int git_reference_peel(
1359
1359
  return peel_error(error, ref, "Cannot resolve reference");
1360
1360
  }
1361
1361
 
1362
- if (!git_oid_iszero(&resolved->peel)) {
1362
+ /*
1363
+ * If we try to peel an object to a tag, we cannot use
1364
+ * the fully peeled object, as that will always resolve
1365
+ * to a commit. So we only want to use the peeled value
1366
+ * if it is not zero and the target is not a tag.
1367
+ */
1368
+ if (target_type != GIT_OBJ_TAG && !git_oid_iszero(&resolved->peel)) {
1363
1369
  error = git_object_lookup(&target,
1364
1370
  git_reference_owner(ref), &resolved->peel, GIT_OBJ_ANY);
1365
1371
  } else {
@@ -1235,7 +1235,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
1235
1235
 
1236
1236
  name_len = strlen(name);
1237
1237
 
1238
- if ((name_len == def_len && memcmp(name, def, def_len) == 0) ||
1238
+ if ((name_len == def_len && memcmp(name, def, def_len) == 0) ||
1239
1239
  (name_len == def_dot_git_len && memcmp(name, def_dot_git, def_dot_git_len) == 0)) {
1240
1240
  git__free(name);
1241
1241
  return 0;
@@ -1784,7 +1784,13 @@ static int repo_init_structure(
1784
1784
  default_template = true;
1785
1785
  }
1786
1786
 
1787
- if (tdir) {
1787
+ /*
1788
+ * If tdir was the empty string, treat it like tdir was a path to an
1789
+ * empty directory (so, don't do any copying). This is the behavior
1790
+ * that git(1) exhibits, although it doesn't seem to be officially
1791
+ * documented.
1792
+ */
1793
+ if (tdir && git__strcmp(tdir, "") != 0) {
1788
1794
  uint32_t cpflags = GIT_CPDIR_COPY_SYMLINKS |
1789
1795
  GIT_CPDIR_SIMPLE_TO_MODE |
1790
1796
  GIT_CPDIR_COPY_DOTFILES;
@@ -2762,7 +2768,7 @@ int git_repository__cleanup_files(
2762
2768
  error = git_futils_rmdir_r(path, NULL,
2763
2769
  GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
2764
2770
  }
2765
-
2771
+
2766
2772
  git_buf_clear(&buf);
2767
2773
  }
2768
2774
 
@@ -232,7 +232,7 @@ int sha1_position(const void *table,
232
232
  {
233
233
  const unsigned char *base = table;
234
234
 
235
- do {
235
+ while (lo < hi) {
236
236
  unsigned mi = (lo + hi) / 2;
237
237
  int cmp = git_oid__hashcmp(base + mi * stride, key);
238
238
 
@@ -243,7 +243,7 @@ int sha1_position(const void *table,
243
243
  hi = mi;
244
244
  else
245
245
  lo = mi+1;
246
- } while (lo < hi);
246
+ }
247
247
 
248
248
  return -((int)lo)-1;
249
249
  }
@@ -231,6 +231,7 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
231
231
  if (git__strtol64(&sig->when.time, time_start, &time_end, 10) < 0) {
232
232
  git__free(sig->name);
233
233
  git__free(sig->email);
234
+ sig->name = sig->email = NULL;
234
235
  return signature_error("invalid Unix timestamp");
235
236
  }
236
237
 
@@ -104,7 +104,7 @@ int socket_connect(git_stream *stream)
104
104
  }
105
105
 
106
106
  for (p = info; p != NULL; p = p->ai_next) {
107
- s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
107
+ s = socket(p->ai_family, p->ai_socktype | SOCK_CLOEXEC, p->ai_protocol);
108
108
 
109
109
  if (s == INVALID_SOCKET)
110
110
  continue;
@@ -81,8 +81,10 @@ static int stransport_connect(git_stream *stream)
81
81
  }
82
82
 
83
83
  if (sec_res == kSecTrustResultDeny || sec_res == kSecTrustResultRecoverableTrustFailure ||
84
- sec_res == kSecTrustResultFatalTrustFailure)
84
+ sec_res == kSecTrustResultFatalTrustFailure) {
85
+ giterr_set(GITERR_SSL, "untrusted connection error");
85
86
  return GIT_ECERTIFICATE;
87
+ }
86
88
 
87
89
  return 0;
88
90
 
@@ -169,13 +169,13 @@ static void free_submodule_names(git_strmap *names)
169
169
  * TODO: for some use-cases, this might need case-folding on a
170
170
  * case-insensitive filesystem
171
171
  */
172
- static int load_submodule_names(git_strmap *out, git_config *cfg)
172
+ static int load_submodule_names(git_strmap *out, git_repository *repo, git_config *cfg)
173
173
  {
174
174
  const char *key = "submodule\\..*\\.path";
175
175
  git_config_iterator *iter;
176
176
  git_config_entry *entry;
177
177
  git_buf buf = GIT_BUF_INIT;
178
- int rval;
178
+ int rval, isvalid;
179
179
  int error = 0;
180
180
 
181
181
  if ((error = git_config_iterator_glob_new(&iter, cfg, key)) < 0)
@@ -186,16 +186,29 @@ static int load_submodule_names(git_strmap *out, git_config *cfg)
186
186
  fdot = strchr(entry->name, '.');
187
187
  ldot = strrchr(entry->name, '.');
188
188
 
189
+ git_buf_clear(&buf);
189
190
  git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
191
+ isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
192
+ if (isvalid < 0) {
193
+ error = isvalid;
194
+ goto out;
195
+ }
196
+ if (!isvalid)
197
+ continue;
198
+
190
199
  git_strmap_insert(out, entry->value, git_buf_detach(&buf), &rval);
191
200
  if (rval < 0) {
192
201
  giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table");
193
202
  return -1;
194
203
  }
195
204
  }
205
+ if (error == GIT_ITEROVER)
206
+ error = 0;
196
207
 
208
+ out:
209
+ git_buf_free(&buf);
197
210
  git_config_iterator_free(iter);
198
- return 0;
211
+ return error;
199
212
  }
200
213
 
201
214
  int git_submodule_lookup(
@@ -309,6 +322,28 @@ int git_submodule_lookup(
309
322
  return 0;
310
323
  }
311
324
 
325
+ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags)
326
+ {
327
+ git_buf buf = GIT_BUF_INIT;
328
+ int error, isvalid;
329
+
330
+ if (flags == 0)
331
+ flags = GIT_PATH_REJECT_FILESYSTEM_DEFAULTS;
332
+
333
+ /* Avoid allocating a new string if we can avoid it */
334
+ if (strchr(name, '\\') != NULL) {
335
+ if ((error = git_path_normalize_slashes(&buf, name)) < 0)
336
+ return error;
337
+ } else {
338
+ git_buf_attach_notowned(&buf, name, strlen(name));
339
+ }
340
+
341
+ isvalid = git_path_isvalid(repo, buf.ptr, 0, flags);
342
+ git_buf_free(&buf);
343
+
344
+ return isvalid;
345
+ }
346
+
312
347
  static void submodule_free_dup(void *sm)
313
348
  {
314
349
  git_submodule_free(sm);
@@ -354,7 +389,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
354
389
  git_strmap *names = 0;
355
390
 
356
391
  git_strmap_alloc(&names);
357
- if ((error = load_submodule_names(names, cfg)))
392
+ if ((error = load_submodule_names(names, git_index_owner(idx), cfg)))
358
393
  goto done;
359
394
 
360
395
  if ((error = git_iterator_for_index(&i, git_index_owner(idx), idx, NULL)) < 0)
@@ -406,7 +441,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
406
441
  const git_index_entry *entry;
407
442
  git_strmap *names = 0;
408
443
  git_strmap_alloc(&names);
409
- if ((error = load_submodule_names(names, cfg)))
444
+ if ((error = load_submodule_names(names, git_tree_owner(head), cfg)))
410
445
  goto done;
411
446
 
412
447
  if ((error = git_iterator_for_tree(&i, head, NULL)) < 0)
@@ -1492,13 +1527,19 @@ static int submodule_update_head(git_submodule *submodule)
1492
1527
 
1493
1528
  int git_submodule_reload(git_submodule *sm, int force)
1494
1529
  {
1495
- int error = 0;
1530
+ int error = 0, isvalid;
1496
1531
  git_config *mods;
1497
1532
 
1498
1533
  GIT_UNUSED(force);
1499
1534
 
1500
1535
  assert(sm);
1501
1536
 
1537
+ isvalid = git_submodule_name_is_valid(sm->repo, sm->name, 0);
1538
+ if (isvalid <= 0) {
1539
+ /* This should come with a warning, but we've no API for that */
1540
+ return isvalid;
1541
+ }
1542
+
1502
1543
  if (!git_repository_is_bare(sm->repo)) {
1503
1544
  /* refresh config data */
1504
1545
  mods = gitmodules_snapshot(sm->repo);
@@ -1839,7 +1880,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
1839
1880
  git_strmap *map = data->map;
1840
1881
  git_buf name = GIT_BUF_INIT;
1841
1882
  git_submodule *sm;
1842
- int error;
1883
+ int error, isvalid;
1843
1884
 
1844
1885
  if (git__prefixcmp(entry->name, "submodule.") != 0)
1845
1886
  return 0;
@@ -1855,6 +1896,12 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
1855
1896
  if ((error = git_buf_set(&name, namestart, property - namestart -1)) < 0)
1856
1897
  return error;
1857
1898
 
1899
+ isvalid = git_submodule_name_is_valid(data->repo, name.ptr, 0);
1900
+ if (isvalid <= 0) {
1901
+ error = isvalid;
1902
+ goto done;
1903
+ }
1904
+
1858
1905
  /*
1859
1906
  * Now that we have the submodule's name, we can use that to
1860
1907
  * figure out whether it's in the map. If it's not, we create
@@ -146,4 +146,17 @@ extern int git_submodule_parse_update(
146
146
  extern int git_submodule__map(
147
147
  git_repository *repo,
148
148
  git_strmap *map);
149
+
150
+ /**
151
+ * Check whether a submodule's name is valid.
152
+ *
153
+ * Check the path against the path validity rules, either the filesystem
154
+ * defaults (like checkout does) or whichever you want to compare against.
155
+ *
156
+ * @param repo the repository which contains the submodule
157
+ * @param name the name to check
158
+ * @param flags the `GIT_PATH` flags to use for the check (0 to use filesystem defaults)
159
+ */
160
+ extern int git_submodule_name_is_valid(git_repository *repo, const char *name, int flags);
161
+
149
162
  #endif
@@ -299,8 +299,11 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
299
299
  pkt->ref = NULL;
300
300
  pkt->type = GIT_PKT_NG;
301
301
 
302
+ if (len < 3)
303
+ goto out_err;
302
304
  line += 3; /* skip "ng " */
303
- if (!(ptr = strchr(line, ' ')))
305
+ len -= 3;
306
+ if (!(ptr = memchr(line, ' ', len)))
304
307
  goto out_err;
305
308
  len = ptr - line;
306
309
 
@@ -311,8 +314,11 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
311
314
  memcpy(pkt->ref, line, len);
312
315
  pkt->ref[len] = '\0';
313
316
 
317
+ if (len < 1)
318
+ goto out_err;
314
319
  line = ptr + 1;
315
- if (!(ptr = strchr(line, '\n')))
320
+ len -= 1;
321
+ if (!(ptr = memchr(line, '\n', len)))
316
322
  goto out_err;
317
323
  len = ptr - line;
318
324
 
@@ -270,7 +270,7 @@ static int fetch_setup_walk(git_revwalk **out, git_repository *repo)
270
270
  git_revwalk *walk = NULL;
271
271
  git_strarray refs;
272
272
  unsigned int i;
273
- git_reference *ref;
273
+ git_reference *ref = NULL;
274
274
  int error;
275
275
 
276
276
  if ((error = git_reference_list(&refs, repo)) < 0)
@@ -282,6 +282,9 @@ static int fetch_setup_walk(git_revwalk **out, git_repository *repo)
282
282
  git_revwalk_sorting(walk, GIT_SORT_TIME);
283
283
 
284
284
  for (i = 0; i < refs.count; ++i) {
285
+ git_reference_free(ref);
286
+ ref = NULL;
287
+
285
288
  /* No tags */
286
289
  if (!git__prefixcmp(refs.strings[i], GIT_REFS_TAGS_DIR))
287
290
  continue;
@@ -294,16 +297,13 @@ static int fetch_setup_walk(git_revwalk **out, git_repository *repo)
294
297
 
295
298
  if ((error = git_revwalk_push(walk, git_reference_target(ref))) < 0)
296
299
  goto on_error;
297
-
298
- git_reference_free(ref);
299
300
  }
300
301
 
301
- git_strarray_free(&refs);
302
302
  *out = walk;
303
- return 0;
304
303
 
305
304
  on_error:
306
- git_revwalk_free(walk);
305
+ if (error)
306
+ git_revwalk_free(walk);
307
307
  git_reference_free(ref);
308
308
  git_strarray_free(&refs);
309
309
  return error;