rugged 1.5.1 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
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 +5 -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 +24 -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 +13 -12
  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 +213 -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 +92 -69
  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 +41 -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 +6 -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
@@ -38,6 +38,25 @@ typedef enum {
38
38
  */
39
39
  typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload);
40
40
 
41
+ /** Options for configuring a loose object backend. */
42
+ typedef struct {
43
+ unsigned int version; /**< version for the struct */
44
+
45
+ /**
46
+ * Type of object IDs to use for this object database, or
47
+ * 0 for default (currently SHA1).
48
+ */
49
+ git_oid_t oid_type;
50
+ } git_odb_options;
51
+
52
+ /* The current version of the diff options structure */
53
+ #define GIT_ODB_OPTIONS_VERSION 1
54
+
55
+ /* Stack initializer for odb options. Alternatively use
56
+ * `git_odb_options_init` programmatic initialization.
57
+ */
58
+ #define GIT_ODB_OPTIONS_INIT { GIT_ODB_OPTIONS_VERSION }
59
+
41
60
  /**
42
61
  * Create a new object database with no backends.
43
62
  *
@@ -46,9 +65,14 @@ typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload);
46
65
  *
47
66
  * @param out location to store the database pointer, if opened.
48
67
  * Set to NULL if the open failed.
68
+ * @param opts the options for this object database or NULL for defaults
49
69
  * @return 0 or an error code
50
70
  */
71
+ #ifdef GIT_EXPERIMENTAL_SHA256
72
+ GIT_EXTERN(int) git_odb_new(git_odb **out, const git_odb_options *opts);
73
+ #else
51
74
  GIT_EXTERN(int) git_odb_new(git_odb **out);
75
+ #endif
52
76
 
53
77
  /**
54
78
  * Create a new object database and automatically add
@@ -64,9 +88,17 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
64
88
  * @param out location to store the database pointer, if opened.
65
89
  * Set to NULL if the open failed.
66
90
  * @param objects_dir path of the backends' "objects" directory.
91
+ * @param opts the options for this object database or NULL for defaults
67
92
  * @return 0 or an error code
68
93
  */
94
+ #ifdef GIT_EXPERIMENTAL_SHA256
95
+ GIT_EXTERN(int) git_odb_open(
96
+ git_odb **out,
97
+ const char *objects_dir,
98
+ const git_odb_options *opts);
99
+ #else
69
100
  GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
101
+ #endif
70
102
 
71
103
  /**
72
104
  * Add an on-disk alternate to an existing Object DB.
@@ -117,7 +149,7 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
117
149
  * This method queries all available ODB backends
118
150
  * trying to match the 'len' first hexadecimal
119
151
  * characters of the 'short_id'.
120
- * The remaining (GIT_OID_HEXSZ-len)*4 bits of
152
+ * The remaining (GIT_OID_SHA1_HEXSIZE-len)*4 bits of
121
153
  * 'short_id' must be 0s.
122
154
  * 'len' must be at least GIT_OID_MINPREFIXLEN,
123
155
  * and the prefix must be long enough to identify
@@ -218,7 +250,7 @@ typedef struct git_odb_expand_id {
218
250
  *
219
251
  * The given array will be updated in place: for each abbreviated ID that is
220
252
  * unique in the database, and of the given type (if specified),
221
- * the full object ID, object ID length (`GIT_OID_HEXSZ`) and type will be
253
+ * the full object ID, object ID length (`GIT_OID_SHA1_HEXSIZE`) and type will be
222
254
  * written back to the array. For IDs that are not found (or are ambiguous),
223
255
  * the array entry will be zeroed.
224
256
  *
@@ -435,18 +467,28 @@ GIT_EXTERN(int) git_odb_write_multi_pack_index(
435
467
  git_odb *db);
436
468
 
437
469
  /**
438
- * Determine the object-ID (sha1 hash) of a data buffer
470
+ * Determine the object-ID (sha1 or sha256 hash) of a data buffer
439
471
  *
440
- * The resulting SHA-1 OID will be the identifier for the data
441
- * buffer as if the data buffer it were to written to the ODB.
472
+ * The resulting OID will be the identifier for the data buffer as if
473
+ * the data buffer it were to written to the ODB.
442
474
  *
443
475
  * @param out the resulting object-ID.
444
476
  * @param data data to hash
445
477
  * @param len size of the data
446
- * @param type of the data to hash
478
+ * @param object_type of the data to hash
479
+ * @param oid_type the oid type to hash to
447
480
  * @return 0 or an error code
448
481
  */
