From: Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
Subject: [PATCH] Relax dependency to glib 2.24

Manually declare gitg_encoding_get_type (G_DEFINE_BOXED_TYPE was
introduced in glib 2.26).

Manually declare G_TYPE_ERROR (was introduced in glib 2.26).

Include explicitly unistd.h in tools/gitg-shell.c. Not sure if it is
related to glib 2.26 or not, but missing here.

Signed-off-by: Guilhem Bonnefille <guilhem.bonnefille@gmail.com>

---
 configure.ac               |    4 +++-
 libgitg/Makefile.am        |    2 ++
 libgitg/gitg-encodings.c   |   21 +++++++++++++++++++++
 libgitg/gitg-io.c          |    2 ++
 libgitg/gitg-line-parser.c |    2 ++
 libgitg/glib-compat.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 libgitg/glib-compat.h      |   42 ++++++++++++++++++++++++++++++++++++++++++
 tools/gitg-shell.c         |    4 ++++
 8 files changed, 118 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index 86cb61f..395a5da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,6 +48,8 @@ GETTEXT_PACKAGE=gitg
 AC_SUBST(GETTEXT_PACKAGE)
 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
 
+AC_HEADER_STDC
+AC_CHECK_HEADERS([unistd.h])
 
 AC_CHECK_LIB([m], [sinf])
 
@@ -64,7 +66,7 @@ PKG_CHECK_EXISTS([gtk+-3.0 >= 2.90],
 			GTKSOURCEVIEW_REQUIRED_VERSION=2.8.0
 		 ])
 
-GLIB_REQUIRED_VERSION=2.26
+GLIB_REQUIRED_VERSION=2.24
 
 PKG_CHECK_MODULES(GITG, [
 	$GTK_REQUIRED >= $GTK_REQUIRED_VERSION
diff --git a/libgitg/Makefile.am b/libgitg/Makefile.am
index a6f6572..e96cf36 100644
--- a/libgitg/Makefile.am
+++ b/libgitg/Makefile.am
@@ -37,6 +37,7 @@ INST_H_FILES =			\
 	gitg-line-parser.h
 
 NOINST_H_FILES =			\
+	glib-compat.h			\
 	gitg-convert.h			\
 	gitg-debug.h			\
 	gitg-i18n.h			\
@@ -46,6 +47,7 @@ NOINST_H_FILES =			\
 
 C_FILES =				\
 	$(BUILT_SOURCES)		\
+	glib-compat.c			\
 	gitg-changed-file.c		\
 	gitg-color.c			\
 	gitg-commit.c			\
diff --git a/libgitg/gitg-encodings.c b/libgitg/gitg-encodings.c
index 48c8988..b190406 100644
--- a/libgitg/gitg-encodings.c
+++ b/libgitg/gitg-encodings.c
@@ -48,10 +48,31 @@ struct _GitgEncoding
 	const gchar *name;
 };
 
+#if GLIB_CHECK_VERSION(2, 26, 0)
+
 G_DEFINE_BOXED_TYPE (GitgEncoding, gitg_encoding,
                      gitg_encoding_copy,
                      gitg_encoding_free)
 
+#else
+
+GType
+gitg_encoding_get_type (void)
+{
+	static GType our_type = 0;
+
+	if (!our_type)
+	{
+		our_type = g_boxed_type_register_static ("GitgEncoding",
+		                                         (GBoxedCopyFunc)gitg_encoding_copy,
+		                                         (GBoxedFreeFunc)gitg_encoding_free);
+	}
+
+	return our_type;
+}
+
+#endif
+
 /* 
  * The original versions of the following tables are taken from profterm 
  *
diff --git a/libgitg/gitg-io.c b/libgitg/gitg-io.c
index d0d1972..75771db 100644
--- a/libgitg/gitg-io.c
+++ b/libgitg/gitg-io.c
@@ -22,6 +22,8 @@
 
 #include "gitg-io.h"
 
+#include "glib-compat.h"
+
 #define GITG_IO_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GITG_TYPE_IO, GitgIOPrivate))
 
 struct _GitgIOPrivate
diff --git a/libgitg/gitg-line-parser.c b/libgitg/gitg-line-parser.c
index 155a203..392c287 100644
--- a/libgitg/gitg-line-parser.c
+++ b/libgitg/gitg-line-parser.c
@@ -22,6 +22,8 @@
 
 #include "gitg-line-parser.h"
 
+#include "glib-compat.h"
+
 #define GITG_LINE_PARSER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GITG_TYPE_LINE_PARSER, GitgLineParserPrivate))
 
 struct _GitgLineParserPrivate
diff --git a/libgitg/glib-compat.c b/libgitg/glib-compat.c
new file mode 100644
index 0000000..5d352ac
--- /dev/null
+++ b/libgitg/glib-compat.c
@@ -0,0 +1,42 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ *  Copyright (C) 2007 Sebastien Granjoux  <seb.sfo@free.fr>
+ *                2010 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ *  This runtime is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This runtime is distributed in the hope runtime it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this runtime; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "glib-compat.h"
+
+#if !GLIB_CHECK_VERSION (2, 26, 0)
+
+GType
+g_error_get_type (void)
+{
+        static GType type = G_TYPE_INVALID;
+
+        if (type == G_TYPE_INVALID)
+        {
+                type = g_boxed_type_register_static ("GError",
+                                (GBoxedCopyFunc) g_error_copy,
+                                (GBoxedFreeFunc) g_error_free);
+        }
+
+        return type;
+}
+
+#endif /* GLIB < 2.26.0 */
+
+/* ex:ts=8:noet: */
diff --git a/libgitg/glib-compat.h b/libgitg/glib-compat.h
new file mode 100644
index 0000000..0607981
--- /dev/null
+++ b/libgitg/glib-compat.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+/*
+ *  Copyright (C) 2007 Sebastien Granjoux  <seb.sfo@free.fr>
+ *                2010 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ *  This runtime is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This runtime is distributed in the hope runtime it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this runtime; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLIB_COMPAT_H
+#define GLIB_COMPAT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#if !GLIB_CHECK_VERSION (2, 26, 0)
+
+#ifndef G_TYPE_ERROR
+#define G_TYPE_ERROR            (g_error_get_type())
+#define NEED_G_ERROR_GET_TYPE
+GType g_error_get_type (void) G_GNUC_CONST;
+#endif /* G_TYPE_ERROR */
+
+#endif /* GLIB < 2.26.0 */
+
+G_END_DECLS
+
+#endif /* GLIB_COMPAT_H */
+
+/* ex:ts=8:noet: */
diff --git a/tools/gitg-shell.c b/tools/gitg-shell.c
index 16ae312..9f487c8 100644
--- a/tools/gitg-shell.c
+++ b/tools/gitg-shell.c
@@ -1,3 +1,7 @@
+#include "config.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 #include <glib.h>
 #include <stdlib.h>
 #include <libgitg/gitg-shell.h>
-- 
tg: (885cfe8..) t/fix/glib-2.24 (depends on: master)
