[gnome-builder] context: emit ::log per line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] context: emit ::log per line
- Date: Tue, 9 Jan 2018 02:16:13 +0000 (UTC)
commit 71615646e2f75ffbc731235c67dfdd3cbce12bf0
Author: Christian Hergert <chergert redhat com>
Date: Mon Jan 8 18:14:56 2018 -0800
context: emit ::log per line
This simplifies handlers by ensuring we emit ::log on a per-line basis.
src/libide/ide-context.c | 21 ++++++++++++++++++++-
1 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/src/libide/ide-context.c b/src/libide/ide-context.c
index 0126370..0d1cfd6 100644
--- a/src/libide/ide-context.c
+++ b/src/libide/ide-context.c
@@ -56,6 +56,7 @@
#include "testing/ide-test-manager.h"
#include "transfers/ide-transfer-manager.h"
#include "util/ide-async-helper.h"
+#include "util/ide-line-reader.h"
#include "util/ide-settings.h"
#include "vcs/ide-vcs.h"
#include "vcs/ide-vcs-monitor.h"
@@ -183,6 +184,9 @@ ide_context_log_observer (IdeBuildLogStream log_stream,
{
IdeContext *self = user_data;
GLogLevelFlags flags;
+ IdeLineReader reader;
+ const gchar *str;
+ gsize len;
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (IDE_IS_CONTEXT (self));
@@ -192,7 +196,22 @@ ide_context_log_observer (IdeBuildLogStream log_stream,
flags = log_stream == IDE_BUILD_LOG_STDOUT ? G_LOG_LEVEL_MESSAGE
: G_LOG_LEVEL_WARNING;
- g_signal_emit (self, signals [LOG], 0, flags, message);
+ ide_line_reader_init (&reader, (gchar *)message, message_len);
+
+ while (NULL != (str = ide_line_reader_next (&reader, &len)))
+ {
+ g_autofree gchar *copy = NULL;
+
+ /* Most of the time, we'll only have a single line, so we
+ * don't need to copy the string to get a single line emitted
+ * to the ::log signal.
+ */
+
+ if G_UNLIKELY (str[len] != '\0')
+ str = copy = g_strndup (str, len);
+
+ g_signal_emit (self, signals [LOG], 0, flags, str);
+ }
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]