Logo Search packages:      
Sourcecode: valatoys version File versions  Download package

vtgvcsbackendsgit.c

/* vtgvcsbackendsgit.c generated by valac 0.10.0, the Vala compiler
 * generated from vtgvcsbackendsgit.vala, do not modify */

/*
 *  vtgvcsbackendsgit.vala - Vala developer toys for GEdit
 *  
 *  Copyright (C) 2008 - Andrea Del Signore <sejerpz@tin.it>
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *   
 *  This program 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 General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330,
 *  Boston, MA 02111-1307, USA.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <valagee.h>
#include <sys/wait.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>


#define VTG_VCS_BACKENDS_TYPE_VCS_BASE (vtg_vcs_backends_vcs_base_get_type ())
#define VTG_VCS_BACKENDS_VCS_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_VCS_BACKENDS_TYPE_VCS_BASE, VtgVcsBackendsVcsBase))
#define VTG_VCS_BACKENDS_VCS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_VCS_BACKENDS_TYPE_VCS_BASE, VtgVcsBackendsVcsBaseClass))
#define VTG_VCS_BACKENDS_IS_VCS_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_VCS_BACKENDS_TYPE_VCS_BASE))
#define VTG_VCS_BACKENDS_IS_VCS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_VCS_BACKENDS_TYPE_VCS_BASE))
#define VTG_VCS_BACKENDS_VCS_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_VCS_BACKENDS_TYPE_VCS_BASE, VtgVcsBackendsVcsBaseClass))

typedef struct _VtgVcsBackendsVcsBase VtgVcsBackendsVcsBase;
typedef struct _VtgVcsBackendsVcsBaseClass VtgVcsBackendsVcsBaseClass;
typedef struct _VtgVcsBackendsVcsBasePrivate VtgVcsBackendsVcsBasePrivate;

#define VTG_VCS_BACKENDS_TYPE_ITEM (vtg_vcs_backends_item_get_type ())
#define VTG_VCS_BACKENDS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_VCS_BACKENDS_TYPE_ITEM, VtgVcsBackendsItem))
#define VTG_VCS_BACKENDS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_VCS_BACKENDS_TYPE_ITEM, VtgVcsBackendsItemClass))
#define VTG_VCS_BACKENDS_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_VCS_BACKENDS_TYPE_ITEM))
#define VTG_VCS_BACKENDS_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_VCS_BACKENDS_TYPE_ITEM))
#define VTG_VCS_BACKENDS_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_VCS_BACKENDS_TYPE_ITEM, VtgVcsBackendsItemClass))

typedef struct _VtgVcsBackendsItem VtgVcsBackendsItem;
typedef struct _VtgVcsBackendsItemClass VtgVcsBackendsItemClass;

#define VTG_VCS_BACKENDS_TYPE_GIT (vtg_vcs_backends_git_get_type ())
#define VTG_VCS_BACKENDS_GIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VTG_VCS_BACKENDS_TYPE_GIT, VtgVcsBackendsGit))
#define VTG_VCS_BACKENDS_GIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VTG_VCS_BACKENDS_TYPE_GIT, VtgVcsBackendsGitClass))
#define VTG_VCS_BACKENDS_IS_GIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VTG_VCS_BACKENDS_TYPE_GIT))
#define VTG_VCS_BACKENDS_IS_GIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VTG_VCS_BACKENDS_TYPE_GIT))
#define VTG_VCS_BACKENDS_GIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VTG_VCS_BACKENDS_TYPE_GIT, VtgVcsBackendsGitClass))

typedef struct _VtgVcsBackendsGit VtgVcsBackendsGit;
typedef struct _VtgVcsBackendsGitClass VtgVcsBackendsGitClass;
typedef struct _VtgVcsBackendsGitPrivate VtgVcsBackendsGitPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_collection_object_unref0(var) ((var == NULL) ? NULL : (var = (vala_collection_object_unref (var), NULL)))
typedef struct _VtgVcsBackendsItemPrivate VtgVcsBackendsItemPrivate;

#define VTG_VCS_BACKENDS_TYPE_STATES (vtg_vcs_backends_states_get_type ())
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_pattern_spec_free0(var) ((var == NULL) ? NULL : (var = (g_pattern_spec_free (var), NULL)))

struct _VtgVcsBackendsVcsBase {
      GObject parent_instance;
      VtgVcsBackendsVcsBasePrivate * priv;
};

struct _VtgVcsBackendsVcsBaseClass {
      GObjectClass parent_class;
      ValaList* (*get_items) (VtgVcsBackendsVcsBase* self, const char* path, GError** error);
      gboolean (*test) (VtgVcsBackendsVcsBase* self, const char* path);
};

00087 struct _VtgVcsBackendsGit {
      VtgVcsBackendsVcsBase parent_instance;
      VtgVcsBackendsGitPrivate * priv;
};

00092 struct _VtgVcsBackendsGitClass {
      VtgVcsBackendsVcsBaseClass parent_class;
};

typedef enum  {
      VTG_VCS_BACKENDS_VCS_ERROR_CommandFailed
} VtgVcsBackendsVcsError;
#define VTG_VCS_BACKENDS_VCS_ERROR vtg_vcs_backends_vcs_error_quark ()
typedef enum  {
      VTG_VCS_BACKENDS_STATES_UNTRACKED,
      VTG_VCS_BACKENDS_STATES_ADDED,
      VTG_VCS_BACKENDS_STATES_MODIFIED,
      VTG_VCS_BACKENDS_STATES_DELETED
} VtgVcsBackendsStates;

struct _VtgVcsBackendsItem {
      GObject parent_instance;
      VtgVcsBackendsItemPrivate * priv;
      char* name;
      VtgVcsBackendsStates state;
};

struct _VtgVcsBackendsItemClass {
      GObjectClass parent_class;
};


static gpointer vtg_vcs_backends_git_parent_class = NULL;
static GType vtg_vcs_backends_git_type_id = 0;

GType vtg_vcs_backends_vcs_base_get_type (void) G_GNUC_CONST;
GType vtg_vcs_backends_vcs_base_register_type (GTypeModule * module);
GType vtg_vcs_backends_item_get_type (void) G_GNUC_CONST;
GType vtg_vcs_backends_item_register_type (GTypeModule * module);
GType vtg_vcs_backends_git_get_type (void) G_GNUC_CONST;
GType vtg_vcs_backends_git_register_type (GTypeModule * module);
enum  {
      VTG_VCS_BACKENDS_GIT_DUMMY_PROPERTY
};
VtgVcsBackendsGit* vtg_vcs_backends_git_new (void);
VtgVcsBackendsGit* vtg_vcs_backends_git_construct (GType object_type);
VtgVcsBackendsVcsBase* vtg_vcs_backends_vcs_base_construct (GType object_type);
GQuark vtg_vcs_backends_vcs_error_quark (void);
static ValaList* vtg_vcs_backends_git_real_get_items (VtgVcsBackendsVcsBase* base, const char* path, GError** error);
VtgVcsBackendsItem* vtg_vcs_backends_item_new (void);
VtgVcsBackendsItem* vtg_vcs_backends_item_construct (GType object_type);
GType vtg_vcs_backends_states_get_type (void) G_GNUC_CONST;
static gboolean vtg_vcs_backends_git_real_test (VtgVcsBackendsVcsBase* base, const char* path);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);



VtgVcsBackendsGit* vtg_vcs_backends_git_construct (GType object_type) {
      VtgVcsBackendsGit * self;
      self = (VtgVcsBackendsGit*) vtg_vcs_backends_vcs_base_construct (object_type);
      return self;
}


VtgVcsBackendsGit* vtg_vcs_backends_git_new (void) {
      return vtg_vcs_backends_git_construct (VTG_VCS_BACKENDS_TYPE_GIT);
}


static char* string_replace (const char* self, const char* old, const char* replacement) {
      char* result = NULL;
      GError * _inner_error_ = NULL;
      g_return_val_if_fail (self != NULL, NULL);
      g_return_val_if_fail (old != NULL, NULL);
      g_return_val_if_fail (replacement != NULL, NULL);
      {
            char* _tmp0_;
            GRegex* _tmp1_;
            GRegex* regex;
            char* _tmp2_;
            regex = (_tmp1_ = g_regex_new (_tmp0_ = g_regex_escape_string (old, -1), 0, 0, &_inner_error_), _g_free0 (_tmp0_), _tmp1_);
            if (_inner_error_ != NULL) {
                  if (_inner_error_->domain == G_REGEX_ERROR) {
                        goto __catch39_g_regex_error;
                  }
                  g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
                  g_clear_error (&_inner_error_);
                  return NULL;
            }
            _tmp2_ = g_regex_replace_literal (regex, self, (gssize) (-1), 0, replacement, 0, &_inner_error_);
            if (_inner_error_ != NULL) {
                  _g_regex_unref0 (regex);
                  if (_inner_error_->domain == G_REGEX_ERROR) {
                        goto __catch39_g_regex_error;
                  }
                  _g_regex_unref0 (regex);
                  g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
                  g_clear_error (&_inner_error_);
                  return NULL;
            }
            result = _tmp2_;
            _g_regex_unref0 (regex);
            return result;
      }
      goto __finally39;
      __catch39_g_regex_error:
      {
            GError * e;
            e = _inner_error_;
            _inner_error_ = NULL;
            {
                  g_assert_not_reached ();
                  _g_error_free0 (e);
            }
      }
      __finally39:
      if (_inner_error_ != NULL) {
            g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
            g_clear_error (&_inner_error_);
            return NULL;
      }
}


static ValaList* vtg_vcs_backends_git_real_get_items (VtgVcsBackendsVcsBase* base, const char* path, GError** error) {
      VtgVcsBackendsGit * self;
      ValaList* result = NULL;
      ValaList* results;
      char* stdo;
      char* stde;
      gint exit_status = 0;
      char** _tmp0_ = NULL;
      char** _tmp1_;
      gint _tmp1__length1;
      char* _tmp2_ = NULL;
      gboolean _tmp3_;
      char* _tmp4_;
      char* _tmp5_ = NULL;
      gboolean _tmp6_;
      char* _tmp7_;
      gboolean _tmp8_;
      gboolean _tmp9_;
      GError * _inner_error_ = NULL;
      self = (VtgVcsBackendsGit*) base;
      g_return_val_if_fail (path != NULL, NULL);
      results = (ValaList*) vala_array_list_new (VTG_VCS_BACKENDS_TYPE_ITEM, (GBoxedCopyFunc) g_object_ref, g_object_unref, g_direct_equal);
      stdo = NULL;
      stde = NULL;
      _tmp9_ = (_tmp8_ = (_tmp6_ = (_tmp3_ = g_spawn_sync (path, (_tmp1_ = (_tmp0_ = g_new0 (char*, 2 + 1), _tmp0_[0] = g_strdup ("git"), _tmp0_[1] = g_strdup ("status"), _tmp0_), _tmp1__length1 = 2, _tmp1_), NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp2_, &_tmp5_, &exit_status, &_inner_error_), stdo = (_tmp4_ = _tmp2_, _g_free0 (stdo), _tmp4_), _tmp3_), stde = (_tmp7_ = _tmp5_, _g_free0 (stde), _tmp7_), _tmp6_), _tmp1_ = (_vala_array_free (_tmp1_, _tmp1__length1, (GDestroyNotify) g_free), NULL), _tmp8_);
      if (_inner_error_ != NULL) {
            if ((_inner_error_->domain == G_SPAWN_ERROR) || (_inner_error_->domain == VTG_VCS_BACKENDS_VCS_ERROR)) {
                  g_propagate_error (error, _inner_error_);
                  _g_free0 (stde);
                  _g_free0 (stdo);
                  _vala_collection_object_unref0 (results);
                  return NULL;
            } else {
                  _g_free0 (stde);
                  _g_free0 (stdo);
                  _vala_collection_object_unref0 (results);
                  g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
                  g_clear_error (&_inner_error_);
                  return NULL;
            }
      }
      if (_tmp9_) {
            gint exit;
            gboolean _tmp10_ = FALSE;
            exit = WEXITSTATUS (exit_status);
            if (exit == 0) {
                  _tmp10_ = TRUE;
            } else {
                  _tmp10_ = exit == 1;
            }
            if (_tmp10_) {
                  gint lines_length1;
                  gint _lines_size_;
                  char** _tmp12_;
                  char** _tmp11_;
                  char** lines;
                  gint idx;
                  GPatternSpec* modp;
                  GPatternSpec* newp;
                  GPatternSpec* delp;
                  lines = (_tmp12_ = _tmp11_ = g_strsplit (stdo, "\n", 0), lines_length1 = _vala_array_length (_tmp11_), _lines_size_ = lines_length1, _tmp12_);
                  idx = 0;
                  modp = g_pattern_spec_new ("#\tmodified:   *");
                  newp = g_pattern_spec_new ("#\tnew file:   *");
                  delp = g_pattern_spec_new ("#\tdeleted:    *");
                  while (TRUE) {
                        char* line;
                        if (!(lines[idx] != NULL)) {
                              break;
                        }
                        line = g_strdup (lines[idx]);
                        if (g_pattern_match_string (modp, line)) {
                              VtgVcsBackendsItem* item;
                              char* _tmp13_;
                              item = vtg_vcs_backends_item_new ();
                              item->state = VTG_VCS_BACKENDS_STATES_MODIFIED;
                              item->name = (_tmp13_ = string_replace (line, "#\tmodified:   ", ""), _g_free0 (item->name), _tmp13_);
                              vala_collection_add ((ValaCollection*) results, item);
                              _g_object_unref0 (item);
                        } else {
                              if (g_pattern_match_string (newp, line)) {
                                    VtgVcsBackendsItem* item;
                                    char* _tmp14_;
                                    item = vtg_vcs_backends_item_new ();
                                    item->state = VTG_VCS_BACKENDS_STATES_ADDED;
                                    item->name = (_tmp14_ = string_replace (line, "#\tnew file:   ", ""), _g_free0 (item->name), _tmp14_);
                                    vala_collection_add ((ValaCollection*) results, item);
                                    _g_object_unref0 (item);
                              } else {
                                    if (g_pattern_match_string (delp, line)) {
                                          VtgVcsBackendsItem* item;
                                          char* _tmp15_;
                                          item = vtg_vcs_backends_item_new ();
                                          item->state = VTG_VCS_BACKENDS_STATES_DELETED;
                                          item->name = (_tmp15_ = string_replace (line, "#\tdeleted:    ", ""), _g_free0 (item->name), _tmp15_);
                                          vala_collection_add ((ValaCollection*) results, item);
                                          _g_object_unref0 (item);
                                    }
                              }
                        }
                        idx++;
                        _g_free0 (line);
                  }
                  _g_pattern_spec_free0 (delp);
                  _g_pattern_spec_free0 (newp);
                  _g_pattern_spec_free0 (modp);
                  lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
            } else {
                  char* _tmp16_;
                  GError* _tmp17_;
                  _inner_error_ = (_tmp17_ = g_error_new_literal (VTG_VCS_BACKENDS_VCS_ERROR, VTG_VCS_BACKENDS_VCS_ERROR_CommandFailed, _tmp16_ = g_strdup_printf (_ ("error executing the git status command.\n%s"), stde)), _g_free0 (_tmp16_), _tmp17_);
                  {
                        if ((_inner_error_->domain == G_SPAWN_ERROR) || (_inner_error_->domain == VTG_VCS_BACKENDS_VCS_ERROR)) {
                              g_propagate_error (error, _inner_error_);
                              _g_free0 (stde);
                              _g_free0 (stdo);
                              _vala_collection_object_unref0 (results);
                              return NULL;
                        } else {
                              _g_free0 (stde);
                              _g_free0 (stdo);
                              _vala_collection_object_unref0 (results);
                              g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
                              g_clear_error (&_inner_error_);
                              return NULL;
                        }
                  }
            }
      }
      result = results;
      _g_free0 (stde);
      _g_free0 (stdo);
      return result;
}


static gboolean vtg_vcs_backends_git_real_test (VtgVcsBackendsVcsBase* base, const char* path) {
      VtgVcsBackendsGit * self;
      gboolean result = FALSE;
      char* git_dir;
      self = (VtgVcsBackendsGit*) base;
      g_return_val_if_fail (path != NULL, FALSE);
      git_dir = g_build_filename (path, ".git", NULL);
      if (g_file_test (git_dir, G_FILE_TEST_IS_DIR)) {
            result = TRUE;
            _g_free0 (git_dir);
            return result;
      }
      result = FALSE;
      _g_free0 (git_dir);
      return result;
}


static void vtg_vcs_backends_git_class_init (VtgVcsBackendsGitClass * klass) {
      vtg_vcs_backends_git_parent_class = g_type_class_peek_parent (klass);
      VTG_VCS_BACKENDS_VCS_BASE_CLASS (klass)->get_items = vtg_vcs_backends_git_real_get_items;
      VTG_VCS_BACKENDS_VCS_BASE_CLASS (klass)->test = vtg_vcs_backends_git_real_test;
}


static void vtg_vcs_backends_git_instance_init (VtgVcsBackendsGit * self) {
}


GType vtg_vcs_backends_git_get_type (void) {
      return vtg_vcs_backends_git_type_id;
}


GType vtg_vcs_backends_git_register_type (GTypeModule * module) {
      static const GTypeInfo g_define_type_info = { sizeof (VtgVcsBackendsGitClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vtg_vcs_backends_git_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (VtgVcsBackendsGit), 0, (GInstanceInitFunc) vtg_vcs_backends_git_instance_init, NULL };
      vtg_vcs_backends_git_type_id = g_type_module_register_type (module, VTG_VCS_BACKENDS_TYPE_VCS_BASE, "VtgVcsBackendsGit", &g_define_type_info, 0);
      return vtg_vcs_backends_git_type_id;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
      if ((array != NULL) && (destroy_func != NULL)) {
            int i;
            for (i = 0; i < array_length; i = i + 1) {
                  if (((gpointer*) array)[i] != NULL) {
                        destroy_func (((gpointer*) array)[i]);
                  }
            }
      }
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
      _vala_array_destroy (array, array_length, destroy_func);
      g_free (array);
}


static gint _vala_array_length (gpointer array) {
      int length;
      length = 0;
      if (array) {
            while (((gpointer*) array)[length]) {
                  length++;
            }
      }
      return length;
}





Generated by  Doxygen 1.6.0   Back to index