Skip to content

Commit 0b8358c

Browse files
committed
net: introduce path formatting function
Introduce a function to format the path and query string for a URL, suitable for creating an HTTP request.
1 parent 1152f36 commit 0b8358c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/net.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,18 @@ int git_net_url_fmt(git_buf *buf, git_net_url *url)
381381
return git_buf_oom(buf) ? -1 : 0;
382382
}
383383

384+
int git_net_url_fmt_path(git_buf *buf, git_net_url *url)
385+
{
386+
git_buf_puts(buf, url->path ? url->path : "/");
387+
388+
if (url->query) {
389+
git_buf_putc(buf, '?');
390+
git_buf_puts(buf, url->query);
391+
}
392+
393+
return git_buf_oom(buf) ? -1 : 0;
394+
}
395+
384396
void git_net_url_dispose(git_net_url *url)
385397
{
386398
if (url->username)

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ extern void git_net_url_swap(git_net_url *a, git_net_url *b);
4848
/** Places the URL into the given buffer. */
4949
extern int git_net_url_fmt(git_buf *out, git_net_url *url);
5050

51+
/** Place the path and query string into the given buffer. */
52+
extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url);
53+
5154
/** Disposes the contents of the structure. */
5255
extern void git_net_url_dispose(git_net_url *url);
5356

0 commit comments

Comments
 (0)