예제 #1
0
static GgitRepository *
ide_git_vcs_load (IdeGitVcs  *self,
                  GError    **error)
{
  g_autoptr(GFile) location = NULL;
  GgitRepository *repository = NULL;
  IdeContext *context;
  GFile *project_file;

  g_assert (IDE_IS_GIT_VCS (self));

  context = ide_object_get_context (IDE_OBJECT (self));
  project_file = ide_context_get_project_file (context);

  if (!(location = ggit_repository_discover (project_file, error)))
    return NULL;

  if (!(repository = ggit_repository_open (location, error)))
    return NULL;

  /* Only set once, on load. Not thread-safe otherwise. */
  if (self->working_directory == NULL)
    self->working_directory = ggit_repository_get_workdir (repository);

  return repository;
}
예제 #2
0
int
main (int argc, char *argv[])
{
	GgitRepository *repository;
	GgitOId *oid;
	GError *error = NULL;
	const gchar hex[] = "82576c09c3fac738a54582c6c04a47684882d1a1";
	gchar *oid_str;
	gchar *repo_path;

	g_type_init ();

	if (argc < 2)
	{
		g_message ("Use: ./general path_to_git_repository");
		return 1;
	}

	repo_path = ggit_repository_discover (argv[1], &error);

	if (error != NULL)
	{
		g_message (error->message);
		return 1;
	}

	g_message ("Path repository: %s", repo_path);
	repository = ggit_repository_open (repo_path, &error);
	g_free (repo_path);

	if (error != NULL)
	{
		g_message (error->message);
		return 1;
	}

	g_message ("Working dir: %s", ggit_repository_get_path (repository,
	                                                        GGIT_REPO_PATH_WORKDIR));

	oid = ggit_oid_new_from_string (hex);
	oid_str = ggit_oid_to_string (oid);

	g_message ("OId str: %s", oid_str);

	g_free (oid_str);
	ggit_oid_free (oid);
	g_object_unref (repository);

	return 0;
}
예제 #3
0
static GgitRepository *
ide_git_vcs_load (IdeGitVcs  *self,
                  GError    **error)
{
  g_autofree gchar *uri = NULL;
  g_autoptr(GFile) location = NULL;
  GgitRepository *repository = NULL;
  IdeContext *context;
  GFile *project_file;

  g_assert (IDE_IS_GIT_VCS (self));
  g_assert (error != NULL);

  context = ide_object_get_context (IDE_OBJECT (self));
  project_file = ide_context_get_project_file (context);

  if (!(location = ide_git_vcs_discover (self, project_file, error)))
    {
      if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
        return NULL;

      g_clear_error (error);

      /* Fallback to libgit2(-glib) discovery */
      if (!(location = ggit_repository_discover (project_file, error)))
        return NULL;
    }

  uri = g_file_get_uri (location);
  g_debug ("Discovered .git location at “%s”", uri);

  if (!(repository = ggit_repository_open (location, error)))
    return NULL;

  /* Note: Only set this once on load, otherwise not thread-safe. */
  if (self->working_directory == NULL)
    self->working_directory = ggit_repository_get_workdir (repository);

  return repository;
}