]> git.ipfire.org Git - thirdparty/git.git/blobdiff - bugreport.c
http: refactor finish_http_pack_request()
[thirdparty/git.git] / bugreport.c
index f6f53a5e8e486f6001e394b3604ace1b999280df..aa8a489c35e8f48799e6e3e3d39e585724c89c3d 100644 (file)
@@ -1,8 +1,84 @@
-#include "builtin.h"
+#include "cache.h"
 #include "parse-options.h"
-#include "stdio.h"
 #include "strbuf.h"
-#include "time.h"
+#include "help.h"
+#include "compat/compiler.h"
+#include "run-command.h"
+
+
+static void get_system_info(struct strbuf *sys_info)
+{
+       struct utsname uname_info;
+
+       /* get git version from native cmd */
+       strbuf_addstr(sys_info, _("git version:\n"));
+       get_version_info(sys_info, 1);
+
+       /* system call for other version info */
+       strbuf_addstr(sys_info, "uname: ");
+       if (uname(&uname_info))
+               strbuf_addf(sys_info, _("uname() failed with error '%s' (%d)\n"),
+                           strerror(errno),
+                           errno);
+       else
+               strbuf_addf(sys_info, "%s %s %s %s\n",
+                           uname_info.sysname,
+                           uname_info.release,
+                           uname_info.version,
+                           uname_info.machine);
+
+       strbuf_addstr(sys_info, _("compiler info: "));
+       get_compiler_info(sys_info);
+       strbuf_addstr(sys_info, _("libc info: "));
+       get_libc_info(sys_info);
+}
+
+static void get_populated_hooks(struct strbuf *hook_info, int nongit)
+{
+       /*
+        * NEEDSWORK: Doesn't look like there is a list of all possible hooks;
+        * so below is a transcription of `git help hooks`. Later, this should
+        * be replaced with some programmatically generated list (generated from
+        * doc or else taken from some library which tells us about all the
+        * hooks)
+        */
+       static const char *hook[] = {
+               "applypatch-msg",
+               "pre-applypatch",
+               "post-applypatch",
+               "pre-commit",
+               "pre-merge-commit",
+               "prepare-commit-msg",
+               "commit-msg",
+               "post-commit",
+               "pre-rebase",
+               "post-checkout",
+               "post-merge",
+               "pre-push",
+               "pre-receive",
+               "update",
+               "post-receive",
+               "post-update",
+               "push-to-checkout",
+               "pre-auto-gc",
+               "post-rewrite",
+               "sendemail-validate",
+               "fsmonitor-watchman",
+               "p4-pre-submit",
+               "post-index-change",
+       };
+       int i;
+
+       if (nongit) {
+               strbuf_addstr(hook_info,
+                       _("not run from a git repository - no hooks to show\n"));
+               return;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(hook); i++)
+               if (find_hook(hook[i]))
+                       strbuf_addf(hook_info, "%s\n", hook[i]);
+}
 
 static const char * const bugreport_usage[] = {
        N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
@@ -32,6 +108,11 @@ static int get_bug_template(struct strbuf *template)
        return 0;
 }
 
+static void get_header(struct strbuf *buf, const char *title)
+{
+       strbuf_addf(buf, "\n\n[%s]\n", title);
+}
+
 int cmd_main(int argc, const char **argv)
 {
        struct strbuf buffer = STRBUF_INIT;
@@ -79,6 +160,12 @@ int cmd_main(int argc, const char **argv)
        /* Prepare the report contents */
        get_bug_template(&buffer);
 
+       get_header(&buffer, _("System Info"));
+       get_system_info(&buffer);
+
+       get_header(&buffer, _("Enabled Hooks"));
+       get_populated_hooks(&buffer, nongit_ok);
+
        /* fopen doesn't offer us an O_EXCL alternative, except with glibc. */
        report = open(report_path.buf, O_CREAT | O_EXCL | O_WRONLY, 0666);