mirror of
https://github.com/haiwen/seafile.git
synced 2025-01-07 03:17:13 +08:00
Fix empty commit (#2551)
This commit is contained in:
parent
8be1b50190
commit
a9199aa91e
@ -271,14 +271,14 @@ changeset_free (ChangeSet *changeset)
|
||||
g_free (changeset);
|
||||
}
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
update_file (ChangeSetDirent *dent,
|
||||
unsigned char *sha1,
|
||||
SeafStat *st,
|
||||
const char *modifier)
|
||||
{
|
||||
if (!sha1 || !st || !S_ISREG(st->st_mode))
|
||||
return;
|
||||
return FALSE;
|
||||
dent->mode = create_ce_mode(st->st_mode);
|
||||
dent->mtime = (gint64)st->st_mtime;
|
||||
dent->size = (gint64)st->st_size;
|
||||
@ -286,6 +286,8 @@ update_file (ChangeSetDirent *dent,
|
||||
|
||||
g_free (dent->modifier);
|
||||
dent->modifier = g_strdup(modifier);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -313,11 +315,16 @@ create_new_dent (ChangeSetDir *dir,
|
||||
}
|
||||
|
||||
static ChangeSetDir *
|
||||
create_intermediate_dir (ChangeSetDir *parent, const char *dname)
|
||||
create_intermediate_dir (ChangeSetDir *parent, const char *dname, SeafStat *st)
|
||||
{
|
||||
ChangeSetDirent *dent;
|
||||
gint64 mtime = 0;
|
||||
|
||||
dent = changeset_dirent_new (EMPTY_SHA1, S_IFDIR, dname, 0, NULL, 0);
|
||||
if (st) {
|
||||
mtime = st->st_mtime;
|
||||
}
|
||||
|
||||
dent = changeset_dirent_new (EMPTY_SHA1, S_IFDIR, dname, mtime, NULL, 0);
|
||||
dent->subdir = changeset_dir_new (parent->version, EMPTY_SHA1, NULL);
|
||||
add_dent_to_dir (parent, dent);
|
||||
|
||||
@ -368,7 +375,9 @@ add_to_tree (ChangeSet *changeset,
|
||||
int n, i;
|
||||
ChangeSetDir *dir;
|
||||
ChangeSetDirent *dent;
|
||||
ChangeSetDirent *parent_dent = NULL;
|
||||
SeafDir *seaf_dir;
|
||||
gboolean changed;
|
||||
|
||||
parts = g_strsplit (path, "/", 0);
|
||||
n = g_strv_length(parts);
|
||||
@ -400,10 +409,15 @@ add_to_tree (ChangeSet *changeset,
|
||||
seaf_dir_free (seaf_dir);
|
||||
}
|
||||
dir = dent->subdir;
|
||||
parent_dent = dent;
|
||||
} else if (S_ISREG(dent->mode)) {
|
||||
if (i == (n-1)) {
|
||||
/* File exists, update it. */
|
||||
update_file (dent, sha1, st, modifier);
|
||||
changed = update_file (dent, sha1, st, modifier);
|
||||
// update parent dir mtime when modify files locally.
|
||||
if (parent_dent && changed) {
|
||||
parent_dent->mtime = st->st_mtime;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -429,9 +443,16 @@ add_to_tree (ChangeSet *changeset,
|
||||
#endif
|
||||
|
||||
if (i == (n-1)) {
|
||||
if (parent_dent && new_dent) {
|
||||
// update parent dir mtime when rename files locally.
|
||||
parent_dent->mtime = time(NULL);
|
||||
} else if (parent_dent && st) {
|
||||
// update parent dir mtime when add files locally.
|
||||
parent_dent->mtime = st->st_mtime;
|
||||
}
|
||||
create_new_dent (dir, dname, sha1, st, modifier, new_dent);
|
||||
} else {
|
||||
dir = create_intermediate_dir (dir, dname);
|
||||
dir = create_intermediate_dir (dir, dname, st);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -450,6 +471,7 @@ delete_from_tree (ChangeSet *changeset,
|
||||
int n, i;
|
||||
ChangeSetDir *dir;
|
||||
ChangeSetDirent *dent, *ret = NULL;
|
||||
ChangeSetDirent *parent_dent = NULL;
|
||||
SeafDir *seaf_dir;
|
||||
|
||||
*parent_empty = FALSE;
|
||||
@ -471,6 +493,10 @@ delete_from_tree (ChangeSet *changeset,
|
||||
if (g_hash_table_size (dir->dents) == 0)
|
||||
*parent_empty = TRUE;
|
||||
ret = dent;
|
||||
// update parent dir mtime when delete dirs locally.
|
||||
if (parent_dent) {
|
||||
parent_dent->mtime = time (NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -488,6 +514,7 @@ delete_from_tree (ChangeSet *changeset,
|
||||
seaf_dir_free (seaf_dir);
|
||||
}
|
||||
dir = dent->subdir;
|
||||
parent_dent = dent;
|
||||
} else if (S_ISREG(dent->mode)) {
|
||||
if (i == (n-1)) {
|
||||
/* Remove from hash table without freeing dent. */
|
||||
@ -495,6 +522,10 @@ delete_from_tree (ChangeSet *changeset,
|
||||
if (g_hash_table_size (dir->dents) == 0)
|
||||
*parent_empty = TRUE;
|
||||
ret = dent;
|
||||
// update parent dir mtime when delete files locally.
|
||||
if (parent_dent) {
|
||||
parent_dent->mtime = time (NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -588,14 +619,12 @@ remove_from_changeset (ChangeSet *changeset,
|
||||
}
|
||||
|
||||
static char *
|
||||
commit_tree_recursive (const char *repo_id, ChangeSetDir *dir, gint64 *new_mtime)
|
||||
commit_tree_recursive (const char *repo_id, ChangeSetDir *dir)
|
||||
{
|
||||
ChangeSetDirent *dent;
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
char *new_id;
|
||||
gint64 subdir_new_mtime;
|
||||
gint64 dir_mtime = 0;
|
||||
SeafDir *seaf_dir;
|
||||
char *ret = NULL;
|
||||
|
||||
@ -603,16 +632,13 @@ commit_tree_recursive (const char *repo_id, ChangeSetDir *dir, gint64 *new_mtime
|
||||
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
||||
dent = value;
|
||||
if (dent->subdir) {
|
||||
new_id = commit_tree_recursive (repo_id, dent->subdir, &subdir_new_mtime);
|
||||
new_id = commit_tree_recursive (repo_id, dent->subdir);
|
||||
if (!new_id)
|
||||
return NULL;
|
||||
|
||||
memcpy (dent->id, new_id, 40);
|
||||
dent->mtime = subdir_new_mtime;
|
||||
g_free (new_id);
|
||||
}
|
||||
if (dir_mtime < dent->mtime)
|
||||
dir_mtime = dent->mtime;
|
||||
}
|
||||
|
||||
seaf_dir = changeset_dir_to_seaf_dir (dir);
|
||||
@ -632,9 +658,6 @@ commit_tree_recursive (const char *repo_id, ChangeSetDir *dir, gint64 *new_mtime
|
||||
ret = g_strdup(seaf_dir->dir_id);
|
||||
|
||||
out:
|
||||
if (ret != NULL)
|
||||
*new_mtime = dir_mtime;
|
||||
|
||||
seaf_dir_free (seaf_dir);
|
||||
return ret;
|
||||
}
|
||||
@ -648,10 +671,8 @@ out:
|
||||
char *
|
||||
commit_tree_from_changeset (ChangeSet *changeset)
|
||||
{
|
||||
gint64 mtime;
|
||||
char *root_id = commit_tree_recursive (changeset->repo_id,
|
||||
changeset->tree_root,
|
||||
&mtime);
|
||||
changeset->tree_root);
|
||||
|
||||
return root_id;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user