]> git.ipfire.org Git - thirdparty/git.git/commitdiff
version: extend get_uname_info() to hide system details
authorUsman Akinyemi <usmanakinyemi202@gmail.com>
Sat, 15 Feb 2025 15:50:50 +0000 (21:20 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Feb 2025 17:05:12 +0000 (09:05 -0800)
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>
builtin/bugreport.c
version.c
version.h

index 5e13d532a8565d93158bebadcc95cecb7554c77d..e3288a86c8eae81ce283bbd0314d2e054ab43c56 100644 (file)
@@ -24,7 +24,7 @@ static void get_system_info(struct strbuf *sys_info)
 
        /* system call for other version info */
        strbuf_addstr(sys_info, "uname: ");
-       get_uname_info(sys_info);
+       get_uname_info(sys_info, 1);
 
        strbuf_addstr(sys_info, _("compiler info: "));
        get_compiler_info(sys_info);
index 3ec8b8243d6cae258e4abb4c03773eef9e8cfb52..d95221a72a6d6397ec30c5575c10a1d5f9cecf16 100644 (file)
--- a/version.c
+++ b/version.c
@@ -49,7 +49,7 @@ const char *git_user_agent_sanitized(void)
        return agent;
 }
 
-int get_uname_info(struct strbuf *buf)
+int get_uname_info(struct strbuf *buf, unsigned int full)
 {
        struct utsname uname_info;
 
@@ -59,11 +59,13 @@ int get_uname_info(struct strbuf *buf)
                            errno);
                return -1;
        }
-
-       strbuf_addf(buf, "%s %s %s %s\n",
-                   uname_info.sysname,
-                   uname_info.release,
-                   uname_info.version,
-                   uname_info.machine);
+       if (full)
+               strbuf_addf(buf, "%s %s %s %s\n",
+                           uname_info.sysname,
+                           uname_info.release,
+                           uname_info.version,
+                           uname_info.machine);
+       else
+            strbuf_addf(buf, "%s\n", uname_info.sysname);
        return 0;
 }
index afe3dbbab74ae76420359c81db5439aeaea82a2b..5eb586c0bdd25c05ac89af12ce010838497b7964 100644 (file)
--- a/version.h
+++ b/version.h
@@ -12,6 +12,6 @@ const char *git_user_agent_sanitized(void);
   Return -1 and put an error message into 'buf' in case of uname()
   error. Return 0 and put uname info into 'buf' otherwise.
 */
-int get_uname_info(struct strbuf *buf);
+int get_uname_info(struct strbuf *buf, unsigned int full);
 
 #endif /* VERSION_H */