rugged 1.5.1 → 1.6.2

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 (154) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +2 -2
  3. data/ext/rugged/rugged_blame.c +2 -0
  4. data/ext/rugged/rugged_blob.c +3 -0
  5. data/ext/rugged/rugged_commit.c +1 -0
  6. data/ext/rugged/rugged_config.c +2 -0
  7. data/ext/rugged/rugged_diff.c +1 -0
  8. data/ext/rugged/rugged_index.c +2 -0
  9. data/ext/rugged/rugged_patch.c +1 -0
  10. data/ext/rugged/rugged_rebase.c +1 -0
  11. data/ext/rugged/rugged_reference.c +1 -0
  12. data/ext/rugged/rugged_remote.c +1 -0
  13. data/ext/rugged/rugged_repo.c +5 -2
  14. data/ext/rugged/rugged_revwalk.c +5 -1
  15. data/ext/rugged/rugged_submodule.c +1 -0
  16. data/ext/rugged/rugged_tag.c +1 -0
  17. data/ext/rugged/rugged_tree.c +4 -0
  18. data/lib/rugged/index.rb +1 -1
  19. data/lib/rugged/tree.rb +1 -1
  20. data/lib/rugged/version.rb +1 -1
  21. data/vendor/libgit2/CMakeLists.txt +5 -1
  22. data/vendor/libgit2/COPYING +30 -0
  23. data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
  24. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +2 -0
  25. data/vendor/libgit2/include/git2/common.h +13 -6
  26. data/vendor/libgit2/include/git2/deprecated.h +6 -0
  27. data/vendor/libgit2/include/git2/diff.h +1 -1
  28. data/vendor/libgit2/include/git2/experimental.h +20 -0
  29. data/vendor/libgit2/include/git2/indexer.h +29 -0
  30. data/vendor/libgit2/include/git2/object.h +28 -2
  31. data/vendor/libgit2/include/git2/odb.h +58 -7
  32. data/vendor/libgit2/include/git2/odb_backend.h +106 -18
  33. data/vendor/libgit2/include/git2/oid.h +115 -15
  34. data/vendor/libgit2/include/git2/repository.h +20 -1
  35. data/vendor/libgit2/include/git2/stash.h +60 -6
  36. data/vendor/libgit2/include/git2/strarray.h +0 -13
  37. data/vendor/libgit2/include/git2/sys/odb_backend.h +1 -1
  38. data/vendor/libgit2/include/git2/sys/transport.h +12 -0
  39. data/vendor/libgit2/include/git2/version.h +4 -4
  40. data/vendor/libgit2/include/git2.h +1 -0
  41. data/vendor/libgit2/src/CMakeLists.txt +0 -6
  42. data/vendor/libgit2/src/cli/CMakeLists.txt +6 -2
  43. data/vendor/libgit2/src/cli/cmd_hash_object.c +27 -8
  44. data/vendor/libgit2/src/cli/opt.c +1 -1
  45. data/vendor/libgit2/src/libgit2/CMakeLists.txt +25 -15
  46. data/vendor/libgit2/src/libgit2/annotated_commit.c +1 -1
  47. data/vendor/libgit2/src/libgit2/annotated_commit.h +1 -1
  48. data/vendor/libgit2/src/libgit2/attr_file.c +1 -1
  49. data/vendor/libgit2/src/libgit2/attrcache.c +1 -1
  50. data/vendor/libgit2/src/libgit2/blame.c +2 -0
  51. data/vendor/libgit2/src/libgit2/blob.c +4 -2
  52. data/vendor/libgit2/src/libgit2/blob.h +2 -2
  53. data/vendor/libgit2/src/libgit2/branch.c +2 -2
  54. data/vendor/libgit2/src/libgit2/cherrypick.c +3 -3
  55. data/vendor/libgit2/src/libgit2/clone.c +31 -2
  56. data/vendor/libgit2/src/libgit2/commit.c +52 -17
  57. data/vendor/libgit2/src/libgit2/commit.h +25 -7
  58. data/vendor/libgit2/src/libgit2/commit_graph.c +47 -32
  59. data/vendor/libgit2/src/libgit2/commit_graph.h +3 -0
  60. data/vendor/libgit2/src/libgit2/commit_list.c +6 -2
  61. data/vendor/libgit2/src/libgit2/config.c +1 -1
  62. data/vendor/libgit2/src/libgit2/config_file.c +2 -2
  63. data/vendor/libgit2/src/libgit2/describe.c +8 -8
  64. data/vendor/libgit2/src/libgit2/diff.c +5 -1
  65. data/vendor/libgit2/src/libgit2/diff_file.c +15 -6
  66. data/vendor/libgit2/src/libgit2/diff_generate.c +17 -12
  67. data/vendor/libgit2/src/libgit2/diff_print.c +5 -5
  68. data/vendor/libgit2/src/libgit2/diff_tform.c +4 -0
  69. data/vendor/libgit2/src/libgit2/email.c +2 -2
  70. data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
  71. data/vendor/libgit2/src/libgit2/fetch.c +3 -6
  72. data/vendor/libgit2/src/libgit2/fetchhead.c +4 -4
  73. data/vendor/libgit2/src/libgit2/ident.c +3 -3
  74. data/vendor/libgit2/src/libgit2/index.c +11 -9
  75. data/vendor/libgit2/src/libgit2/indexer.c +107 -44
  76. data/vendor/libgit2/src/libgit2/iterator.c +4 -2
  77. data/vendor/libgit2/src/libgit2/libgit2.c +19 -0
  78. data/vendor/libgit2/src/libgit2/merge.c +3 -3
  79. data/vendor/libgit2/src/libgit2/midx.c +16 -15
  80. data/vendor/libgit2/src/libgit2/mwindow.c +5 -2
  81. data/vendor/libgit2/src/libgit2/mwindow.h +4 -1
  82. data/vendor/libgit2/src/libgit2/notes.c +5 -5
  83. data/vendor/libgit2/src/libgit2/object.c +89 -25
  84. data/vendor/libgit2/src/libgit2/object.h +12 -3
  85. data/vendor/libgit2/src/libgit2/odb.c +194 -50
  86. data/vendor/libgit2/src/libgit2/odb.h +43 -4
  87. data/vendor/libgit2/src/libgit2/odb_loose.c +128 -70
  88. data/vendor/libgit2/src/libgit2/odb_pack.c +96 -44
  89. data/vendor/libgit2/src/libgit2/oid.c +134 -76
  90. data/vendor/libgit2/src/libgit2/oid.h +183 -9
  91. data/vendor/libgit2/src/libgit2/pack-objects.c +15 -4
  92. data/vendor/libgit2/src/libgit2/pack.c +90 -66
  93. data/vendor/libgit2/src/libgit2/pack.h +29 -15
  94. data/vendor/libgit2/src/libgit2/parse.c +4 -3
  95. data/vendor/libgit2/src/libgit2/patch_parse.c +5 -5
  96. data/vendor/libgit2/src/libgit2/push.c +13 -3
  97. data/vendor/libgit2/src/libgit2/reader.c +1 -1
  98. data/vendor/libgit2/src/libgit2/rebase.c +19 -18
  99. data/vendor/libgit2/src/libgit2/refdb_fs.c +70 -39
  100. data/vendor/libgit2/src/libgit2/reflog.c +7 -5
  101. data/vendor/libgit2/src/libgit2/reflog.h +1 -2
  102. data/vendor/libgit2/src/libgit2/refs.c +2 -0
  103. data/vendor/libgit2/src/libgit2/remote.c +38 -37
  104. data/vendor/libgit2/src/libgit2/remote.h +40 -0
  105. data/vendor/libgit2/src/libgit2/repository.c +212 -36
  106. data/vendor/libgit2/src/libgit2/repository.h +9 -0
  107. data/vendor/libgit2/src/libgit2/reset.c +2 -2
  108. data/vendor/libgit2/src/libgit2/revert.c +4 -4
  109. data/vendor/libgit2/src/libgit2/revparse.c +23 -7
  110. data/vendor/libgit2/src/libgit2/revwalk.c +5 -1
  111. data/vendor/libgit2/src/libgit2/stash.c +201 -26
  112. data/vendor/libgit2/src/libgit2/strarray.c +1 -0
  113. data/vendor/libgit2/src/libgit2/strarray.h +25 -0
  114. data/vendor/libgit2/src/libgit2/streams/openssl.c +1 -1
  115. data/vendor/libgit2/src/libgit2/streams/openssl_dynamic.c +7 -3
  116. data/vendor/libgit2/src/libgit2/streams/socket.c +4 -1
  117. data/vendor/libgit2/src/libgit2/submodule.c +6 -2
  118. data/vendor/libgit2/src/libgit2/sysdir.c +294 -7
  119. data/vendor/libgit2/src/libgit2/sysdir.h +39 -9
  120. data/vendor/libgit2/src/libgit2/tag.c +29 -10
  121. data/vendor/libgit2/src/libgit2/tag.h +2 -2
  122. data/vendor/libgit2/src/libgit2/threadstate.h +1 -1
  123. data/vendor/libgit2/src/libgit2/transports/http.c +8 -7
  124. data/vendor/libgit2/src/libgit2/transports/httpclient.c +9 -0
  125. data/vendor/libgit2/src/libgit2/transports/httpclient.h +10 -0
  126. data/vendor/libgit2/src/libgit2/transports/local.c +14 -0
  127. data/vendor/libgit2/src/libgit2/transports/smart.c +35 -0
  128. data/vendor/libgit2/src/libgit2/transports/smart.h +10 -1
  129. data/vendor/libgit2/src/libgit2/transports/smart_pkt.c +153 -41
  130. data/vendor/libgit2/src/libgit2/transports/smart_protocol.c +42 -12
  131. data/vendor/libgit2/src/libgit2/transports/ssh.c +62 -65
  132. data/vendor/libgit2/src/libgit2/transports/winhttp.c +9 -4
  133. data/vendor/libgit2/src/libgit2/tree-cache.c +4 -4
  134. data/vendor/libgit2/src/libgit2/tree.c +22 -16
  135. data/vendor/libgit2/src/libgit2/tree.h +2 -2
  136. data/vendor/libgit2/src/libgit2/worktree.c +5 -0
  137. data/vendor/libgit2/src/util/CMakeLists.txt +7 -1
  138. data/vendor/libgit2/src/util/fs_path.c +1 -1
  139. data/vendor/libgit2/src/util/futils.c +0 -3
  140. data/vendor/libgit2/src/util/git2_util.h +2 -2
  141. data/vendor/libgit2/src/util/hash/openssl.c +4 -3
  142. data/vendor/libgit2/src/util/hash/rfc6234/sha.h +0 -112
  143. data/vendor/libgit2/src/util/hash.h +13 -0
  144. data/vendor/libgit2/src/util/net.c +338 -84
  145. data/vendor/libgit2/src/util/net.h +7 -0
  146. data/vendor/libgit2/src/util/posix.h +2 -0
  147. data/vendor/libgit2/src/util/rand.c +4 -0
  148. data/vendor/libgit2/src/util/regexp.c +3 -3
  149. data/vendor/libgit2/src/util/thread.h +20 -19
  150. data/vendor/libgit2/src/util/util.h +1 -0
  151. metadata +7 -5
  152. data/vendor/libgit2/src/util/win32/findfile.c +0 -286
  153. data/vendor/libgit2/src/util/win32/findfile.h +0 -22
  154. /data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +0 -0
