static int send_commit_start (CcnetProcessor *processor, int argc, char **argv) { USE_PRIV; GString *buf; TransferTask *task = ((SeafileSendcommitV3Proc *)processor)->tx_task; memcpy (priv->remote_id, task->remote_head, 41); /* fs_roots can be non-NULL if transfer is resumed from NET_DOWN. */ if (task->fs_roots != NULL) object_list_free (task->fs_roots); task->fs_roots = object_list_new (); if (task->commits != NULL) object_list_free (task->commits); task->commits = object_list_new (); buf = g_string_new (NULL); g_string_printf (buf, "remote %s seafile-recvcommit-v3 %s %s", processor->peer_id, task->to_branch, task->session_token); ccnet_processor_send_request (processor, buf->str); g_string_free (buf, TRUE); return 0; }
static int get_commit_start (CcnetProcessor *processor, int argc, char **argv) { USE_PRIV; GString *buf = g_string_new (NULL); TransferTask *task = ((SeafileGetcommitV3Proc *)processor)->tx_task; SeafBranch *master = NULL; g_return_val_if_fail (task->session_token, -1); /* fs_roots can be non-NULL if transfer is resumed from NET_DOWN. */ if (task->fs_roots != NULL) object_list_free (task->fs_roots); task->fs_roots = object_list_new (); priv->writer_id = seaf_obj_store_register_async_write (seaf->commit_mgr->obj_store, task->repo_id, task->repo_version, commit_write_cb, processor); g_string_printf (buf, "remote %s seafile-putcommit-v3 %s %s", processor->peer_id, task->head, task->session_token); ccnet_processor_send_request (processor, buf->str); g_string_free (buf, TRUE); seaf_branch_unref (master); return 0; }
static int send_commit_start (CcnetProcessor *processor, int argc, char **argv) { GString *buf; int ret; TransferTask *task = ((SeafileSendcommitProc *)processor)->tx_task; ObjectList *ol = object_list_new (); ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr, task->head, commit_collector, ol, FALSE); if (ret == FALSE) { object_list_free (ol); seaf_warning ("[sendcommit] Load commits error\n"); ccnet_processor_done (processor, FALSE); return -1; } g_return_val_if_fail (object_list_length(ol) != 0, -1); task->commits = ol; /* Send to_branch to the relay. */ buf = g_string_new (NULL); g_string_printf (buf, "remote %s seafile-recvcommit %s %s", processor->peer_id, task->to_branch, task->session_token); ccnet_processor_send_request (processor, buf->str); g_string_free (buf, TRUE); processor->state = INIT; return 0; }
/** * Return a common object list instance. */ object_list_t *object_list_shared_instance(void) { if (object_list_subwindow == NULL) { object_list_subwindow = object_list_new(); } return object_list_subwindow; }
static int send_commit_ids (CcnetProcessor *processor, const char *head) { char buf[2048]; char *ptr = buf; int i, count = 0; int ret; ObjectList *ol = object_list_new (); ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr, head, commit_collector, ol); if (ret == FALSE) { object_list_free (ol); g_warning ("[putcommit] Load commits error\n"); ccnet_processor_send_response ( processor, SC_NOT_FOUND, SS_NOT_FOUND, NULL, 0); ccnet_processor_done (processor, FALSE); return -1; } int ollen = object_list_length(ol); g_assert (ollen != 0); for (i = 0; i < ollen; i++) { memcpy (ptr, g_ptr_array_index(ol->obj_ids, i), 40); ptr += 40; *ptr++ = '\n'; if (++count == 48) { *ptr = '\0'; g_debug ("[putcommit] Send commit ids:\n%s", buf); ccnet_processor_send_response (processor, SC_COMMIT_IDS, SS_COMMIT_IDS, buf, 41 * count + 1); ptr = buf; count = 0; } } if (count) { *ptr = '\0'; g_debug ("[putcommit] Send commit ids:\n%s", buf); ccnet_processor_send_response (processor, SC_COMMIT_IDS, SS_COMMIT_IDS, buf, 41 * count + 1); } g_debug ("[putcommit] Sent commit ids.\n"); ccnet_processor_send_response (processor, SC_END, SS_END, NULL, 0); return 0; }
static int compute_delta_commits (CcnetProcessor *processor, const char *head) { gboolean ret; TransferTask *task = ((SeafileSendcommitV3Proc *)processor)->tx_task; USE_PRIV; string_list_free (priv->id_list); priv->id_list = NULL; object_list_free (task->fs_roots); task->fs_roots = object_list_new (); object_list_free (task->commits); task->commits = object_list_new (); priv->commit_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr, priv->remote_id, traverse_commit_remote, processor, FALSE); if (!ret) { return -1; } ret = seaf_commit_manager_traverse_commit_tree (seaf->commit_mgr, head, compute_delta, processor, FALSE); if (!ret) { return -1; } return 0; }
/** * Display the object list interactively. This will dynamically size the list * for the best appearance. This should only be used in the main term. * * \param height is the height limit for the list. * \param width is the width limit for the list. */ void object_list_show_interactive(int height, int width) { textblock *tb; object_list_t *list; size_t max_width = 0, max_height = 0; int safe_height, safe_width; region r; if (height < 1 || width < 1) return; tb = textblock_new(); list = object_list_new(); object_list_collect(list); object_list_sort(list, object_list_standard_compare); /* * Figure out optimal display rect. Large numbers are passed as the height * and width limit so that we can calculate the maximum number of rows and * columns to display the list nicely. We then adjust those values as * needed to fit in the main term. Height is adjusted to account for the * texblock prompt. The list is positioned on the right side of the term * underneath the status line. */ object_list_format_textblock(list, NULL, 1000, 1000, &max_height, &max_width); safe_height = MIN(height - 2, (int)max_height + 2); safe_width = MIN(width - 13, (int)max_width); r.col = -safe_width; r.row = 1; r.width = safe_width; r.page_rows = safe_height; /* * Actually draw the list. We pass in max_height to the format function so * that all lines will be appended to the textblock. The textblock itself * will handle fitting it into the region. However, we have to pass * safe_width so that the format function will pad the lines properly so * that the location string is aligned to the right edge of the list. */ object_list_format_textblock(list, tb, (int)max_height, safe_width, NULL, NULL); region_erase_bordered(&r); textui_textblock_show(tb, r, NULL); textblock_free(tb); object_list_free(list); }
static int get_commit_start (CcnetProcessor *processor, int argc, char **argv) { GString *buf = g_string_new (NULL); TransferTask *task = ((SeafileGetcommitV2Proc *)processor)->tx_task; SeafBranch *master = NULL; char *end_commit_id = NULL; g_return_val_if_fail (task->session_token, -1); if (!task->is_clone) { master = seaf_branch_manager_get_branch (seaf->branch_mgr, task->repo_id, "master"); if (master != NULL) end_commit_id = master->commit_id; } /* fs_roots can be non-NULL if transfer is resumed from NET_DOWN. */ if (task->fs_roots != NULL) object_list_free (task->fs_roots); task->fs_roots = object_list_new (); if (end_commit_id != NULL) g_string_printf (buf, "remote %s seafile-putcommit-v2 %s %s %s", processor->peer_id, task->head, end_commit_id, task->session_token); else g_string_printf (buf, "remote %s seafile-putcommit-v2 %s %s", processor->peer_id, task->head, task->session_token); ccnet_processor_send_request (processor, buf->str); g_string_free (buf, TRUE); seaf_branch_unref (master); return 0; }