1 #ifndef DIFF_SIMPLE_H 2 #define DIFF_SIMPLE_H 3 4 #include <glib.h> 5 #include "seafile-session.h" 6 7 #define DIFF_TYPE_WORKTREE 'W' /* diff from index to worktree */ 8 #define DIFF_TYPE_INDEX 'I' /* diff from commit to index */ 9 #define DIFF_TYPE_COMMITS 'C' /* diff between two commits*/ 10 11 #define DIFF_STATUS_ADDED 'A' 12 #define DIFF_STATUS_DELETED 'D' 13 #define DIFF_STATUS_MODIFIED 'M' 14 #define DIFF_STATUS_RENAMED 'R' 15 #define DIFF_STATUS_UNMERGED 'U' 16 #define DIFF_STATUS_DIR_ADDED 'B' 17 #define DIFF_STATUS_DIR_DELETED 'C' 18 #define DIFF_STATUS_DIR_RENAMED 'E' 19 20 enum { 21 STATUS_UNMERGED_NONE, 22 /* I and others modified the same file differently. */ 23 STATUS_UNMERGED_BOTH_CHANGED, 24 /* I and others created the same file with different contents. */ 25 STATUS_UNMERGED_BOTH_ADDED, 26 /* I removed a file while others modified it. */ 27 STATUS_UNMERGED_I_REMOVED, 28 /* Others removed a file while I modified it. */ 29 STATUS_UNMERGED_OTHERS_REMOVED, 30 /* I replace a directory with a file while others modified files under the directory. */ 31 STATUS_UNMERGED_DFC_I_ADDED_FILE, 32 /* Others replace a directory with a file while I modified files under the directory. */ 33 STATUS_UNMERGED_DFC_OTHERS_ADDED_FILE, 34 }; 35 36 typedef struct DiffEntry { 37 char type; 38 char status; 39 int unmerge_state; 40 unsigned char sha1[20]; /* used for resolve rename */ 41 char *name; 42 char *new_name; /* only used in rename. */ 43 gint64 size; 44 gint64 origin_size; /* only used in modified */ 45 } DiffEntry; 46 47 DiffEntry * 48 diff_entry_new (char type, char status, unsigned char *sha1, const char *name); 49 50 void 51 diff_entry_free (DiffEntry *de); 52 53 /* 54 * @fold_dir_diff: if TRUE, only the top level directory will be included 55 * in the diff result if a directory with files is added or removed. 56 * Otherwise all the files in the direcotory will be recursively 57 * included in the diff result. 58 */ 59 int 60 diff_commits (SeafCommit *commit1, SeafCommit *commit2, GList **results, 61 gboolean fold_dir_diff); 62 63 int 64 diff_commit_roots (const char *store_id, int version, 65 const char *root1, const char *root2, GList **results, 66 gboolean fold_dir_diff); 67 68 int 69 diff_merge (SeafCommit *merge, GList **results, gboolean fold_dir_diff); 70 71 int 72 diff_merge_roots (const char *store_id, int version, 73 const char *merged_root, const char *p1_root, const char *p2_root, 74 GList **results, gboolean fold_dir_diff); 75 76 void 77 diff_resolve_renames (GList **diff_entries); 78 79 void 80 diff_resolve_empty_dirs (GList **diff_entries); 81 82 int 83 diff_unmerged_state(int mask); 84 85 char * 86 format_diff_results(GList *results); 87 88 char * 89 diff_results_to_description (GList *results); 90 91 typedef int (*DiffFileCB) (int n, 92 const char *basedir, 93 SeafDirent *files[], 94 void *data); 95 96 typedef int (*DiffDirCB) (int n, 97 const char *basedir, 98 SeafDirent *dirs[], 99 void *data, 100 gboolean *recurse); 101 102 typedef struct DiffOptions { 103 char store_id[37]; 104 int version; 105 106 DiffFileCB file_cb; 107 DiffDirCB dir_cb; 108 void *data; 109 } DiffOptions; 110 111 int 112 diff_trees (int n, const char *roots[], DiffOptions *opt); 113 114 #endif 115