File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,39 @@ void git_net_url_swap(git_net_url *a, git_net_url *b)
348348 memcpy (b , & tmp , sizeof (git_net_url ));
349349}
350350
351+ int git_net_url_fmt (git_buf * buf , git_net_url * url )
352+ {
353+ git_buf_puts (buf , url -> scheme );
354+ git_buf_puts (buf , "://" );
355+
356+ if (url -> username ) {
357+ git_buf_puts (buf , url -> username );
358+
359+ if (url -> password ) {
360+ git_buf_puts (buf , ":" );
361+ git_buf_puts (buf , url -> password );
362+ }
363+
364+ git_buf_putc (buf , '@' );
365+ }
366+
367+ git_buf_puts (buf , url -> host );
368+
369+ if (url -> port && !git_net_url_is_default_port (url )) {
370+ git_buf_putc (buf , ':' );
371+ git_buf_puts (buf , url -> port );
372+ }
373+
374+ git_buf_puts (buf , url -> path ? url -> path : "/" );
375+
376+ if (url -> query ) {
377+ git_buf_putc (buf , '?' );
378+ git_buf_puts (buf , url -> query );
379+ }
380+
381+ return git_buf_oom (buf ) ? -1 : 0 ;
382+ }
383+
351384void git_net_url_dispose (git_net_url * url )
352385{
353386 if (url -> username )
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ extern int git_net_url_apply_redirect(
4545/** Swaps the contents of one URL for another. */
4646extern void git_net_url_swap (git_net_url * a , git_net_url * b );
4747
48+ /** Places the URL into the given buffer. */
49+ extern int git_net_url_fmt (git_buf * out , git_net_url * url );
50+
4851/** Disposes the contents of the structure. */
4952extern void git_net_url_dispose (git_net_url * url );
5053
You can’t perform that action at this time.
0 commit comments