482
+ #ifdef GIT_EXPERIMENTAL_SHA256
483
+ GIT_EXTERN(int) git_odb_hash(
484
+ git_oid *out,
485
+ const void *data,
486
+ size_t len,
487
+ git_object_t object_type,
488
+ git_oid_t oid_type);
489
+ #else
449
490
  GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type);
491
+ #endif
450
492
 
451
493
  /**
452
494
  * Read a file from disk and fill a git_oid with the object id
@@ -458,10 +500,19 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_obj
458
500
  *
459
501
  * @param out oid structure the result is written into.
460
502
  * @param path file to read and determine object id for
461
- * @param type the type of the object that will be hashed
503
+ * @param object_type of the data to hash
504
+ * @param oid_type the oid type to hash to
462
505
  * @return 0 or an error code
463
506
  */
507
+ #ifdef GIT_EXPERIMENTAL_SHA256
508
+ GIT_EXTERN(int) git_odb_hashfile(
509
+ git_oid *out,
510
+ const char *path,
511
+ git_object_t object_type,
512
+ git_oid_t oid_type);
513
+ #else
464
514
  GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type);
515
+ #endif
465
516
 
466
517
  /**
467
518
  * Create a copy of an odb_object
@@ -24,6 +24,26 @@ GIT_BEGIN_DECL
24
24
  * Constructors for in-box ODB backends.
25
25
  */
26
26
 
27
+ /** Options for configuring a packfile object backend. */
28
+ typedef struct {
29
+ unsigned int version; /**< version for the struct */
30
+
31
+ /**
32
+ * Type of object IDs to use for this object database, or
33
+ * 0 for default (currently SHA1).
34
+ */
35
+ git_oid_t oid_type;
36
+ } git_odb_backend_pack_options;
37
+
38
+ /* The current version of the diff options structure */
39
+ #define GIT_ODB_BACKEND_PACK_OPTIONS_VERSION 1
40
+
41
+ /* Stack initializer for odb pack backend options. Alternatively use
42
+ * `git_odb_backend_pack_options_init` programmatic initialization.
43
+ */
44
+ #define GIT_ODB_BACKEND_PACK_OPTIONS_INIT \
45
+ { GIT_ODB_BACKEND_PACK_OPTIONS_VERSION }
46
+
27
47
  /**
28
48
  * Create a backend for the packfiles.
29
49
  *
@@ -32,20 +52,96 @@ GIT_BEGIN_DECL
32
52
  *
33
53
  * @return 0 or an error code
34
54
  */
