diff options
author | Adam Spragg <adam@spra.gg> | 2022-05-18 16:35:35 +0100 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-05-24 10:12:33 +0100 |
commit | 7292804c1bafd43389defc0d7b4352ada666d626 (patch) | |
tree | 9e0390c7f45dd20b7db92d3f64bdcecaa3d9c1dc /src/metastore.c | |
parent | ce62a76e4570b6368384b3995c1ba106389df454 (diff) |
Add ability to not save mtime in metadata files
If you're storing metadata in a version control system with multiple
branches, mtime differences are going to produce a whole bunch of
conflicts that you likely don't care about. This allows you to not
save mtime and avoid those.
Note that we use a sentinel value of -1 for the mentry `mtimensec` field
to indicate this in the data, as all values of `mtime` are theoretically
valid, but `mtimensec` must always be between 0 and 999,999,999 in the
real world.
I'm not 100% sure about the mechanism for selecting this feature. The
legacy behaviour for metastore was to save mtimes in the metadata files,
but ignore them for compare/apply by default, with a `--mtime` option to
use the mtime data.
Keeping the legacy behaviour for backwards compatibility, but adding a
`--no-mtime` option to ignore mtimes when saving felt like a reasonable
way of making this happen, but something about it doesn't feel great.
Maybe I just didn't figure out how to make the documentation clear
enough. ¯\_(ツ)_/¯
Diffstat (limited to 'src/metastore.c')
-rw-r--r-- | src/metastore.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/metastore.c b/src/metastore.c index 2bc2a89..bc5787e 100644 --- a/src/metastore.c +++ b/src/metastore.c @@ -43,7 +43,7 @@ /* metastore settings */ static struct metasettings settings = { .metafile = METAFILE, - .do_mtime = false, + .do_mtime = 0, .do_emptydirs = false, .do_removeemptydirs = false, .do_git = false, @@ -286,7 +286,7 @@ compare_fix(struct metaentry *real, struct metaentry *stored, int cmp) * recreating them. */ static void -fixup_emptydirs(void) +fixup_emptydirs(int do_mtime) { struct metaentry *entry; struct metaentry *cur; @@ -364,7 +364,7 @@ fixup_emptydirs(void) } msg(MSG_QUIET, "ok\n"); - new = mentry_create(cur->path); + new = mentry_create(cur->path, do_mtime >= 0); if (!new) { msg(MSG_QUIET, "Failed to get metadata for %s\n", cur->path); continue; @@ -459,6 +459,7 @@ usage(const char *arg0, const char *message) " -v, --verbose Print more verbose messages\n" " -q, --quiet Print less verbose messages\n" " -m, --mtime Also take mtime into account for diff or apply\n" +" -M, --no-mtime Do not save mtime into metadata\n" " -e, --empty-dirs Recreate missing empty directories\n" " -E, --remove-empty-dirs Remove extra empty directories\n" " -g, --git Do not omit .git directories\n" @@ -480,6 +481,7 @@ static struct option long_options[] = { { "verbose", no_argument, NULL, 'v' }, { "quiet", no_argument, NULL, 'q' }, { "mtime", no_argument, NULL, 'm' }, + { "no-mtime", no_argument, NULL, 'M' }, { "empty-dirs", no_argument, NULL, 'e' }, { "remove-empty-dirs", no_argument, NULL, 'E' }, { "git", no_argument, NULL, 'g' }, @@ -501,7 +503,7 @@ main(int argc, char **argv) i = 0; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "csadVhvqmeEgf:r:", + c = getopt_long(argc, argv, "csadVhvqmMeEgf:r:", long_options, &option_index); if (c == -1) break; @@ -514,7 +516,8 @@ main(int argc, char **argv) case 'h': /* help */ action |= ACTION_HELP; i++; break; case 'v': /* verbose */ adjust_verbosity(1); break; case 'q': /* quiet */ adjust_verbosity(-1); break; - case 'm': /* mtime */ settings.do_mtime = true; break; + case 'm': /* mtime */ settings.do_mtime = 1; break; + case 'M': /* no-mtime */ settings.do_mtime = -1; break; case 'e': /* empty-dirs */ settings.do_emptydirs = true; break; case 'E': /* remove-empty-dirs */ settings.do_removeemptydirs = true; break; @@ -577,7 +580,7 @@ main(int argc, char **argv) case ACTION_APPLY: mentries_compare(real, stored, compare_fix, &settings); if (settings.do_emptydirs) - fixup_emptydirs(); + fixup_emptydirs(settings.do_mtime); if (settings.do_removeemptydirs) fixup_newemptydirs(); break; |