Skip to content

Commit

Permalink
fix get commit history limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jyelee committed Jan 12, 2016
1 parent 6411c1e commit 62a449f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
16 changes: 9 additions & 7 deletions server/gc/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ seaf_repo_manager_get_repo_history_limit (SeafRepoManager *mgr,
const char *r_repo_id = repo_id;
char sql[256];
int per_repo_days = -1;
int ret;

vinfo = seaf_repo_manager_get_virtual_repo_info (mgr, repo_id);
if (vinfo)
Expand All @@ -495,15 +496,16 @@ seaf_repo_manager_get_repo_history_limit (SeafRepoManager *mgr,
* since the global value may be smaller than per repo one.
* This can lead to data lose in GC.
*/
if (seaf_db_foreach_selected_row (mgr->seaf->db, sql,
get_limit, &per_repo_days) < 0) {
seaf_warning ("DB error.\n");
return -1;
ret = seaf_db_foreach_selected_row (mgr->seaf->db, sql,
get_limit, &per_repo_days);
if (ret == 0) {
/* If per repo value is not set, return the global one. */
return mgr->seaf->keep_history_days;
}

/* If per repo value is not set, return the global one. */
if (per_repo_days < 0)
return mgr->seaf->keep_history_days;
if (per_repo_days < 0) {
per_repo_days = -1;
}

return per_repo_days;
}
Expand Down
28 changes: 22 additions & 6 deletions server/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,28 +1778,44 @@ seaf_repo_manager_set_repo_history_limit (SeafRepoManager *mgr,
return 0;
}

static gboolean
get_history_limit_cb (SeafDBRow *row, void *data)
{
int *limit = data;

*limit = seaf_db_row_get_column_int (row, 0);

return FALSE;
}

int
seaf_repo_manager_get_repo_history_limit (SeafRepoManager *mgr,
const char *repo_id)
{
SeafVirtRepo *vinfo;
const char *r_repo_id = repo_id;
char *sql;
int per_repo_days;
int per_repo_days = -1;
int ret;

vinfo = seaf_repo_manager_get_virtual_repo_info (mgr, repo_id);
if (vinfo)
r_repo_id = vinfo->origin_repo_id;

sql = "SELECT days FROM RepoHistoryLimit WHERE repo_id=?";
per_repo_days = seaf_db_statement_get_int (mgr->seaf->db, sql,
1, "string", r_repo_id);

seaf_virtual_repo_info_free (vinfo);
ret = seaf_db_statement_foreach_row (mgr->seaf->db, sql, get_history_limit_cb,
&per_repo_days, 1, "string", r_repo_id);
if (ret == 0) {
// limit not set, return global one
per_repo_days = mgr->seaf->keep_history_days;
}

/* If per repo value is not set or DB error, return the global one. */
// db error or limit set as negative, means keep full history, return -1
if (per_repo_days < 0)
return mgr->seaf->keep_history_days;
per_repo_days = -1;

seaf_virtual_repo_info_free (vinfo);

return per_repo_days;
}
Expand Down

0 comments on commit 62a449f

Please sign in to comment.