35
- GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
55
+ #ifdef GIT_EXPERIMENTAL_SHA256
56
+ GIT_EXTERN(int) git_odb_backend_pack(
57
+ git_odb_backend **out,
58
+ const char *objects_dir,
59
+ const git_odb_backend_pack_options *opts);
60
+ #else
61
+ GIT_EXTERN(int) git_odb_backend_pack(
62
+ git_odb_backend **out,
63
+ const char *objects_dir);
64
+ #endif
65
+
66
+ /**
67
+ * Create a backend out of a single packfile
68
+ *
69
+ * This can be useful for inspecting the contents of a single
70
+ * packfile.
71
+ *
72
+ * @param out location to store the odb backend pointer
73
+ * @param index_file path to the packfile's .idx file
74
+ *
75
+ * @return 0 or an error code
76
+ */
77
+ #ifdef GIT_EXPERIMENTAL_SHA256
78
+ GIT_EXTERN(int) git_odb_backend_one_pack(
79
+ git_odb_backend **out,
80
+ const char *index_file,
81
+ const git_odb_backend_pack_options *opts);
82
+ #else
83
+ GIT_EXTERN(int) git_odb_backend_one_pack(
84
+ git_odb_backend **out,
85
+ const char *index_file);
86
+ #endif
87
+
88
+ typedef enum {
89
+ GIT_ODB_BACKEND_LOOSE_FSYNC = (1 << 0)
90
+ } git_odb_backend_loose_flag_t;
91
+
92
+ /** Options for configuring a loose object backend. */
93
+ typedef struct {
94
+ unsigned int version; /**< version for the struct */
95
+
96
+ /** A combination of the `git_odb_backend_loose_flag_t` types. */
97
+ uint32_t flags;
98
+
99
+ /**
100
+ * zlib compression level to use (0-9), where 1 is the fastest
101
+ * at the expense of larger files, and 9 produces the best
102
+ * compression at the expense of speed. 0 indicates that no
103
+ * compression should be performed. -1 is the default (currently
104
+ * optimizing for speed).
105
+ */
106
+ int compression_level;
107
+
108
+ /** Permissions to use creating a directory or 0 for defaults */
109
+ unsigned int dir_mode;
110
+
111
+ /** Permissions to use creating a file or 0 for defaults */
112
+ unsigned int file_mode;
113
+
114
+ /**
115
+ * Type of object IDs to use for this object database, or
116
+ * 0 for default (currently SHA1).
117
+ */
118
+ git_oid_t oid_type;
119
+ } git_odb_backend_loose_options;
120
+
121
+ /* The current version of the diff options structure */
122
+ #define GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION 1
123
+
124
+ /* Stack initializer for odb loose backend options. Alternatively use
125
+ * `git_odb_backend_loose_options_init` programmatic initialization.
126
+ */
127
+ #define GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT \
128
+ { GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION, 0, -1 }
36
129
 
37
130
  /**
38
131
  * Create a backend for loose objects
39
132
  *
40
133
  * @param out location to store the odb backend pointer
41
134
  * @param objects_dir the Git repository's objects directory
42
- * @param compression_level zlib compression level to use
43
- * @param do_fsync whether to do an fsync() after writing
44
- * @param dir_mode permissions to use creating a directory or 0 for defaults
45
- * @param file_mode permissions to use creating a file or 0 for defaults
135
+ * @param opts options for the loose object backend or NULL
46
136
  *
47
137
  * @return 0 or an error code
48
138
  */