@@ -16,6 +16,7 @@
16
16
  #include "netops.h"
17
17
  #include "smart.h"
18
18
  #include "streams/socket.h"
19
+ #include "sysdir.h"
19
20
 
20
21
  #include "git2/credential.h"
21
22
  #include "git2/sys/credential.h"
@@ -245,8 +246,10 @@ static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) {
245
246
 
246
247
  rc = libssh2_agent_connect(agent);
247
248
 
248
- if (rc != LIBSSH2_ERROR_NONE)
249
+ if (rc != LIBSSH2_ERROR_NONE) {
250
+ rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED;
249
251
  goto shutdown;
252
+ }
250
253
 
251
254
  rc = libssh2_agent_list_identities(agent);
252
255
 
@@ -421,7 +424,8 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char *
421
424
  return 0;
422
425
  }
423
426
 
424
- #define KNOWN_HOSTS_FILE ".ssh/known_hosts"
427
+ #define SSH_DIR ".ssh"
428
+ #define KNOWN_HOSTS_FILE "known_hosts"
425
429
 
426
430
  /*
427
431
  * Load the known_hosts file.
@@ -430,16 +434,14 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char *
430
434
  */
431
435
  static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session)
432
436
  {
433
- git_str path = GIT_STR_INIT, home = GIT_STR_INIT;
437
+ git_str path = GIT_STR_INIT, sshdir = GIT_STR_INIT;
434
438
  LIBSSH2_KNOWNHOSTS *known_hosts = NULL;
435
439
  int error;
436
440
 
437
441
  GIT_ASSERT_ARG(hosts);
438
442
 
439
- if ((error = git__getenv(&home, "HOME")) < 0)
440
- return error;
441
-
442
- if ((error = git_str_joinpath(&path, git_str_cstr(&home), KNOWN_HOSTS_FILE)) < 0)
443
+ if ((error = git_sysdir_expand_homedir_file(&sshdir, SSH_DIR)) < 0 ||
444
+ (error = git_str_joinpath(&path, git_str_cstr(&sshdir), KNOWN_HOSTS_FILE)) < 0)
443
445
  goto out;
444
446
 
445
447
  if ((known_hosts = libssh2_knownhost_init(session)) == NULL) {
@@ -461,34 +463,32 @@ static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session
461
463
  out:
462
464
  *hosts = known_hosts;
463
465
 
464
- git_str_clear(&home);
465
- git_str_clear(&path);
466
+ git_str_dispose(&sshdir);
467
+ git_str_dispose(&path);
466
468
 
467
469
  return error;
468
470
  }
469
471
 
470
- static const char *hostkey_type_to_string(int type)
472
+ static void add_hostkey_pref_if_avail(
473
+ LIBSSH2_KNOWNHOSTS *known_hosts,
474
+ const char *hostname,
475
+ int port,
476
+ git_str *prefs,
477
+ int type,
478
+ const char *type_name)
471
479
  {
472
- switch (type) {
473
- case LIBSSH2_KNOWNHOST_KEY_SSHRSA:
474
- return "ssh-rsa";
475
- case LIBSSH2_KNOWNHOST_KEY_SSHDSS:
476
- return "ssh-dss";
477
- #ifdef LIBSSH2_KNOWNHOST_KEY_ECDSA_256
478
- case LIBSSH2_KNOWNHOST_KEY_ECDSA_256:
479
- return "ecdsa-sha2-nistp256";
480
- case LIBSSH2_KNOWNHOST_KEY_ECDSA_384:
481
- return "ecdsa-sha2-nistp384";
482
- case LIBSSH2_KNOWNHOST_KEY_ECDSA_521:
483
- return "ecdsa-sha2-nistp521";
484
- #endif
485
- #ifdef LIBSSH2_KNOWNHOST_KEY_ED25519
486
- case LIBSSH2_KNOWNHOST_KEY_ED25519:
487
- return "ssh-ed25519";
488
- #endif
489
- }
480
+ struct libssh2_knownhost *host = NULL;
481
+ const char key = '\0';
482
+ int mask = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW | type;
483
+ int error;
490
484
 
491
- return NULL;
485
+ error = libssh2_knownhost_checkp(known_hosts, hostname, port, &key, 1, mask, &host);
486
+ if (error == LIBSSH2_KNOWNHOST_CHECK_MISMATCH) {
487
+ if (git_str_len(prefs) > 0) {
488
+ git_str_putc(prefs, ',');
489
+ }
490
+ git_str_puts(prefs, type_name);
491
+ }
492
492
  }
493
493
 
494
494
  /*
@@ -496,27 +496,27 @@ static const char *hostkey_type_to_string(int type)
496
496
  * look it up with a nonsense key and using that mismatch to figure out what key
497
497
  * we do have stored for the host.
498
498
  *
499
- * Returns the string to pass to libssh2_session_method_pref or NULL if we were
500
- * unable to find anything or an error happened.
499
+ * Populates prefs with the string to pass to libssh2_session_method_pref.
501
500
  */
502
- static const char *find_hostkey_preference(LIBSSH2_KNOWNHOSTS *known_hosts, const char *hostname, int port)
501
+ static void find_hostkey_preference(
502
+ LIBSSH2_KNOWNHOSTS *known_hosts,
503
+ const char *hostname,
504
+ int port,
505
+ git_str *prefs)
503
506
  {
504
- struct libssh2_knownhost *host = NULL;
505
- /* Specify no key type so we don't filter on that */
506
- int type = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW;
507
- const char key = '\0';
508
- int error;
509
-
510
507
  /*
511
- * In case of mismatch, we can find the type of key from known_hosts in
512
- * the returned host's information as it means that an entry was found
513
- * but our nonsense key obviously didn't match.
508
+ * The order here is important as it indicates the priority of what will
509
+ * be preferred.
514
510
  */
515
- error = libssh2_knownhost_checkp(known_hosts, hostname, port, &key, 1, type, &host);
516
- if (error == LIBSSH2_KNOWNHOST_CHECK_MISMATCH)
517
- return hostkey_type_to_string(host->typemask & LIBSSH2_KNOWNHOST_KEY_MASK);
518
-
519
- return NULL;
511
+ #ifdef LIBSSH2_KNOWNHOST_KEY_ED25519
512
+ add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ED25519, "ssh-ed25519");
513
+ #endif
514
+ #ifdef LIBSSH2_KNOWNHOST_KEY_ECDSA_256
515
+ add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_256, "ecdsa-sha2-nistp256");
516
+ add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_384, "ecdsa-sha2-nistp384");
517
+ add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_521, "ecdsa-sha2-nistp521");
518
+ #endif
519
+ add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_SSHRSA, "ssh-rsa");
520
520
  }
