Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username to commit #662

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion common/commit-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ seaf_commit_new (const char *commit_id,
const char *repo_id,
const char *root_id,
const char *creator_name,
const char *username,
const char *creator_id,
const char *desc,
guint64 ctime)
Expand All @@ -86,6 +87,8 @@ seaf_commit_new (const char *commit_id,
memcpy (commit->creator_id, creator_id, 40);
commit->creator_id[40] = '\0';

commit->username = g_strdup (username);

commit->desc = g_strdup (desc);

if (ctime == 0) {
Expand Down Expand Up @@ -608,6 +611,8 @@ commit_to_json_object (SeafCommit *commit)
json_object_set_string_member (object, "repo_id", commit->repo_id);
if (commit->creator_name)
json_object_set_string_member (object, "creator_name", commit->creator_name);
if (commit->username)
json_object_set_string_member (object, "username", commit->username);
json_object_set_string_member (object, "creator", commit->creator_id);
json_object_set_string_member (object, "description", commit->desc);
json_object_set_int_member (object, "ctime", (gint64)commit->ctime);
Expand Down Expand Up @@ -661,6 +666,7 @@ commit_from_json_object (const char *commit_id, json_t *object)
const char *root_id;
const char *repo_id;
const char *creator_name = NULL;
const char *username = NULL;
const char *creator;
const char *desc;
gint64 ctime;
Expand All @@ -684,6 +690,8 @@ commit_from_json_object (const char *commit_id, json_t *object)
repo_id = json_object_get_string_member (object, "repo_id");
if (json_object_has_member (object, "creator_name"))
creator_name = json_object_get_string_or_null_member (object, "creator_name");
if (json_object_has_member (object, "username"))
username = json_object_get_string_or_null_member (object, "username");
creator = json_object_get_string_member (object, "creator");
desc = json_object_get_string_member (object, "description");
if (!desc)
Expand Down Expand Up @@ -775,7 +783,7 @@ commit_from_json_object (const char *commit_id, json_t *object)

char *creator_name_l = creator_name ? g_ascii_strdown (creator_name, -1) : NULL;
commit = seaf_commit_new (commit_id, repo_id, root_id,
creator_name_l, creator, desc, ctime);
creator_name_l, username, creator, desc, ctime);
g_free (creator_name_l);

commit->parent_id = parent_id ? g_strdup(parent_id) : NULL;
Expand Down
4 changes: 3 additions & 1 deletion common/commit-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct _SeafCommit {
char repo_id[37];
char root_id[41]; /* the fs root */
char *desc;
char *creator_name;
char *creator_name; // creator_name is user's email.
char *username; // username is user's friendly username.
char creator_id[41];
guint64 ctime; /* creation time */
char *parent_id;
Expand Down Expand Up @@ -56,6 +57,7 @@ seaf_commit_new (const char *commit_id,
const char *repo_id,
const char *root_id,
const char *author_name,
const char *username,
const char *creator_id,
const char *desc,
guint64 ctime);
Expand Down
6 changes: 5 additions & 1 deletion common/merge-new.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ merge_conflict_dirname (const char *store_id, int version,
opt->remote_repo_id, opt->remote_head);
goto out;
}
modifier = g_strdup(commit->creator_name);
if (commit->username) {
modifier = g_strdup(commit->username);
} else {
modifier = g_strdup(commit->creator_name);
}
seaf_commit_unref (commit);

conflict_name = gen_conflict_path (dirname, modifier, (gint64)time(NULL));
Expand Down
45 changes: 31 additions & 14 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ seafile_change_repo_passwd (const char *repo_id,
repo->id,
parent->root_id,
user,
NULL,
EMPTY_SHA1,
"Changed library password",
0);
Expand Down Expand Up @@ -1398,6 +1399,7 @@ seafile_web_get_access_token (const char *repo_id,
const char *obj_id,
const char *op,
const char *username,
const char *friendly_name,
int use_onetime,
GError **error)
{
Expand All @@ -1410,7 +1412,8 @@ seafile_web_get_access_token (const char *repo_id,

token = seaf_web_at_manager_get_access_token (seaf->web_at_mgr,
repo_id, obj_id, op,
username, use_onetime, error);
username, friendly_name,
use_onetime, error);
return token;
}

Expand Down Expand Up @@ -2345,6 +2348,7 @@ int
seafile_revert_on_server (const char *repo_id,
const char *commit_id,
const char *user_name,
const char *friendly_name,
GError **error)
{
if (!repo_id || strlen(repo_id) != 36 ||
Expand All @@ -2369,13 +2373,14 @@ seafile_revert_on_server (const char *repo_id,
repo_id,
commit_id,
user_name,
friendly_name,
error);
}

int
seafile_post_file (const char *repo_id, const char *temp_file_path,
const char *parent_dir, const char *file_name,
const char *user,
const char *user, const char *friendly_name,
GError **error)
{
char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL;
Expand Down Expand Up @@ -2412,7 +2417,7 @@ seafile_post_file (const char *repo_id, const char *temp_file_path,

if (seaf_repo_manager_post_file (seaf->repo_mgr, repo_id,
temp_file_path, rpath,
norm_file_name, user,
norm_file_name, user, friendly_name,
error) < 0) {
ret = -1;
}
Expand Down Expand Up @@ -2493,6 +2498,7 @@ seafile_post_multi_files (const char *repo_id,
const char *filenames_json,
const char *paths_json,
const char *user,
const char *friendly_name,
int replace_existed,
GError **error)
{
Expand Down Expand Up @@ -2525,6 +2531,7 @@ seafile_post_multi_files (const char *repo_id,
filenames_json,
paths_json,
user,
friendly_name,
replace_existed,
&ret_json,
NULL,
Expand All @@ -2540,7 +2547,8 @@ seafile_post_multi_files (const char *repo_id,
char *
seafile_put_file (const char *repo_id, const char *temp_file_path,
const char *parent_dir, const char *file_name,
const char *user, const char *head_id,
const char *user, const char *friendly_name,
const char *head_id,
GError **error)
{
char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL;
Expand Down Expand Up @@ -2575,7 +2583,7 @@ seafile_put_file (const char *repo_id, const char *temp_file_path,

seaf_repo_manager_put_file (seaf->repo_mgr, repo_id,
temp_file_path, rpath,
norm_file_name, user, head_id,
norm_file_name, user, friendly_name, head_id,
&new_file_id, error);

out:
Expand Down Expand Up @@ -2640,6 +2648,7 @@ seafile_put_file (const char *repo_id, const char *temp_file_path,
int
seafile_post_dir (const char *repo_id, const char *parent_dir,
const char *new_dir_name, const char *user,
const char *friendly_name,
GError **error)
{
char *norm_parent_dir = NULL, *norm_dir_name = NULL, *rpath = NULL;
Expand Down Expand Up @@ -2675,7 +2684,7 @@ seafile_post_dir (const char *repo_id, const char *parent_dir,

if (seaf_repo_manager_post_dir (seaf->repo_mgr, repo_id,
rpath, norm_dir_name,
user, error) < 0) {
user, friendly_name, error) < 0) {
ret = -1;
}

Expand All @@ -2690,6 +2699,7 @@ seafile_post_dir (const char *repo_id, const char *parent_dir,
int
seafile_post_empty_file (const char *repo_id, const char *parent_dir,
const char *new_file_name, const char *user,
const char *friendly_name,
GError **error)
{
char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL;
Expand Down Expand Up @@ -2725,7 +2735,7 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir,

if (seaf_repo_manager_post_empty_file (seaf->repo_mgr, repo_id,
rpath, norm_file_name,
user, error) < 0) {
user, friendly_name, error) < 0) {
ret = -1;
}

Expand All @@ -2740,6 +2750,7 @@ seafile_post_empty_file (const char *repo_id, const char *parent_dir,
int
seafile_del_file (const char *repo_id, const char *parent_dir,
const char *file_name, const char *user,
const char *friendly_name,
GError **error)
{
char *norm_parent_dir = NULL, *norm_file_name = NULL, *rpath = NULL;
Expand Down Expand Up @@ -2775,7 +2786,7 @@ seafile_del_file (const char *repo_id, const char *parent_dir,

if (seaf_repo_manager_del_file (seaf->repo_mgr, repo_id,
rpath, norm_file_name,
user, error) < 0) {
user, friendly_name, error) < 0) {
ret = -1;
}

Expand All @@ -2795,6 +2806,7 @@ seafile_copy_file (const char *src_repo_id,
const char *dst_dir,
const char *dst_filename,
const char *user,
const char *friendly_name,
int need_progress,
int synchronous,
GError **error)
Expand Down Expand Up @@ -2849,7 +2861,7 @@ seafile_copy_file (const char *src_repo_id,
ret = (GObject *)seaf_repo_manager_copy_multiple_files (seaf->repo_mgr,
src_repo_id, rsrc_dir, norm_src_filename,
dst_repo_id, rdst_dir, norm_dst_filename,
user, need_progress, synchronous,
user, friendly_name, need_progress, synchronous,
error);

out:
Expand All @@ -2872,6 +2884,7 @@ seafile_move_file (const char *src_repo_id,
const char *dst_filename,
int replace,
const char *user,
const char *friendly_name,
int need_progress,
int synchronous,
GError **error)
Expand Down Expand Up @@ -2926,7 +2939,7 @@ seafile_move_file (const char *src_repo_id,
ret = (GObject *)seaf_repo_manager_move_multiple_files (seaf->repo_mgr,
src_repo_id, rsrc_dir, norm_src_filename,
dst_repo_id, rdst_dir, norm_dst_filename,
replace, user, need_progress, synchronous,
replace, user, friendly_name, need_progress, synchronous,
error);

out:
Expand Down Expand Up @@ -2958,6 +2971,7 @@ seafile_rename_file (const char *repo_id,
const char *oldname,
const char *newname,
const char *user,
const char *friendly_name,
GError **error)
{
char *norm_parent_dir = NULL, *norm_oldname = NULL, *norm_newname = NULL;
Expand Down Expand Up @@ -3002,7 +3016,7 @@ seafile_rename_file (const char *repo_id,

if (seaf_repo_manager_rename_file (seaf->repo_mgr, repo_id,
rpath, norm_oldname, norm_newname,
user, error) < 0) {
user, friendly_name, error) < 0) {
ret = -1;
}

Expand Down Expand Up @@ -3506,6 +3520,7 @@ seafile_revert_file (const char *repo_id,
const char *commit_id,
const char *path,
const char *user,
const char *friendly_name,
GError **error)
{
if (!repo_id || !commit_id || !path || !user) {
Expand All @@ -3528,7 +3543,7 @@ seafile_revert_file (const char *repo_id,

int ret = seaf_repo_manager_revert_file (seaf->repo_mgr,
repo_id, commit_id,
rpath, user, error);
rpath, user, friendly_name, error);
g_free (rpath);

return ret;
Expand All @@ -3539,6 +3554,7 @@ seafile_revert_dir (const char *repo_id,
const char *commit_id,
const char *path,
const char *user,
const char *friendly_name,
GError **error)
{
if (!repo_id || !commit_id || !path || !user) {
Expand All @@ -3561,7 +3577,7 @@ seafile_revert_dir (const char *repo_id,

int ret = seaf_repo_manager_revert_dir (seaf->repo_mgr,
repo_id, commit_id,
rpath, user, error);
rpath, user, friendly_name, error);
g_free (rpath);

return ret;
Expand Down Expand Up @@ -4259,6 +4275,7 @@ seafile_get_trash_repo_owner (const char *repo_id, GError **error)
int
seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir,
const char *new_dir_path, const char *user,
const char *friendly_name,
GError **error)
{
if (!repo_id || !parent_dir || !new_dir_path || !user) {
Expand All @@ -4273,7 +4290,7 @@ seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir,

if (seaf_repo_manager_mkdir_with_parents (seaf->repo_mgr, repo_id,
parent_dir, new_dir_path,
user, error) < 0) {
user, friendly_name, error) < 0) {
return -1;
}

Expand Down
4 changes: 3 additions & 1 deletion fileserver/commitmgr/commitmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Commit struct {
RepoID string `json:"repo_id"`
RootID string `json:"root_id"`
CreatorName string `json:"creator_name,omitempty"`
UserName string `json:"username,omitempty"`
CreatorID string `json:"creator"`
Desc string `json:"description"`
Ctime int64 `json:"ctime"`
Expand Down Expand Up @@ -50,12 +51,13 @@ func Init(seafileConfPath string, seafileDataDir string) {
}

// NewCommit initializes a Commit object.
func NewCommit(repoID, parentID, newRoot, user, desc string) *Commit {
func NewCommit(repoID, parentID, newRoot, user, username, desc string) *Commit {
commit := new(Commit)
commit.RepoID = repoID
commit.RootID = newRoot
commit.Desc = desc
commit.CreatorName = user
commit.UserName = username
commit.CreatorID = "0000000000000000000000000000000000000000"
commit.Ctime = time.Now().Unix()
commit.CommitID = computeCommitID(commit)
Expand Down
Loading
Loading