139
+ #ifdef GIT_EXPERIMENTAL_SHA256
140
+ GIT_EXTERN(int) git_odb_backend_loose(
141
+ git_odb_backend **out,
142
+ const char *objects_dir,
143
+ git_odb_backend_loose_options *opts);
144
+ #else
49
145
  GIT_EXTERN(int) git_odb_backend_loose(
50
146
  git_odb_backend **out,
51
147
  const char *objects_dir,
@@ -53,19 +149,7 @@ GIT_EXTERN(int) git_odb_backend_loose(
53
149
  int do_fsync,
54
150
  unsigned int dir_mode,
55
151
  unsigned int file_mode);
56
-
57
- /**
58
- * Create a backend out of a single packfile
59
- *
60
- * This can be useful for inspecting the contents of a single
61
- * packfile.
62
- *
63
- * @param out location to store the odb backend pointer
64
- * @param index_file path to the packfile's .idx file
65
- *
66
- * @return 0 or an error code
67
- */
68
- GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
152
+ #endif
69
153
 
70
154
  /** Streaming mode */
71
155
  typedef enum {
@@ -87,6 +171,10 @@ struct git_odb_stream {
87
171
  unsigned int mode;
88
172
  void *hash_ctx;
89
173
 
174
+ #ifdef GIT_EXPERIMENTAL_SHA256
175
+ git_oid_t oid_type;
176
+ #endif
177
+
90
178
  git_object_size_t declared_size;
91
179
  git_object_size_t received_bytes;
92
180
 
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "common.h"
11
11
  #include "types.h"
12
+ #include "experimental.h"
12
13
 
13
14
  /**
14
15
  * @file git2/oid.h
@@ -19,11 +20,76 @@
19
20
  */
20
21
  GIT_BEGIN_DECL
21
22
 
22
- /** Size (in bytes) of a raw/binary oid */
23
- #define GIT_OID_RAWSZ 20
23
+ /** The type of object id. */
24
+ typedef enum {
24
25
 
25
- /** Size (in bytes) of a hex formatted oid */
26
- #define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2)
26
+ #ifdef GIT_EXPERIMENTAL_SHA256
27
+ GIT_OID_SHA1 = 1, /**< SHA1 */
28
+ GIT_OID_SHA256 = 2 /**< SHA256 */
29
+ #else
30
+ GIT_OID_SHA1 = 1 /**< SHA1 */
31
+ #endif
32
+
33
+ } git_oid_t;
34
+
35
+ /*
36
+ * SHA1 is currently the only supported object ID type.
37
+ */
38
+
39
+ /** SHA1 is currently libgit2's default oid type. */
40
+ #define GIT_OID_DEFAULT GIT_OID_SHA1
41
+
42
+ /** Size (in bytes) of a raw/binary sha1 oid */
43
+ #define GIT_OID_SHA1_SIZE 20
44
+ /** Size (in bytes) of a hex formatted sha1 oid */
45
+ #define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2)
46
+
47
+ /**
48
+ * The binary representation of the null sha1 object ID.
49
+ */
50
+ #ifndef GIT_EXPERIMENTAL_SHA256
51
+ # define GIT_OID_SHA1_ZERO { { 0 } }
52
+ #else
53
+ # define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } }
54
+ #endif
55
+
56
+ /**
57
+ * The string representation of the null sha1 object ID.
58
+ */
59
+ #define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000"
60
+
61
+ /*
62
+ * Experimental SHA256 support is a breaking change to the API.
63
+ * This exists for application compatibility testing.
64
+ */
65
+
66
+ #ifdef GIT_EXPERIMENTAL_SHA256
67
+
68
+ /** Size (in bytes) of a raw/binary sha256 oid */
69
+ # define GIT_OID_SHA256_SIZE 32
70
+ /** Size (in bytes) of a hex formatted sha256 oid */
71
+ # define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2)
72
+
73
+ /**
74
+ * The binary representation of the null sha256 object ID.
75
+ */
76
+ # define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } }
77
+
78
+ /**
79
+ * The string representation of the null sha256 object ID.
80
+ */
81
+ # define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000"
82
+
83
+ #endif
84
+
85
+ /* Maximum possible object ID size in raw / hex string format. */
86
+ #ifndef GIT_EXPERIMENTAL_SHA256
87
+ # define GIT_OID_MAX_SIZE GIT_OID_SHA1_SIZE
88
+ # define GIT_OID_MAX_HEXSIZE GIT_OID_SHA1_HEXSIZE
89
+ #else
90
+ # define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE
91
+ # define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE
92
+ #endif
27
93
 
28
94
  /** Minimum length (in number of hex characters,
29
95
  * i.e. packets of 4 bits) of an oid prefix */
@@ -31,29 +97,50 @@ GIT_BEGIN_DECL
31
97
 
32
98
  /** Unique identity of any object (commit, tree, blob, tag). */
33
99
  typedef struct git_oid {
100
+
101
+ #ifdef GIT_EXPERIMENTAL_SHA256
102
+ /** type of object id */
103
+ unsigned char type;
104
+ #endif
105
+
34
106
  /** raw binary formatted id */
35
- unsigned char id[GIT_OID_RAWSZ];
107
+ unsigned char id[GIT_OID_MAX_SIZE];
36
108
  } git_oid;
37
109
 
38
110
  /**
39
111
  * Parse a hex formatted object id into a git_oid.
40
112
  *
113
+ * The appropriate number of bytes for the given object ID type will
114
+ * be read from the string - 40 bytes for SHA1, 64 bytes for SHA256.
115
+ * The given string need not be NUL terminated.
116
+ *
41
117
  * @param out oid structure the result is written into.
42
118
  * @param str input hex string; must be pointing at the start of
43
119
  * the hex sequence and have at least the number of bytes
44
- * needed for an oid encoded in hex (40 bytes).
120
+ * needed for an oid encoded in hex (40 bytes for sha1,
121
+ * 256 bytes for sha256).
122
+ * @param type the type of object id
45
123
  * @return 0 or an error code
46
124
  */
125
+ #ifdef GIT_EXPERIMENTAL_SHA256
126
+ GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str, git_oid_t type);
127
+ #else
47
128
  GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
129
+ #endif
48
130
 
49
131
  /**
50
- * Parse a hex formatted null-terminated string into a git_oid.
132
+ * Parse a hex formatted NUL-terminated string into a git_oid.
51
133
  *
52
134
  * @param out oid structure the result is written into.
53
135
  * @param str input hex string; must be null-terminated.
136
+ * @param type the type of object id
54
137
  * @return 0 or an error code
55
138
  */
139
+ #ifdef GIT_EXPERIMENTAL_SHA256
140
+ GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type);
141
+ #else
56
142
  GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str);
