Commit 39fd7646cbb7cdc41c4f6810ca69ed234307fe10

Alex Good 2021-06-30T12:59:48

Merge branch 'main' into respect-force-flag-in-remote-fetch

diff --git a/README.md b/README.md
index b8448be..aa64254 100644
--- a/README.md
+++ b/README.md
@@ -104,7 +104,8 @@ Getting Help
 
 **Chat with us**
 
-- via IRC: join [#libgit2](https://webchat.freenode.net/#libgit2) on Freenode
+- via IRC: join [#libgit2](https://web.libera.chat/#libgit2) on
+  [libera](https://libera.chat).
 - via Slack: visit [slack.libgit2.org](http://slack.libgit2.org/) to sign up,
   then join us in `#libgit2`
 
diff --git a/docs/contributing.md b/docs/contributing.md
index 21e42b1..a6eca3d 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -35,7 +35,7 @@ easily accessible permanent record of the conversation.
 
 ## Libgit2 Versions
 
-The `master` branch is the main branch where development happens.
+The `main` branch is the main branch where development happens.
 Releases are tagged
 (e.g. [v0.21.0](https://github.com/libgit2/libgit2/releases/tag/v0.21.0) )
 and when a critical bug fix needs to be backported, it will be done on a
@@ -51,7 +51,7 @@ commit SHA
 Using [`git describe`](http://git-scm.com/docs/git-describe) is a
 great way to tell us what version you're working with.
 
-If you're not running against the latest `master` branch version,
+If you're not running against the latest `main` branch version,
 please compile and test against that to avoid re-reporting an issue that's
 already been fixed.
 
@@ -68,11 +68,11 @@ flow](https://guides.github.com/introduction/flow/index.html), where
 contributors fork the [libgit2 repository](https://github.com/libgit2/libgit2),
 make their changes on branch, and submit a
 [Pull Request](https://help.github.com/articles/using-pull-requests)
-(a.k.a. "PR").  Pull requests should usually be targeted at the `master`
+(a.k.a. "PR").  Pull requests should usually be targeted at the `main`
 branch.
 
 Life will be a lot easier for you (and us) if you follow this pattern
-(i.e. fork, named branch, submit PR).  If you use your fork's `master`
+(i.e. fork, named branch, submit PR).  If you use your fork's `main`
 branch directly, things can get messy.
 
 Please include a nice description of your changes when you submit your PR;
diff --git a/docs/release.md b/docs/release.md
index 22b35ed..3200c44 100644
--- a/docs/release.md
+++ b/docs/release.md
@@ -1,6 +1,6 @@
 # Releasing the library
 
-We have three kinds of releases: "full" releases, maintenance releases and security releases. Full ones release the state of the `master` branch whereas maintenance releases provide bugfixes building on top of the currently released series. Security releases are also for the current series but only contain security fixes on top of the previous release.
+We have three kinds of releases: "full" releases, maintenance releases and security releases. Full ones release the state of the `main` branch whereas maintenance releases provide bugfixes building on top of the currently released series. Security releases are also for the current series but only contain security fixes on top of the previous release.
 
 ## Full release
 
@@ -40,7 +40,7 @@ followed by the three sections in the changelog. For release candidates we can a
 
 During the freeze, and certainly after the first release candidate, any bindings the core team work with should be updated in order to discover any issues that might come up with the multitude of approaches to memory management, embedding or linking.
 
-Create a branch `maint/v0.X` at the current state of `master` after you've created the tag. This will be used for maintenance releases and lets our dependents track the latest state of the series.
+Create a branch `maint/v0.X` at the current state of `main` after you've created the tag. This will be used for maintenance releases and lets our dependents track the latest state of the series.
 
 ## Maintenance release
 
@@ -76,7 +76,7 @@ We use docurium to generate our documentation. It is a tool written in ruby whic
 
     gem install docurium
 
-and run it against our description file with the tip of master checked out.
+and run it against our description file with the tip of `main` checked out.
 
     cm doc api.docurium
 
diff --git a/include/git2/apply.h b/include/git2/apply.h
index b248eaa..bc637df 100644
--- a/include/git2/apply.h
+++ b/include/git2/apply.h
@@ -100,6 +100,7 @@ GIT_EXTERN(int) git_apply_options_init(git_apply_options *opts, unsigned int ver
  * @param preimage the tree to apply the diff to
  * @param diff the diff to apply
  * @param options the options for the apply (or null for defaults)
+ * @return 0 or an error code
  */
 GIT_EXTERN(int) git_apply_to_tree(
 	git_index **out,
@@ -137,6 +138,7 @@ typedef enum {
  * @param diff the diff to apply
  * @param location the location to apply (workdir, index or both)
  * @param options the options for the apply (or null for defaults)
+ * @return 0 or an error code
  */
 GIT_EXTERN(int) git_apply(
 	git_repository *repo,
diff --git a/include/git2/common.h b/include/git2/common.h
index 8dd30d5..dee260e 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -356,6 +356,11 @@ typedef enum {
  *		>
  *		> - `ciphers` is the list of ciphers that are eanbled.
  *
+ *	* opts(GIT_OPT_GET_USER_AGENT, git_buf *out)
+ *
+ *		> Get the value of the User-Agent header.
+ *		> The User-Agent is written to the `out` buffer.
+ *
  *	* opts(GIT_OPT_ENABLE_OFS_DELTA, int enabled)
  *
  *		> Enable or disable the use of "offset deltas" when creating packfiles,
diff --git a/include/git2/index.h b/include/git2/index.h
index 14a1324..532a520 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -702,7 +702,7 @@ GIT_EXTERN(int) git_index_update_all(
  * @param at_pos the address to which the position of the index entry is written (optional)
  * @param index an existing index object
  * @param path path to search
- * @return a zero-based position in the index if found; GIT_ENOTFOUND otherwise
+ * @return 0 or an error code
  */
 GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *path);
 
@@ -713,7 +713,7 @@ GIT_EXTERN(int) git_index_find(size_t *at_pos, git_index *index, const char *pat
  * @param at_pos the address to which the position of the index entry is written (optional)
  * @param index an existing index object
  * @param prefix the prefix to search for
- * @return 0 with valid value in at_pos; an error code otherwise
+ * @return 0 or an error code
  */
 GIT_EXTERN(int) git_index_find_prefix(size_t *at_pos, git_index *index, const char *prefix);
 
diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index 8059e4d..a434d24 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -51,7 +51,7 @@ typedef struct git_indexer_progress {
  * Type for progress callbacks during indexing.  Return a value less
  * than zero to cancel the indexing or download.
  *
- * @param stats Structure containing information about the state of the tran    sfer
+ * @param stats Structure containing information about the state of the transfer
  * @param payload Payload provided by caller
  */
 typedef int GIT_CALLBACK(git_indexer_progress_cb)(const git_indexer_progress *stats, void *payload);
@@ -64,6 +64,7 @@ typedef struct git_indexer_options {
 
 	/** progress_cb function to call with progress information */
 	git_indexer_progress_cb progress_cb;
+
 	/** progress_cb_payload payload for the progress callback */
 	void *progress_cb_payload;
 
diff --git a/include/git2/tree.h b/include/git2/tree.h
index d7545ac..f2289fc 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -334,6 +334,7 @@ GIT_EXTERN(int) git_treebuilder_insert(
  *
  * @param bld Tree builder
  * @param filename Filename of the entry to remove
+ * @return 0 or an error code
  */
 GIT_EXTERN(int) git_treebuilder_remove(
 	git_treebuilder *bld, const char *filename);
@@ -463,6 +464,7 @@ typedef struct {
  * @param baseline the tree to base these changes on
  * @param nupdates the number of elements in the update list
  * @param updates the list of updates to perform
+ * @return 0 or an error code
  */
 GIT_EXTERN(int) git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseline, size_t nupdates, const git_tree_update *updates);
 
diff --git a/src/odb.c b/src/odb.c
index 1b91434..7625ce6 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -297,14 +297,15 @@ int git_odb__hashlink(git_oid *out, const char *path)
 		GIT_ERROR_CHECK_ALLOC(link_data);
 
 		read_len = p_readlink(path, link_data, size);
-		link_data[size] = '\0';
-		if (read_len != size) {
+		if (read_len == -1) {
 			git_error_set(GIT_ERROR_OS, "failed to read symlink data for '%s'", path);
 			git__free(link_data);
 			return -1;
 		}
+		GIT_ASSERT(read_len <= size);
+		link_data[read_len] = '\0';
 
-		result = git_odb_hash(out, link_data, size, GIT_OBJECT_BLOB);
+		result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB);
 		git__free(link_data);
 	} else {
 		int fd = git_futils_open_ro(path);
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 97ceab2..d21c506 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -52,6 +52,10 @@
 # define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_3 0x00002000
 #endif
 
+#ifndef WINHTTP_NO_CLIENT_CERT_CONTEXT
+# define WINHTTP_NO_CLIENT_CERT_CONTEXT NULL
+#endif
+
 #ifndef HTTP_STATUS_PERMANENT_REDIRECT
 # define HTTP_STATUS_PERMANENT_REDIRECT 308
 #endif