Skip to content

Commit 6aa09fd

Browse files
Unique-Usmangitster
authored andcommitted
version: extend get_uname_info() to hide system details
Currently, get_uname_info() function provides the full OS information. In a following commit, we will need it to provide only the OS name. Let's extend it to accept a "full" flag that makes it switch between providing full OS information and providing only the OS name. We may need to refactor this function in the future if an `osVersion.format` is added. Mentored-by: Christian Couder <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a78d61 commit 6aa09fd

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

builtin/bugreport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void get_system_info(struct strbuf *sys_info)
2424

2525
/* system call for other version info */
2626
strbuf_addstr(sys_info, "uname: ");
27-
get_uname_info(sys_info);
27+
get_uname_info(sys_info, 1);
2828

2929
strbuf_addstr(sys_info, _("compiler info: "));
3030
get_compiler_info(sys_info);

version.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const char *git_user_agent_sanitized(void)
4949
return agent;
5050
}
5151

52-
int get_uname_info(struct strbuf *buf)
52+
int get_uname_info(struct strbuf *buf, unsigned int full)
5353
{
5454
struct utsname uname_info;
5555

@@ -59,11 +59,13 @@ int get_uname_info(struct strbuf *buf)
5959
errno);
6060
return -1;
6161
}
62-
63-
strbuf_addf(buf, "%s %s %s %s\n",
64-
uname_info.sysname,
65-
uname_info.release,
66-
uname_info.version,
67-
uname_info.machine);
62+
if (full)
63+
strbuf_addf(buf, "%s %s %s %s\n",
64+
uname_info.sysname,
65+
uname_info.release,
66+
uname_info.version,
67+
uname_info.machine);
68+
else
69+
strbuf_addf(buf, "%s\n", uname_info.sysname);
6870
return 0;
6971
}

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ const char *git_user_agent_sanitized(void);
1212
Return -1 and put an error message into 'buf' in case of uname()
1313
error. Return 0 and put uname info into 'buf' otherwise.
1414
*/
15-
int get_uname_info(struct strbuf *buf);
15+
int get_uname_info(struct strbuf *buf, unsigned int full);
1616

1717
#endif /* VERSION_H */

0 commit comments

Comments
 (0)