143
+ #endif
57
144
 
58
145
  /**
59
146
  * Parse N characters of a hex formatted object id into a git_oid.
@@ -64,9 +151,14 @@ GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str);
64
151
  * @param out oid structure the result is written into.
65
152
  * @param str input hex string of at least size `length`
66
153
  * @param length length of the input string
154
+ * @param type the type of object id
67
155
  * @return 0 or an error code
68
156
  */
157
+ #ifdef GIT_EXPERIMENTAL_SHA256
158
+ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length, git_oid_t type);
159
+ #else
69
160
  GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length);
161
+ #endif
70
162
 
71
163
  /**
72
164
  * Copy an already raw oid into a git_oid structure.
@@ -75,16 +167,21 @@ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length);
75
167
  * @param raw the raw input bytes to be copied.
76
168
  * @return 0 on success or error code
77
169
  */
170
+ #ifdef GIT_EXPERIMENTAL_SHA256
171
+ GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type);
172
+ #else
78
173
  GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw);
174
+ #endif
79
175
 
80
176
  /**
81
177
  * Format a git_oid into a hex string.
82
178
  *
83
179
  * @param out output hex string; must be pointing at the start of
84
180
  * the hex sequence and have at least the number of bytes
85
- * needed for an oid encoded in hex (40 bytes). Only the
86
- * oid digits are written; a '\\0' terminator must be added
87
- * by the caller if it is required.
181
+ * needed for an oid encoded in hex (40 bytes for SHA1,
182
+ * 64 bytes for SHA256). Only the oid digits are written;
183
+ * a '\\0' terminator must be added by the caller if it is
184
+ * required.
88
185
  * @param id oid structure to format.
89
186
  * @return 0 on success or error code
90
187
  */
@@ -94,7 +191,7 @@ GIT_EXTERN(int) git_oid_fmt(char *out, const git_oid *id);
94
191
  * Format a git_oid into a partial hex string.
95
192
  *
96
193
  * @param out output hex string; you say how many bytes to write.
97
- * If the number of bytes is > GIT_OID_HEXSZ, extra bytes
194
+ * If the number of bytes is > GIT_OID_SHA1_HEXSIZE, extra bytes
98
195
  * will be zeroed; if not, a '\0' terminator is NOT added.
99
196
  * @param n number of characters to write into out string
100
197
  * @param id oid structure to format.
@@ -110,9 +207,10 @@ GIT_EXTERN(int) git_oid_nfmt(char *out, size_t n, const git_oid *id);
110
207
  *
111
208
  * @param out output hex string; must be pointing at the start of
112
209
  * the hex sequence and have at least the number of bytes
113
- * needed for an oid encoded in hex (41 bytes). Only the
114
- * oid digits are written; a '\\0' terminator must be added
115
- * by the caller if it is required.
210
+ * needed for an oid encoded in hex (41 bytes for SHA1,
211
+ * 65 bytes for SHA256). Only the oid digits are written;
212
+ * a '\\0' terminator must be added by the caller if it
213
+ * is required.
116
214
  * @param id oid structure to format.
