Skip to content

Commit

Permalink
[client] Scan worktree changes when "sync now" is invoked.
Browse files Browse the repository at this point in the history
  • Loading branch information
killing committed Dec 23, 2014
1 parent 55a8a20 commit 21bfad2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
19 changes: 12 additions & 7 deletions daemon/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,13 @@ static int
scan_worktree_for_changes (struct index_state *istate, SeafRepo *repo,
SeafileCrypt *crypt, GList *ignore_list)
{
remove_deleted (istate, repo->worktree, "", ignore_list, NULL);

if (add_recursive (repo->id, repo->version, repo->email,
istate, repo->worktree, "", crypt, FALSE, ignore_list,
NULL, NULL, NULL) < 0)
return -1;

remove_deleted (istate, repo->worktree, "", ignore_list, NULL);

return 0;
}

Expand Down Expand Up @@ -1406,7 +1406,7 @@ handle_unmerged_index_entries (SeafRepo *repo, struct index_state *istate,

static int
index_add (SeafRepo *repo, struct index_state *istate,
gboolean is_initial_commit, gboolean handle_unmerged)
gboolean is_force_commit, gboolean handle_unmerged)
{
SeafileCrypt *crypt = NULL;
GList *ignore_list = NULL;
Expand All @@ -1418,8 +1418,13 @@ index_add (SeafRepo *repo, struct index_state *istate,

ignore_list = seaf_repo_load_ignore_files (repo->worktree);

if (apply_worktree_changes_to_index (repo, istate, crypt, ignore_list) < 0) {
seaf_warning ("Failed to apply worktree changes to index.\n");
if (!is_force_commit) {
if (apply_worktree_changes_to_index (repo, istate, crypt, ignore_list) < 0) {
seaf_warning ("Failed to apply worktree changes to index.\n");
ret = -1;
}
} else if (scan_worktree_for_changes (istate, repo, crypt, ignore_list) < 0) {
seaf_warning ("Failed to scan worktree for changes.\n");
ret = -1;
}

Expand Down Expand Up @@ -1755,7 +1760,7 @@ print_index (struct index_state *istate)
}

char *
seaf_repo_index_commit (SeafRepo *repo, const char *desc, gboolean is_initial_commit,
seaf_repo_index_commit (SeafRepo *repo, const char *desc, gboolean is_force_commit,
GError **error)
{
SeafRepoManager *mgr = repo->manager;
Expand All @@ -1779,7 +1784,7 @@ seaf_repo_index_commit (SeafRepo *repo, const char *desc, gboolean is_initial_co
if (need_handle_unmerged_index (repo, &istate))
unmerged = TRUE;

if (index_add (repo, &istate, is_initial_commit, unmerged) < 0) {
if (index_add (repo, &istate, is_force_commit, unmerged) < 0) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to add");
goto error;
}
Expand Down
27 changes: 21 additions & 6 deletions daemon/sync-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ has_old_commits_to_upload (SeafRepo *repo);
static int
sync_repo_v2 (SeafSyncManager *manager, SeafRepo *repo, gboolean is_manual_sync);

static gboolean
check_http_protocol (SeafSyncManager *mgr, SeafRepo *repo, gboolean *is_checking);

SeafSyncManager*
seaf_sync_manager_new (SeafileSession *seaf)
{
Expand Down Expand Up @@ -393,6 +396,19 @@ seaf_sync_manager_add_sync_task (SeafSyncManager *mgr,
return -1;
}

SyncInfo *info = get_sync_info (mgr, repo->id);

if (info->in_sync)
return 0;

gboolean is_checking_http = FALSE;
if (seaf->enable_http_sync && repo->version > 0) {
if (check_http_protocol (mgr, repo, &is_checking_http)) {
sync_repo_v2 (mgr, repo, TRUE);
return 0;
}
}

/* If relay is not ready or protocol version is not determined,
* need to wait.
*/
Expand All @@ -402,11 +418,6 @@ seaf_sync_manager_add_sync_task (SeafSyncManager *mgr,
return 0;
}

SyncInfo *info = get_sync_info (mgr, repo->id);

if (info->in_sync)
return 0;

ServerState *state = g_hash_table_lookup (mgr->server_states,
repo->relay_id);

Expand Down Expand Up @@ -1515,7 +1526,7 @@ commit_job (void *vtask)
res->changed = TRUE;
res->success = TRUE;

char *commit_id = seaf_repo_index_commit (repo, "", task->is_initial_commit,
char *commit_id = seaf_repo_index_commit (repo, "", task->is_manual_sync,
&error);
if (commit_id == NULL && error != NULL) {
seaf_warning ("[Sync mgr] Failed to commit to repo %s(%.8s).\n",
Expand Down Expand Up @@ -1842,6 +1853,10 @@ sync_repo_v2 (SeafSyncManager *manager, SeafRepo *repo, gboolean is_manual_sync)
* but it's before 30-second schedule.
*/
goto out;
} else if (is_manual_sync) {
task = create_sync_task_v2 (manager, repo, is_manual_sync, FALSE);
commit_repo (task);
goto out;
} else if (create_commit_from_event_queue (manager, repo, is_manual_sync))
goto out;
}
Expand Down

0 comments on commit 21bfad2

Please sign in to comment.