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 <chriscool@tuxfamily.org> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Usman Akinyemi committed Feb 15, 2025 at 21:20 UTC 6aa09fd8726b7e8de37c0187a83c2c0fca280358
3 files changed +11 -9
builtin/bugreport.c
+1 -1
@@ -24,7 +24,7 @@ static void get_system_info(struct strbuf *sys_info)
24
25 /* system call for other version info */
26 strbuf_addstr(sys_info, "uname: ");
27 - get_uname_info(sys_info);
27 + get_uname_info(sys_info, 1);
28
29 strbuf_addstr(sys_info, _("compiler info: "));
30 get_compiler_info(sys_info);
version.c
+9 -7
@@ -49,7 +49,7 @@ const char *git_user_agent_sanitized(void)
49 return agent;
50 }
51
52 -int get_uname_info(struct strbuf *buf)
52 +int get_uname_info(struct strbuf *buf, unsigned int full)
53 {
54 struct utsname uname_info;
55
@@ -59,11 +59,13 @@ int get_uname_info(struct strbuf *buf)
59 errno);
60 return -1;
61 }
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);
70 return 0;
71 }
version.h
+1 -1
@@ -12,6 +12,6 @@ const char *git_user_agent_sanitized(void);
12 Return -1 and put an error message into 'buf' in case of uname()
13 error. Return 0 and put uname info into 'buf' otherwise.
14 */
15 -int get_uname_info(struct strbuf *buf);
15 +int get_uname_info(struct strbuf *buf, unsigned int full);
16
17 #endif /* VERSION_H */