521
521
 
522
522
  static int _git_ssh_session_create(
@@ -526,11 +526,11 @@ static int _git_ssh_session_create(
526
526
  int port,
527
527
  git_stream *io)
528
528
  {
529
- int rc = 0;
529
+ git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
530
530
  LIBSSH2_SESSION *s;
531
531
  LIBSSH2_KNOWNHOSTS *known_hosts;
532
- git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
533
- const char *keytype = NULL;
532
+ git_str prefs = GIT_STR_INIT;
533
+ int rc = 0;
534
534
 
535
535
  GIT_ASSERT_ARG(session);
536
536
  GIT_ASSERT_ARG(hosts);
@@ -547,16 +547,17 @@ static int _git_ssh_session_create(
547
547
  return -1;
548
548
  }
549
549
 
550
- if ((keytype = find_hostkey_preference(known_hosts, hostname, port)) != NULL) {
550
+ find_hostkey_preference(known_hosts, hostname, port, &prefs);
551
+ if (git_str_len(&prefs) > 0) {
551
552
  do {
552
- rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, keytype);
553
+ rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, git_str_cstr(&prefs));
553
554
  } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc);
554
555
  if (rc != LIBSSH2_ERROR_NONE) {
555
556
  ssh_error(s, "failed to set hostkey preference");
556
557
  goto on_error;
557
558
  }
558
559
  }
