summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog6
-rw-r--r--metaentry.c55
-rw-r--r--metaentry.h2
-rw-r--r--metastore.15
-rw-r--r--metastore.c25
5 files changed, 81 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog
index 31775e5..074bf50 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+metastore (1:20120210) unstable; urgency=low
+
+ * Add option preventing metastore from omitting .git directories.
+
+ -- Przemyslaw Pawelczyk <przemoc@gmail.com> Fri, 10 Feb 2012 01:23:47 +0100
+
metastore (1+20080623+debian-2) unstable; urgency=low
* New maintainer (closes: #540588).
diff --git a/metaentry.c b/metaentry.c
index a557a93..79db236 100644
--- a/metaentry.c
+++ b/metaentry.c
@@ -347,12 +347,58 @@ mentries_recurse(const char *path, struct metahash *mhash)
while ((dent = readdir(dir))) {
if (!strcmp(dent->d_name, ".") ||
+ !strcmp(dent->d_name, ".."))
+ continue;
+ snprintf(tpath, PATH_MAX, "%s/%s", path, dent->d_name);
+ tpath[PATH_MAX - 1] = '\0';
+ mentries_recurse(tpath, mhash);
+ }
+
+ closedir(dir);
+ }
+}
+
+/* Internal function for the recursive path walk ignoring .git dirs */
+static void
+mentries_recurse_wo_git(const char *path, struct metahash *mhash)
+{
+ struct stat sbuf;
+ struct metaentry *mentry;
+ char tpath[PATH_MAX];
+ DIR *dir;
+ struct dirent *dent;
+
+ if (!path)
+ return;
+
+ if (lstat(path, &sbuf)) {
+ msg(MSG_ERROR, "lstat failed for %s: %s\n",
+ path, strerror(errno));
+ return;
+ }
+
+ mentry = mentry_create(path);
+ if (!mentry)
+ return;
+
+ mentry_insert(mentry, mhash);
+
+ if (S_ISDIR(sbuf.st_mode)) {
+ dir = opendir(path);
+ if (!dir) {
+ msg(MSG_ERROR, "opendir failed for %s: %s\n",
+ path, strerror(errno));
+ return;
+ }
+
+ while ((dent = readdir(dir))) {
+ if (!strcmp(dent->d_name, ".") ||
!strcmp(dent->d_name, "..") ||
!strcmp(dent->d_name, ".git"))
continue;
snprintf(tpath, PATH_MAX, "%s/%s", path, dent->d_name);
tpath[PATH_MAX - 1] = '\0';
- mentries_recurse(tpath, mhash);
+ mentries_recurse_wo_git(tpath, mhash);
}
closedir(dir);
@@ -361,13 +407,16 @@ mentries_recurse(const char *path, struct metahash *mhash)
/* Recurses opath and adds metadata entries to the metaentry list */
void
-mentries_recurse_path(const char *opath, struct metahash **mhash)
+mentries_recurse_path(const char *opath, struct metahash **mhash, bool git)
{
char *path = normalize_path(opath);
if (!(*mhash))
*mhash = mhash_alloc();
- mentries_recurse(path, *mhash);
+ if (git)
+ mentries_recurse(path, *mhash);
+ else
+ mentries_recurse_wo_git(path, *mhash);
free(path);
}
diff --git a/metaentry.h b/metaentry.h
index fe3351a..3b2f2a1 100644
--- a/metaentry.h
+++ b/metaentry.h
@@ -52,7 +52,7 @@ struct metahash {
struct metaentry *mentry_create(const char *path);
/* Recurses opath and adds metadata entries to the metaentry list */
-void mentries_recurse_path(const char *opath, struct metahash **mhash);
+void mentries_recurse_path(const char *opath, struct metahash **mhash, bool git);
/* Stores a metaentry list to a file */
void mentries_tofile(const struct metahash *mhash, const char *path);
diff --git a/metastore.1 b/metastore.1
index 316f4b4..5a7e1ee 100644
--- a/metastore.1
+++ b/metastore.1
@@ -1,4 +1,4 @@
-.TH metastore "1" "May 2007"
+.TH metastore "1" "February 2012"
.\"
.SH NAME
metastore \- stores and restores filesystem metadata
@@ -48,6 +48,9 @@ empty directories are not tracked (e.g. by git or cvs).
Only works in combination with the \fBapply\fR option.
This is currently an experimental feature.
.TP
+.B -g, --git
+Prevents metastore from omitting .git directories.
+.TP
.B -f <file>, --file <file>
Causes the metadata to be saved, read from the specified file rather
than ./.metadata.
diff --git a/metastore.c b/metastore.c
index 8aad770..d3864f4 100644
--- a/metastore.c
+++ b/metastore.c
@@ -41,6 +41,9 @@ static bool do_mtime = false;
/* Used to indicate whether empty dirs should be recreated */
static bool do_emptydirs = false;
+/* Used to indicate whether .git dirs should be processed */
+static bool do_git = false;
+
/* Used to create lists of dirs / other files which are missing in the fs */
static struct metaentry *missingdirs = NULL;
static struct metaentry *missingothers = NULL;
@@ -343,6 +346,7 @@ usage(const char *arg0, const char *message)
" -q, --quiet\t\tPrint less verbose messages\n"
" -m, --mtime\t\tAlso take mtime into account for diff or apply\n"
" -e, --empty-dirs\tRecreate missing empty directories (experimental)\n"
+ " -g, --git\t\tDo not omit .git directories\n"
" -f, --file <file>\tSet metadata file\n"
);
@@ -359,6 +363,7 @@ static struct option long_options[] = {
{"quiet", 0, 0, 0},
{"mtime", 0, 0, 0},
{"empty-dirs", 0, 0, 0},
+ {"git", 0, 0, 0},
{"file", required_argument, 0, 0},
{0, 0, 0, 0}
};
@@ -376,7 +381,7 @@ main(int argc, char **argv, char **envp)
i = 0;
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "csahvqmef:",
+ c = getopt_long(argc, argv, "csahvqmegf:",
long_options, &option_index);
if (c == -1)
break;
@@ -394,6 +399,9 @@ main(int argc, char **argv, char **envp)
} else if (!strcmp("empty-dirs",
long_options[option_index].name)) {
do_emptydirs = true;
+ } else if (!strcmp("git",
+ long_options[option_index].name)) {
+ do_git = true;
} else if (!strcmp("file",
long_options[option_index].name)) {
metafile = optarg;
@@ -430,6 +438,9 @@ main(int argc, char **argv, char **envp)
case 'e':
do_emptydirs = true;
break;
+ case 'g':
+ do_git = true;
+ break;
case 'f':
metafile = optarg;
break;
@@ -458,9 +469,9 @@ main(int argc, char **argv, char **envp)
if (optind < argc) {
while (optind < argc)
- mentries_recurse_path(argv[optind++], &real);
+ mentries_recurse_path(argv[optind++], &real, do_git);
} else {
- mentries_recurse_path(".", &real);
+ mentries_recurse_path(".", &real, do_git);
}
if (!real) {
@@ -475,9 +486,9 @@ main(int argc, char **argv, char **envp)
case ACTION_SAVE:
if (optind < argc) {
while (optind < argc)
- mentries_recurse_path(argv[optind++], &real);
+ mentries_recurse_path(argv[optind++], &real, do_git);
} else {
- mentries_recurse_path(".", &real);
+ mentries_recurse_path(".", &real, do_git);
}
if (!real) {
@@ -499,9 +510,9 @@ main(int argc, char **argv, char **envp)
if (optind < argc) {
while (optind < argc)
- mentries_recurse_path(argv[optind++], &real);
+ mentries_recurse_path(argv[optind++], &real, do_git);
} else {
- mentries_recurse_path(".", &real);
+ mentries_recurse_path(".", &real, do_git);
}
if (!real) {