117
215
  * @return 0 on success, non-zero callback return value, or error code
118
216
  */
@@ -134,7 +232,9 @@ GIT_EXTERN(char *) git_oid_tostr_s(const git_oid *oid);
134
232
  /**
135
233
  * Format a git_oid into a buffer as a hex format c-string.
136
234
  *
137
- * If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting
235
+ * If the buffer is smaller than the size of a hex-formatted oid string
236
+ * plus an additional byte (GIT_OID_SHA_HEXSIZE + 1 for SHA1 or
237
+ * GIT_OID_SHA256_HEXSIZE + 1 for SHA256), then the resulting
138
238
  * oid c-string will be truncated to n-1 characters (but will still be
139
239
  * NUL-byte terminated).
140
240
  *
@@ -351,6 +351,15 @@ typedef struct {
351
351
  * pointing to this URL.
352
352
  */
353
353
  const char *origin_url;
354
+
355
+ #ifdef GIT_EXPERIMENTAL_SHA256
356
+ /**
357
+ *
358
+ * Type of object IDs to use for this repository, or 0 for
359
+ * default (currently SHA1).
360
+ */
361
+ git_oid_t oid_type;
362
+ #endif
354
363
  } git_repository_init_options;
355
364
 
356
365
  #define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1
@@ -456,7 +465,9 @@ GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo);
456
465
  * Check if a repository is empty
457
466
  *
458
467
  * An empty repository has just been initialized and contains no references
459
- * apart from HEAD, which must be pointing to the unborn master branch.
468
+ * apart from HEAD, which must be pointing to the unborn master branch,
469
+ * or the branch specified for the repository in the `init.defaultBranch`
470
+ * configuration variable.
460
471
  *
461
472
  * @param repo Repo to test
462
473
  * @return 1 if the repository is empty, 0 if it isn't, error code
@@ -949,6 +960,14 @@ GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, cons
949
960
  */
950
961
  GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email);
951
962
 
963
+ /**
964
+ * Gets the object type used by this repository.
965
+ *
966
+ * @param repo the repository
967
+ * @return the object id type
968
+ */
969
+ GIT_EXTERN(git_oid_t) git_repository_oid_type(git_repository *repo);
970
+
952
971
  /** @} */
953
972
  GIT_END_DECL
954
973
  #endif
@@ -44,7 +44,12 @@ typedef enum {
44
44
  * All ignored files are also stashed and then cleaned up from
45
45
  * the working directory
46
46
  */
47
- GIT_STASH_INCLUDE_IGNORED = (1 << 2)
47
+ GIT_STASH_INCLUDE_IGNORED = (1 << 2),
48
+
49
+ /**
50
+ * All changes in the index and working directory are left intact
51
+ */
52
+ GIT_STASH_KEEP_ALL = (1 << 3)
48
53
  } git_stash_flags;
49
54
 
50
55
  /**
@@ -52,15 +57,10 @@ typedef enum {
52
57
  *
53
58
  * @param out Object id of the commit containing the stashed state.
54
59
  * This commit is also the target of the direct reference refs/stash.
55
- *
56
60
  * @param repo The owning repository.
57
- *
58
61
  * @param stasher The identity of the person performing the stashing.
59
- *
60
62
  * @param message Optional description along with the stashed state.
61
- *
62
63
  * @param flags Flags to control the stashing process. (see GIT_STASH_* above)
63
- *
64
64
  * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
65
65
  * or error code.
66
66
  */
@@ -71,6 +71,60 @@ GIT_EXTERN(int) git_stash_save(
71
71
  const char *message,
72
72
  uint32_t flags);
73
73
 