559
-
560
+ git_str_dispose(&prefs);
560
561
 
561
562
  do {
562
563
  rc = libssh2_session_handshake(s, socket->s);
@@ -753,7 +754,7 @@ static int check_certificate(
753
754
  if (error == GIT_PASSTHROUGH) {
754
755
  error = git_error_state_restore(&previous_error);
755
756
  } else if (error < 0 && !git_error_last()) {
756
- git_error_set(GIT_ERROR_NET, "user canceled hostkey check");
757
+ git_error_set(GIT_ERROR_NET, "unknown remote host key");
757
758
  }
758
759
 
759
760
  git_error_state_free(&previous_error);
@@ -787,15 +788,8 @@ static int _git_ssh_setup_conn(
787
788
  s->session = NULL;
788
789
  s->channel = NULL;
789
790
 
790
- if (git_net_str_is_url(url))
791
- error = git_net_url_parse(&s->url, url);
792
- else
793
- error = git_net_url_parse_scp(&s->url, url);
794
-
795
- if (error < 0)
796
- goto done;
797
-
798
- if ((error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
791
+ if ((error = git_net_url_parse_standard_or_scp(&s->url, url)) < 0 ||
792
+ (error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 ||
799
793
  (error = git_stream_connect(s->io)) < 0)
800
794
  goto done;
801
795
 
@@ -805,8 +799,11 @@ static int _git_ssh_setup_conn(
805
799
  * as part of the stream connection, but that's not something that's
806
800
  * exposed.
807
801
  */
808
- if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0)
809
- port = -1;
802
+ if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) {
803
+ git_error_set(GIT_ERROR_NET, "invalid port to ssh: %s", s->url.port);
804
+ error = -1;
805
+ goto done;
806
+ }
810
807
 
811
808
  if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0)
812
809
  goto done;
@@ -1009,7 +1006,7 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
1009
1006
 
1010
1007
  /* either error, or the remote accepts NONE auth, which is bizarre, let's punt */
1011
1008
  if (list == NULL && !libssh2_userauth_authenticated(session)) {
1012
- ssh_error(session, "Failed to retrieve list of SSH authentication methods");
1009
+ ssh_error(session, "remote rejected authentication");
1013
1010
  return GIT_EAUTH;
1014
1011
  }
1015
1012
 
@@ -562,18 +562,23 @@ static int winhttp_stream_connect(winhttp_stream *s)
562
562
 
563
563
  for (i = 0; i < t->owner->connect_opts.custom_headers.count; i++) {
564
564
  if (t->owner->connect_opts.custom_headers.strings[i]) {
565
+ wchar_t *custom_header_wide = NULL;
566
+
565
567
  git_str_clear(&buf);
566
568
  git_str_puts(&buf, t->owner->connect_opts.custom_headers.strings[i]);
567
- if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) {
568
- git_error_set(GIT_ERROR_OS, "failed to convert custom header to wide characters");
569
+
570
+ /* Convert header to wide characters */
571
+ if ((error = git__utf8_to_16_alloc(&custom_header_wide, git_str_cstr(&buf))) < 0)
569
572
  goto on_error;
570
- }
571
573
 
572
- if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
574
+ if (!WinHttpAddRequestHeaders(s->request, custom_header_wide, (ULONG)-1L,
573
575
  WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
574
576
  git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
577
+ git__free(custom_header_wide);
575
578
  goto on_error;
576
579
  }
580
+
581
+ git__free(custom_header_wide);
577
582
  }
578
583
  }
579
584
 
@@ -111,11 +111,11 @@ static int read_tree_internal(git_tree_cache **out,
111
111
  /* The SHA1 is only there if it's not invalidated */
112
112
  if (tree->entry_count >= 0) {
113
113
  /* 160-bit SHA-1 for this tree and it's children */
114
- if (buffer + GIT_OID_RAWSZ > buffer_end)
114
+ if (buffer + GIT_OID_SHA1_SIZE > buffer_end)
115
115
  goto corrupted;
116
116
 
117
- git_oid_fromraw(&tree->oid, (const unsigned char *)buffer);
118
- buffer += GIT_OID_RAWSZ;
117
+ git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, GIT_OID_SHA1);
118
+ buffer += GIT_OID_SHA1_SIZE;
119
119
  }
120
120
 
121
121
  /* Parse children: */
@@ -263,7 +263,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
263
263
  git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
264
264
 
265
265
  if (tree->entry_count != -1)
266
- git_str_put(out, (char *)&tree->oid.id, GIT_OID_RAWSZ);
266
+ git_str_put(out, (char *)&tree->oid.id, GIT_OID_SHA1_SIZE);
267
267
 
268
268
  for (i = 0; i < tree->children_count; i++)
269
269
  write_tree(out, tree->children[i]);
@@ -85,11 +85,17 @@ static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, co
85
85
  char *filename_ptr;
86
86
  size_t tree_len;
87
87
 
88
+ #ifdef GIT_EXPERIMENTAL_SHA256
89
+ size_t oid_size = git_oid_size(id->type);
90
+ #else
91
+ size_t oid_size = GIT_OID_SHA1_SIZE;
92
+ #endif
93
+
88
94
  TREE_ENTRY_CHECK_NAMELEN(filename_len);
89
95
 
90
96
  if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) ||
91
97
  GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1) ||
92
- GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, GIT_OID_RAWSZ))
98
+ GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, oid_size))
93
99
  return NULL;
