static gboolean resolve_refspec (OstreeRepo *self, const char *remote, const char *ref, gboolean allow_noent, char **out_rev, GError **error) { gboolean ret = FALSE; __attribute__((unused)) GCancellable *cancellable = NULL; GError *temp_error = NULL; g_autofree char *ret_rev = NULL; g_autoptr(GFile) child = NULL; g_return_val_if_fail (ref != NULL, FALSE); /* We intentionally don't allow a ref that looks like a checksum */ if (ostree_validate_checksum_string (ref, NULL)) { ret_rev = g_strdup (ref); } else if (remote != NULL) { child = ot_gfile_resolve_path_printf (self->remote_heads_dir, "%s/%s", remote, ref); if (!g_file_query_exists (child, NULL)) g_clear_object (&child); } else { child = g_file_resolve_relative_path (self->local_heads_dir, ref); if (!g_file_query_exists (child, NULL)) { g_clear_object (&child); child = g_file_resolve_relative_path (self->remote_heads_dir, ref); if (!g_file_query_exists (child, NULL)) { g_clear_object (&child); if (!find_ref_in_remotes (self, ref, &child, error)) goto out; } } } if (child) { if ((ret_rev = gs_file_load_contents_utf8 (child, NULL, &temp_error)) == NULL) { g_propagate_error (error, temp_error); g_prefix_error (error, "Couldn't open ref '%s': ", gs_file_get_path_cached (child)); goto out; } g_strchomp (ret_rev); if (!ostree_validate_checksum_string (ret_rev, error)) goto out; } else { if (!resolve_refspec_fallback (self, remote, ref, allow_noent, &ret_rev, cancellable, error)) goto out; } ot_transfer_out_value (out_rev, &ret_rev); ret = TRUE; out: return ret; }
static gboolean resolve_refspec (OstreeRepo *self, const char *remote, const char *ref, gboolean allow_noent, gboolean fallback_remote, char **out_rev, GError **error) { __attribute__((unused)) GCancellable *cancellable = NULL; g_autofree char *ret_rev = NULL; glnx_fd_close int target_fd = -1; g_return_val_if_fail (ref != NULL, FALSE); /* We intentionally don't allow a ref that looks like a checksum */ if (ostree_validate_checksum_string (ref, NULL)) { ret_rev = g_strdup (ref); } else if (remote != NULL) { const char *remote_ref = glnx_strjoina ("refs/remotes/", remote, "/", ref); if (!ot_openat_ignore_enoent (self->repo_dir_fd, remote_ref, &target_fd, error)) return FALSE; } else { const char *local_ref = glnx_strjoina ("refs/heads/", ref); if (!ot_openat_ignore_enoent (self->repo_dir_fd, local_ref, &target_fd, error)) return FALSE; if (target_fd == -1 && fallback_remote) { local_ref = glnx_strjoina ("refs/remotes/", ref); if (!ot_openat_ignore_enoent (self->repo_dir_fd, local_ref, &target_fd, error)) return FALSE; if (target_fd == -1) { if (!find_ref_in_remotes (self, ref, &target_fd, error)) return FALSE; } } } if (target_fd != -1) { ret_rev = glnx_fd_readall_utf8 (target_fd, NULL, NULL, error); if (!ret_rev) { g_prefix_error (error, "Couldn't open ref '%s': ", ref); return FALSE; } g_strchomp (ret_rev); if (!ostree_validate_checksum_string (ret_rev, error)) return FALSE; } else { if (!resolve_refspec_fallback (self, remote, ref, allow_noent, fallback_remote, &ret_rev, cancellable, error)) return FALSE; } ot_transfer_out_value (out_rev, &ret_rev); return TRUE; }