Skip to content

Commit c18a2bc

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#3851 from txdv/get-user-agent
Add get user agent functionality.
2 parents b57c176 + f1dba14 commit c18a2bc

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ v0.24 + 1
1212

1313
### API additions
1414

15+
* You can now get the user-agent used by libgit2 using the
16+
`GIT_OPT_GET_USER_AGENT` option with `git_libgit2_opts()`.
17+
It is the counterpart to `GIT_OPT_SET_USER_AGENT`.
18+
1519
* `git_commit_create_buffer()` creates a commit and writes it into a
1620
user-provided buffer instead of writing it into the object db.
1721

include/git2/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ typedef enum {
158158
GIT_OPT_SET_USER_AGENT,
159159
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
160160
GIT_OPT_SET_SSL_CIPHERS,
161+
GIT_OPT_GET_USER_AGENT,
161162
} git_libgit2_opt_t;
162163

163164
/**

src/settings.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ int git_libgit2_opts(int key, ...)
209209
#endif
210210
break;
211211

212+
case GIT_OPT_GET_USER_AGENT:
213+
{
214+
git_buf *out = va_arg(ap, git_buf *);
215+
git_buf_sanitize(out);
216+
error = git_buf_sets(out, git__user_agent);
217+
}
218+
break;
219+
212220
default:
213221
giterr_set(GITERR_INVALID, "invalid option key");
214222
error = -1;

tests/core/useragent.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
void test_core_useragent__get(void)
55
{
66
const char *custom_name = "super duper git";
7+
git_buf buf = GIT_BUF_INIT;
78

89
cl_assert_equal_p(NULL, git_libgit2__user_agent());
910
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_USER_AGENT, custom_name));
1011
cl_assert_equal_s(custom_name, git_libgit2__user_agent());
12+
13+
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_USER_AGENT, &buf));
14+
cl_assert_equal_s(custom_name, buf.ptr);
15+
16+
git_buf_free(&buf);
1117
}

0 commit comments

Comments
 (0)