94
100
 
95
101
  entry = git__calloc(1, tree_len);
@@ -383,11 +389,12 @@ static int parse_mode(uint16_t *mode_out, const char *buffer, size_t buffer_len,
383
389
  return 0;
384
390
  }
385
391
 
386
- int git_tree__parse_raw(void *_tree, const char *data, size_t size)
392
+ int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type)
387
393
  {
388
394
  git_tree *tree = _tree;
389
395
  const char *buffer;
390
396
  const char *buffer_end;
397
+ const long oid_size = (long)git_oid_size(oid_type);
391
398
 
392
399
  buffer = data;
393
400
  buffer_end = buffer + size;
@@ -414,35 +421,33 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
414
421
  if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
415
422
  return tree_parse_error("failed to parse tree: can't parse filename", NULL);
416
423
 
417
- if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ)
424
+ if ((buffer_end - (nul + 1)) < (long)oid_size)
418
425
  return tree_parse_error("failed to parse tree: can't parse OID", NULL);
419
426
 
420
427
  /* Allocate the entry */
421
- {
422
- entry = git_array_alloc(tree->entries);
423
- GIT_ERROR_CHECK_ALLOC(entry);
424
-
425
- entry->attr = attr;
426
- entry->filename_len = (uint16_t)filename_len;
427
- entry->filename = buffer;
428
- git_oid_fromraw(&entry->oid, ((unsigned char *) buffer + filename_len + 1));
429
- }
428
+ entry = git_array_alloc(tree->entries);
429
+ GIT_ERROR_CHECK_ALLOC(entry);
430
430
 