74
+ /**
75
+ * Stash save options structure
76
+ *
77
+ * Initialize with `GIT_STASH_SAVE_OPTIONS_INIT`. Alternatively, you can
78
+ * use `git_stash_save_options_init`.
79
+ *
80
+ */
81
+ typedef struct git_stash_save_options {
82
+ unsigned int version;
83
+
84
+ /** Flags to control the stashing process. (see GIT_STASH_* above) */
85
+ uint32_t flags;
86
+
87
+ /** The identity of the person performing the stashing. */
88
+ const git_signature *stasher;
89
+
90
+ /** Optional description along with the stashed state. */
91
+ const char *message;
92
+
93
+ /** Optional paths that control which files are stashed. */
94
+ git_strarray paths;
95
+ } git_stash_save_options;
96
+
97
+ #define GIT_STASH_SAVE_OPTIONS_VERSION 1
98
+ #define GIT_STASH_SAVE_OPTIONS_INIT { GIT_STASH_SAVE_OPTIONS_VERSION }
99
+
100
+ /**
101
+ * Initialize git_stash_save_options structure
102
+ *
103
+ * Initializes a `git_stash_save_options` with default values. Equivalent to
104
+ * creating an instance with `GIT_STASH_SAVE_OPTIONS_INIT`.
105
+ *
106
+ * @param opts The `git_stash_save_options` struct to initialize.
107
+ * @param version The struct version; pass `GIT_STASH_SAVE_OPTIONS_VERSION`.
108
+ * @return Zero on success; -1 on failure.
109
+ */
110
+ GIT_EXTERN(int) git_stash_save_options_init(
111
+ git_stash_save_options *opts, unsigned int version);
112
+
113
+ /**
114
+ * Save the local modifications to a new stash, with options.
115
+ *
116
+ * @param out Object id of the commit containing the stashed state.
117
+ * This commit is also the target of the direct reference refs/stash.
118
+ * @param repo The owning repository.
119
+ * @param opts The stash options.
120
+ * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
121
+ * or error code.
122
+ */
123
+ GIT_EXTERN(int) git_stash_save_with_opts(
124
+ git_oid *out,
125
+ git_repository *repo,
126
+ const git_stash_save_options *opts);
127
+
74
128
  /** Stash application flags. */
75
129
  typedef enum {
76
130
  GIT_STASH_APPLY_DEFAULT = 0,
@@ -36,19 +36,6 @@ typedef struct git_strarray {
36
36
  */
37
37
  GIT_EXTERN(void) git_strarray_dispose(git_strarray *array);
38
38
 
39
- /**
40
- * Copy a string array object from source to target.
41
- *
42
- * Note: target is overwritten and hence should be empty, otherwise its
43
- * contents are leaked. Call git_strarray_free() if necessary.
44
- *
45
- * @param tgt target
46
- * @param src source
47
- * @return 0 on success, < 0 on allocation failure
48
- */
49
- GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src);
50
-
51
-
52
39
  /** @} */
53
40
  GIT_END_DECL
54
41
 
@@ -36,7 +36,7 @@ struct git_odb_backend {
36
36
  void **, size_t *, git_object_t *, git_odb_backend *, const git_oid *);
37
37
 
38
38
  /* To find a unique object given a prefix of its oid. The oid given
39
- * must be so that the remaining (GIT_OID_HEXSZ - len)*4 bits are 0s.
39
+ * must be so that the remaining (GIT_OID_SHA1_HEXSIZE - len)*4 bits are 0s.
40
40
  */
41
41
  int GIT_CALLBACK(read_prefix)(
42
42
  git_oid *, void **, size_t *, git_object_t *,
@@ -57,6 +57,18 @@ struct git_transport {
57
57
  unsigned int *capabilities,
58
58
  git_transport *transport);
59
59
 
60
+ #ifdef GIT_EXPERIMENTAL_SHA256
61
+ /**
62
+ * Gets the object type for the remote repository.
63
+ *
64
+ * This function may be called after a successful call to
65
+ * `connect()`.
66
+ */
67
+ int GIT_CALLBACK(oid_type)(
68
+ git_oid_t *object_type,
69
+ git_transport *transport);
70
+ #endif
71
+
60
72
  /**
61
73
  * Get the list of available references in the remote repository.
62
74
  *