[libgit2-glib] Bind git_diff_similarity_metric



commit b2c54a8604f859e7c788bead3aad484065dd86c7
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sat Jul 6 14:09:32 2013 +0200

    Bind git_diff_similarity_metric

 libgit2-glib/Makefile.am                   |    2 +
 libgit2-glib/ggit-diff-similarity-metric.c |  182 ++++++++++++++++++++++++++++
 libgit2-glib/ggit-diff-similarity-metric.h |   53 ++++++++
 libgit2-glib/ggit-types.h                  |   30 +++++
 4 files changed, 267 insertions(+), 0 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 3259faa..fa3341d 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -33,6 +33,7 @@ INST_H_FILES =                                \
        ggit-diff-options.h             \
        ggit-diff-patch.h               \
        ggit-diff-range.h               \
+       ggit-diff-similarity-metric.h   \
        ggit-error.h                    \
        ggit-index.h                    \
        ggit-index-entry.h              \
@@ -85,6 +86,7 @@ C_FILES =                             \
        ggit-diff-options.c             \
        ggit-diff-patch.c               \
        ggit-diff-range.c               \
+       ggit-diff-similarity-metric.c   \
        ggit-error.c                    \
        ggit-index.c                    \
        ggit-index-entry.c              \
diff --git a/libgit2-glib/ggit-diff-similarity-metric.c b/libgit2-glib/ggit-diff-similarity-metric.c
new file mode 100644
index 0000000..975b6a5
--- /dev/null
+++ b/libgit2-glib/ggit-diff-similarity-metric.c
@@ -0,0 +1,182 @@
+/*
+ * ggit-diff-similarity-metric.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib 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 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that 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 libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "ggit-diff-similarity-metric.h"
+#include "ggit-diff-file.h"
+
+
+struct _GgitDiffSimilarityMetric
+{
+       git_diff_similarity_metric metric;
+       GgitDiffSimilarityMetricFileSignatureCallback file_signature;
+       GgitDiffSimilarityMetricBufferSignatureCallback buffer_signature;
+       GgitDiffSimilarityMetricFreeSignatureCallback free_signature;
+       GgitDiffSimilarityMetricSimilarityCallback similarity;
+       gpointer user_data;
+};
+
+G_DEFINE_BOXED_TYPE (GgitDiffSimilarityMetric, ggit_diff_similarity_metric,
+                     ggit_diff_similarity_metric_copy, ggit_diff_similarity_metric_free)
+
+const git_diff_similarity_metric *
+_ggit_diff_similarity_metric_get_similarity_metric (GgitDiffSimilarityMetric *metric)
+{
+       if (metric == NULL)
+       {
+               return NULL;
+       }
+
+       return (const git_diff_similarity_metric *)&metric->metric;
+}
+
+/**
+ * ggit_diff_similarity_metric_copy:
+ * @metric: a #GgitDiffSimilarityMetric.
+ *
+ * Copies @metric into a newly allocated #GgitDiffSimilarityMetric.
+ *
+ * Returns: (transfer full): a newly allocated #GgitDiffSimilarityMetric.
+ */
+GgitDiffSimilarityMetric *
+ggit_diff_similarity_metric_copy (GgitDiffSimilarityMetric *metric)
+{
+       GgitDiffSimilarityMetric *copy;
+
+       g_return_val_if_fail (metric != NULL, NULL);
+
+       copy = g_slice_new (GgitDiffSimilarityMetric);
+       copy->metric = metric->metric;
+       copy->file_signature = metric->file_signature;
+       copy->buffer_signature = metric->buffer_signature;
+       copy->free_signature = metric->free_signature;
+       copy->similarity = metric->similarity;
+       copy->user_data = metric->user_data;
+
+       return copy;
+}
+
+/**
+ * ggit_diff_similarity_metric_free:
+ * @metric: a #GgitDiffSimilarityMetric.
+ *
+ * Frees @metric.
+ */
+void
+ggit_diff_similarity_metric_free (GgitDiffSimilarityMetric *metric)
+{
+       g_return_if_fail (metric != NULL);
+
+       g_slice_free (GgitDiffSimilarityMetric, metric);
+}
+
+static int
+ggit_diff_similarity_metric_file_signature (gpointer            *out,
+                                            const git_diff_file *file,
+                                            const gchar         *fullpath,
+                                            gpointer             payload)
+{
+       GgitDiffSimilarityMetric *metric = (GgitDiffSimilarityMetric *)payload;
+       gint ret;
+       GgitDiffFile *diff_file;
+
+       diff_file = _ggit_diff_file_wrap (file);
+       ret = metric->file_signature (diff_file, fullpath, out, metric->user_data);
+       ggit_diff_file_unref (diff_file);
+
+       return ret;
+}
+
+static int
+ggit_diff_similarity_metric_buffer_signature (gpointer            *out,
+                                              const git_diff_file *file,
+                                              const gchar         *buf,
+                                              gsize                buflen,
+                                              gpointer             payload)
+{
+       GgitDiffSimilarityMetric *metric = (GgitDiffSimilarityMetric *)payload;
+       gint ret;
+       GgitDiffFile *diff_file;
+
+       diff_file = _ggit_diff_file_wrap (file);
+       ret = metric->buffer_signature (diff_file, buf, buflen, out, metric->user_data);
+       ggit_diff_file_unref (diff_file);
+
+       return ret;
+}
+
+static void
+ggit_diff_similarity_metric_free_signature (gpointer signature,
+                                            gpointer payload)
+{
+       GgitDiffSimilarityMetric *metric = (GgitDiffSimilarityMetric *)payload;
+
+       metric->free_signature (signature, metric->user_data);
+}
+
+static int
+ggit_diff_similarity_metric_similarity (gint     *score,
+                                        gpointer  signature_a,
+                                        gpointer  signature_b,
+                                        gpointer  payload)
+{
+       GgitDiffSimilarityMetric *metric = (GgitDiffSimilarityMetric *)payload;
+
+       return metric->similarity (score, signature_a, signature_b, metric->user_data);
+}
+
+/**
+ * ggit_diff_similarity_metric_new:
+ * @file_signature: (scope call): a #GgitDiffSimilarityMetricFileSignature.
+ * @buffer_signature: (scope call): a #GgitDiffSimilarityMetricBufferSignature.
+ * @free_signature: (scope call): a #GgitDiffSimilarityMetricFreeSignature.
+ * @similarity: (scope call): a #GgitDiffSimilarityMetricSimilarity.
+ * @user_data: passed as user_data to the previous parameters.
+ *
+ * Creates a new #GgitDiffSimilarityMetric.
+ *
+ * Returns: a newly allocated #GgitDiffSimilarityMetric.
+ */
+GgitDiffSimilarityMetric *
+ggit_diff_similarity_metric_new (GgitDiffSimilarityMetricFileSignatureCallback   file_signature,
+                                 GgitDiffSimilarityMetricBufferSignatureCallback buffer_signature,
+                                 GgitDiffSimilarityMetricFreeSignatureCallback   free_signature,
+                                 GgitDiffSimilarityMetricSimilarityCallback      similarity,
+                                 gpointer                                        user_data)
+{
+       GgitDiffSimilarityMetric *metric;
+
+       metric = g_slice_new (GgitDiffSimilarityMetric);
+       metric->file_signature = file_signature;
+       metric->buffer_signature = buffer_signature;
+       metric->free_signature = free_signature;
+       metric->similarity = similarity;
+       metric->user_data = user_data;
+
+       metric->metric.file_signature = ggit_diff_similarity_metric_file_signature;
+       metric->metric.buffer_signature = ggit_diff_similarity_metric_buffer_signature;
+       metric->metric.free_signature = ggit_diff_similarity_metric_free_signature;
+       metric->metric.similarity = ggit_diff_similarity_metric_similarity;
+       metric->metric.payload = (void *)metric;
+
+       return metric;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-diff-similarity-metric.h b/libgit2-glib/ggit-diff-similarity-metric.h
new file mode 100644
index 0000000..1a11977
--- /dev/null
+++ b/libgit2-glib/ggit-diff-similarity-metric.h
@@ -0,0 +1,53 @@
+/*
+ * ggit-diff-similarity-metric.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib 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 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib is distributed in the hope that 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 libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GGIT_DIFF_SIMILARITY_METRIC_H__
+#define __GGIT_DIFF_SIMILARITY_METRIC_H__
+
+#include <glib-object.h>
+#include <git2.h>
+
+#include "ggit-types.h"
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_DIFF_SIMILARITY_METRIC       (ggit_diff_similarity_metric_get_type ())
+#define GGIT_DIFF_SIMILARITY_METRIC(obj)       ((GgitDiffSimilarityMetric *)obj)
+
+GType                      ggit_diff_similarity_metric_get_type                (void) G_GNUC_CONST;
+
+const git_diff_similarity_metric *
+                          _ggit_diff_similarity_metric_get_similarity_metric   (GgitDiffSimilarityMetric   
*metric);
+
+GgitDiffSimilarityMetric  *ggit_diff_similarity_metric_copy                    (GgitDiffSimilarityMetric   
*metric);
+void                       ggit_diff_similarity_metric_free                    (GgitDiffSimilarityMetric   
*metric);
+
+GgitDiffSimilarityMetric  *ggit_diff_similarity_metric_new                     
(GgitDiffSimilarityMetricFileSignatureCallback   file_signature,
+                                                                                
GgitDiffSimilarityMetricBufferSignatureCallback buffer_signature,
+                                                                                
GgitDiffSimilarityMetricFreeSignatureCallback   free_signature,
+                                                                                
GgitDiffSimilarityMetricSimilarityCallback      similarity,
+                                                                                gpointer                     
                   user_data);
+
+G_END_DECLS
+
+#endif /* __GGIT_DIFF_SIMILARITY_METRIC_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 85e0d83..7f29a8d 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -138,6 +138,13 @@ typedef struct _GgitDiffOptions GgitDiffOptions;
 typedef struct _GgitDiffRange GgitDiffRange;
 
 /**
+ * GgitDiffSimilarityMetric:
+ *
+ * Represents a similarity metric.
+ */
+typedef struct _GgitDiffSimilarityMetric GgitDiffSimilarityMetric;
+
+/**
  * GgitIndex:
  *
  * Represents an index object.
@@ -916,6 +923,29 @@ typedef gint (* GgitDiffLineCallback) (GgitDiffDelta    *delta,
                                        gsize             content_len,
                                        gpointer          user_data);
 
+/*
+ * FIXME: request docs for this to libgit2
+ */
+typedef gint (* GgitDiffSimilarityMetricFileSignatureCallback) (GgitDiffFile *file,
+                                                                const gchar  *fullpath,
+                                                                gpointer     *out,
+                                                                gpointer      user_data);
+
+
+typedef gint (* GgitDiffSimilarityMetricBufferSignatureCallback) (GgitDiffFile *file,
+                                                                  const gchar  *buf,
+                                                                  gsize         buflen,
+                                                                  gpointer     *out,
+                                                                  gpointer      user_data);
+
+typedef void (* GgitDiffSimilarityMetricFreeSignatureCallback) (gpointer signature,
+                                                                gpointer user_data);
+
+typedef gint (* GgitDiffSimilarityMetricSimilarityCallback) (gint     *score,
+                                                             gpointer  signature_a,
+                                                             gpointer  signature_b,
+                                                             gpointer  user_data);
+
 /**
  * GgitReferencesNameCallback:
  * @name: the name of the reference



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]