431
+ entry->attr = attr;
432
+ entry->filename_len = (uint16_t)filename_len;
433
+ entry->filename = buffer;
431
434
  buffer += filename_len + 1;
432
- buffer += GIT_OID_RAWSZ;
435
+
436
+ git_oid__fromraw(&entry->oid, (unsigned char *)buffer, oid_type);
437
+ buffer += oid_size;
433
438
  }
434
439
 
435
440
  return 0;
436
441
  }
437
442
 
438
- int git_tree__parse(void *_tree, git_odb_object *odb_obj)
443
+ int git_tree__parse(void *_tree, git_odb_object *odb_obj, git_oid_t oid_type)
439
444
  {
440
445
  git_tree *tree = _tree;
441
446
  const char *data = git_odb_object_data(odb_obj);
442
447
  size_t size = git_odb_object_size(odb_obj);
443
448
  int error;
444
449
 
445
- if ((error = git_tree__parse_raw(tree, data, size)) < 0 ||
450
+ if ((error = git_tree__parse_raw(tree, data, size, oid_type)) < 0 ||
446
451
  (error = git_odb_object_dup(&tree->odb_obj, odb_obj)) < 0)
447
452
  return error;
448
453
 
@@ -506,6 +511,7 @@ static int git_treebuilder__write_with_buffer(
506
511
  git_odb *odb;
507
512
  git_tree_entry *entry;
508
513
  git_vector entries = GIT_VECTOR_INIT;
514
+ size_t oid_size = git_oid_size(bld->repo->oid_type);
509
515
 
510
516
  git_str_clear(buf);
511
517
 
@@ -529,7 +535,7 @@ static int git_treebuilder__write_with_buffer(
529
535
 
530
536
  git_str_printf(buf, "%o ", entry->attr);
531
537
  git_str_put(buf, entry->filename, entry->filename_len + 1);
532
- git_str_put(buf, (char *)entry->oid.id, GIT_OID_RAWSZ);
538
+ git_str_put(buf, (char *)entry->oid.id, oid_size);
533
539
 
534
540
  if (git_str_oom(buf)) {
535
541
  error = -1;
@@ -41,8 +41,8 @@ GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e)
41
41
  }
42
42
 
43
43
  void git_tree__free(void *tree);
44
- int git_tree__parse(void *tree, git_odb_object *obj);
45
- int git_tree__parse_raw(void *_tree, const char *data, size_t size);
44
+ int git_tree__parse(void *tree, git_odb_object *obj, git_oid_t oid_type);
45
+ int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type);
46
46
 
47
47
  /**
48
48
  * Write a tree to the given repository
@@ -187,6 +187,11 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
187
187
  if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0)
188
188
  goto out;
189
189
 
190
+ if (!git_fs_path_isdir(path.ptr)) {
191
+ error = GIT_ENOTFOUND;
192
+ goto out;
193
+ }
194
+
190
195
  if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0)
191
196
  goto out;
192
197
 
@@ -4,8 +4,12 @@ add_library(util OBJECT)
4
4
  set_target_properties(util PROPERTIES C_STANDARD 90)
5
5
  set_target_properties(util PROPERTIES C_EXTENSIONS OFF)
6
6
 
7
+ configure_file(git2_features.h.in git2_features.h)
8
+
7
9
  set(UTIL_INCLUDES
8
- "${PROJECT_BINARY_DIR}/src"
10
+ "${PROJECT_BINARY_DIR}/src/util"
11
+ "${PROJECT_BINARY_DIR}/include"
12
+ "${PROJECT_BINARY_DIR}/include/git2"
9
13
  "${PROJECT_SOURCE_DIR}/src/util"
10
14
  "${PROJECT_SOURCE_DIR}/include")
11
15
 
@@ -34,6 +38,7 @@ if(USE_SHA1 STREQUAL "CollisionDetection")
34
38
  target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_SHA1_C=\"git2_util.h\")
35
39
  target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"git2_util.h\")
36
40
  elseif(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA1 STREQUAL "OpenSSL-Dynamic")
41
+ add_definitions(-DOPENSSL_API_COMPAT=0x10100000L)
37
42
  file(GLOB UTIL_SRC_SHA1 hash/openssl.*)
38
43
  elseif(USE_SHA1 STREQUAL "CommonCrypto")
39
44
  file(GLOB UTIL_SRC_SHA1 hash/common_crypto.*)
@@ -50,6 +55,7 @@ list(SORT UTIL_SRC_SHA1)
50
55
  if(USE_SHA256 STREQUAL "Builtin")
51
56
  file(GLOB UTIL_SRC_SHA256 hash/builtin.* hash/rfc6234/*)
52
57
  elseif(USE_SHA256 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL-Dynamic")
58
+ add_definitions(-DOPENSSL_API_COMPAT=0x10100000L)
53
59
  file(GLOB UTIL_SRC_SHA256 hash/openssl.*)
54
60
  elseif(USE_SHA256 STREQUAL "CommonCrypto")
55
61
  file(GLOB UTIL_SRC_SHA256 hash/common_crypto.*)
@@ -1855,7 +1855,7 @@ static int file_owner_sid(PSID *out, const char *path)
1855
1855
  PSECURITY_DESCRIPTOR descriptor = NULL;
1856
1856
  PSID owner_sid;
1857
1857
  DWORD ret;
1858
- int error = -1;
1858
+ int error = GIT_EINVALID;
1859
1859
 
1860
1860
  if (git_win32_path_from_utf8(path_w32, path) < 0)
1861
1861
  return -1;
@@ -13,9 +13,6 @@
13
13
  #include "rand.h"
14
14
 
15
15
  #include <ctype.h>
16
- #if GIT_WIN32
17
- #include "win32/findfile.h"
18
- #endif
19
16
 
20
17
  #define GIT_FILEMODE_DEFAULT 0100666
21
18
 
@@ -7,8 +7,8 @@
7
7
  #ifndef INCLUDE_git2_util_h__
8
8
  #define INCLUDE_git2_util_h__
9
9
 
10
- #ifndef LIBGIT2_NO_FEATURES_H
11
- # include "git2/sys/features.h"
10
+ #if !defined(LIBGIT2_NO_FEATURES_H)
11
+ # include "git2_features.h"
12
12
  #endif
13
13
 
14
14
  #include "git2/common.h"
@@ -10,8 +10,8 @@
10
10
  #ifdef GIT_OPENSSL_DYNAMIC
11
11
  # include <dlfcn.h>
12
12
 
13
- int handle_count;
14
- void *openssl_handle;
13
+ static int handle_count;
14
+ static void *openssl_handle;
15
15
 
16
16
  static int git_hash_openssl_global_shutdown(void)
17
17
  {
@@ -30,7 +30,8 @@ static int git_hash_openssl_global_init(void)
30
30
  (openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL &&
31
31
  (openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL &&
32
32
  (openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL &&
33
- (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL) {
33
+ (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL &&
34
+ (openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) {
34
35
  git_error_set(GIT_ERROR_SSL, "could not load ssl libraries");
35
36
  return -1;
36
37
  }
@@ -191,49 +191,6 @@ typedef struct SHA256Context SHA224Context;
191
191
  */
192
192
  typedef struct SHA512Context SHA384Context;
193
193
 
194
- /*
195
- * This structure holds context information for all SHA
196
- * hashing operations.
197
- */
198
- typedef struct USHAContext {
199
- int whichSha; /* which SHA is being used */
200
- union {
201
- SHA1Context sha1Context;
202
- SHA224Context sha224Context; SHA256Context sha256Context;
203
- SHA384Context sha384Context; SHA512Context sha512Context;
204
- } ctx;
205
- } USHAContext;
206
-
207
- /*
208
- * This structure will hold context information for the HMAC
209
- * keyed-hashing operation.
210
- */
211
- typedef struct HMACContext {
212
- int whichSha; /* which SHA is being used */
213
- int hashSize; /* hash size of SHA being used */
214
- int blockSize; /* block size of SHA being used */
215
- USHAContext shaContext; /* SHA context */
216
- unsigned char k_opad[USHA_Max_Message_Block_Size];
217
- /* outer padding - key XORd with opad */
218
- int Computed; /* Is the MAC computed? */
219
- int Corrupted; /* Cumulative corruption code */
220
-
221
- } HMACContext;
222
-
223
- /*
224
- * This structure will hold context information for the HKDF
225
- * extract-and-expand Key Derivation Functions.
226
- */
227
- typedef struct HKDFContext {
228
- int whichSha; /* which SHA is being used */
229
- HMACContext hmacContext;
230
- int hashSize; /* hash size of SHA being used */
231
- unsigned char prk[USHAMaxHashSize];
232
- /* pseudo-random key - output of hkdfInput */
233
- int Computed; /* Is the key material computed? */
234
- int Corrupted; /* Cumulative corruption code */
235
- } HKDFContext;
236
-
237
194
  /*
238
195
  * Function Prototypes
239
196
  */
@@ -283,73 +240,4 @@ extern int SHA512FinalBits(SHA512Context *, uint8_t bits,
283
240
  extern int SHA512Result(SHA512Context *,
284
241
  uint8_t Message_Digest[SHA512HashSize]);
285
242
 
286
- /* Unified SHA functions, chosen by whichSha */
287
- extern int USHAReset(USHAContext *context, SHAversion whichSha);
288
- extern int USHAInput(USHAContext *context,
289
- const uint8_t *bytes, unsigned int bytecount);
290
- extern int USHAFinalBits(USHAContext *context,
291
- uint8_t bits, unsigned int bit_count);
292
- extern int USHAResult(USHAContext *context,
293
- uint8_t Message_Digest[USHAMaxHashSize]);
294
- extern int USHABlockSize(enum SHAversion whichSha);
295
- extern int USHAHashSize(enum SHAversion whichSha);
296
- extern int USHAHashSizeBits(enum SHAversion whichSha);
297
- extern const char *USHAHashName(enum SHAversion whichSha);
298
-
299
- /*
300
- * HMAC Keyed-Hashing for Message Authentication, RFC 2104,
301
- * for all SHAs.
302
- * This interface allows a fixed-length text input to be used.
303
- */
304
- extern int hmac(SHAversion whichSha, /* which SHA algorithm to use */
305
- const unsigned char *text, /* pointer to data stream */
306
- int text_len, /* length of data stream */
307
- const unsigned char *key, /* pointer to authentication key */
308
- int key_len, /* length of authentication key */
309
- uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */
310
-
311
- /*
312
- * HMAC Keyed-Hashing for Message Authentication, RFC 2104,
313
- * for all SHAs.
314
- * This interface allows any length of text input to be used.
315
- */
316
- extern int hmacReset(HMACContext *context, enum SHAversion whichSha,
317
- const unsigned char *key, int key_len);
318
- extern int hmacInput(HMACContext *context, const unsigned char *text,
319
- int text_len);
320
- extern int hmacFinalBits(HMACContext *context, uint8_t bits,
321
- unsigned int bit_count);
322
- extern int hmacResult(HMACContext *context,
323
- uint8_t digest[USHAMaxHashSize]);
324
-
325
- /*
326
- * HKDF HMAC-based Extract-and-Expand Key Derivation Function,
327
- * RFC 5869, for all SHAs.
328
- */
329
- extern int hkdf(SHAversion whichSha, const unsigned char *salt,
330
- int salt_len, const unsigned char *ikm, int ikm_len,
331
- const unsigned char *info, int info_len,
332
- uint8_t okm[ ], int okm_len);
333
- extern int hkdfExtract(SHAversion whichSha, const unsigned char *salt,
334
- int salt_len, const unsigned char *ikm,
335
- int ikm_len, uint8_t prk[USHAMaxHashSize]);
336
- extern int hkdfExpand(SHAversion whichSha, const uint8_t prk[ ],
337
- int prk_len, const unsigned char *info,
338
- int info_len, uint8_t okm[ ], int okm_len);
339
-
340
- /*
341
- * HKDF HMAC-based Extract-and-Expand Key Derivation Function,
342
- * RFC 5869, for all SHAs.
343
- * This interface allows any length of text input to be used.
344
- */
345
- extern int hkdfReset(HKDFContext *context, enum SHAversion whichSha,
346
- const unsigned char *salt, int salt_len);
347
- extern int hkdfInput(HKDFContext *context, const unsigned char *ikm,
348
- int ikm_len);
349
- extern int hkdfFinalBits(HKDFContext *context, uint8_t ikm_bits,
350
- unsigned int ikm_bit_count);
351
- extern int hkdfResult(HKDFContext *context,
352
- uint8_t prk[USHAMaxHashSize],
353
- const unsigned char *info, int info_len,
354
- uint8_t okm[USHAMaxHashSize], int okm_len);
355
243
  #endif /* _SHA_H_ */
@@ -23,6 +23,8 @@ typedef enum {
23
23
  GIT_HASH_ALGORITHM_SHA256
24
24
  } git_hash_algorithm_t;
25
25
 
26
+ #define GIT_HASH_MAX_SIZE GIT_HASH_SHA256_SIZE
27
+
26
28
  typedef struct git_hash_ctx {
27
29
  union {
28
30
  git_hash_sha1_ctx sha1;
@@ -45,4 +47,15 @@ int git_hash_vec(unsigned char *out, git_str_vec *vec, size_t n, git_hash_algori
45
47
 
46
48
  int git_hash_fmt(char *out, unsigned char *hash, size_t hash_len);
47
49
 
50
+ GIT_INLINE(size_t) git_hash_size(git_hash_algorithm_t algorithm) {
51
+ switch (algorithm) {
52
+ case GIT_HASH_ALGORITHM_SHA1:
53
+ return GIT_HASH_SHA1_SIZE;
54
+ case GIT_HASH_ALGORITHM_SHA256:
55
+ return GIT_HASH_SHA256_SIZE;
56
+ default:
57
+ return 0;
58
+ }
59
+ }
60
+
48
61
  #endif