Add option preventing metastore from omitting .git dirs.
[metastore.git] / metaentry.h
blob3b2f2a1c68dffc929ce0bf3635fff3664f447332
1 /*
2 * Various functions to work with meta entries.
4 * Copyright (C) 2007 David Härdeman <david@hardeman.nu>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <stdbool.h>
23 /* Data structure to hold all metadata for a file/dir */
24 struct metaentry {
25 struct metaentry *next; /* For the metahash chains */
26 struct metaentry *list; /* For creating additional lists of entries */
28 char *path;
29 unsigned int pathlen;
31 char *owner;
32 char *group;
33 mode_t mode;
34 time_t mtime;
35 long mtimensec;
37 unsigned int xattrs;
38 char **xattr_names;
39 ssize_t *xattr_lvalues;
40 char **xattr_values;
43 #define HASH_INDEXES 1024
45 /* Data structure to hold a number of metadata entries */
46 struct metahash {
47 struct metaentry *bucket[HASH_INDEXES];
48 unsigned int count;
51 /* Create a metaentry for the file/dir/etc at path */
52 struct metaentry *mentry_create(const char *path);
54 /* Recurses opath and adds metadata entries to the metaentry list */
55 void mentries_recurse_path(const char *opath, struct metahash **mhash, bool git);
57 /* Stores a metaentry list to a file */
58 void mentries_tofile(const struct metahash *mhash, const char *path);
60 /* Creates a metaentry list from a file */
61 void mentries_fromfile(struct metahash **mhash, const char *path);
63 /* Searches haystack for an xattr matching xattr number n in needle */
64 int mentry_find_xattr(struct metaentry *haystack,
65 struct metaentry *needle,
66 int n);
68 #define DIFF_NONE 0x00
69 #define DIFF_OWNER 0x01
70 #define DIFF_GROUP 0x02
71 #define DIFF_MODE 0x04
72 #define DIFF_TYPE 0x08
73 #define DIFF_MTIME 0x10
74 #define DIFF_XATTR 0x20
75 #define DIFF_ADDED 0x40
76 #define DIFF_DELE 0x80
78 /* Compares two metaentries and returns an int with a bitmask of differences */
79 int mentry_compare(struct metaentry *left,
80 struct metaentry *right,
81 bool do_mtime);
83 /* Compares lists of real and stored metadata and calls pfunc for each */
84 void mentries_compare(struct metahash *mhashreal,
85 struct metahash *mhashstored,
86 void (*pfunc)(struct metaentry *real,
87 struct metaentry *stored,
88 int cmp),
89 bool do_mtime);