#include "git-compat-util.h"
+#include "bloom.h"
#include "builtin.h"
+#include "commit-graph.h"
#include "commit.h"
#include "config.h"
#include "diff.h"
struct last_modified_entry {
struct hashmap_entry hashent;
struct object_id oid;
+ struct bloom_key key;
const char path[FLEX_ARRAY];
};
static void last_modified_release(struct last_modified *lm)
{
+ struct hashmap_iter iter;
+ struct last_modified_entry *ent;
+
+ hashmap_for_each_entry(&lm->paths, &iter, ent, hashent)
+ bloom_key_clear(&ent->key);
+
hashmap_clear_and_free(&lm->paths, struct last_modified_entry, hashent);
release_revisions(&lm->rev);
}
FLEX_ALLOC_STR(ent, path, path);
oidcpy(&ent->oid, &p->two->oid);
+ if (lm->rev.bloom_filter_settings)
+ bloom_key_fill(&ent->key, path, strlen(path),
+ lm->rev.bloom_filter_settings);
hashmap_entry_init(&ent->hashent, strhash(ent->path));
hashmap_add(&lm->paths, &ent->hashent);
}
last_modified_emit(data->lm, path, data->commit);
hashmap_remove(&data->lm->paths, &ent->hashent, path);
+ bloom_key_clear(&ent->key);
free(ent);
}
}
}
+static bool maybe_changed_path(struct last_modified *lm, struct commit *origin)
+{
+ struct bloom_filter *filter;
+ struct last_modified_entry *ent;
+ struct hashmap_iter iter;
+
+ if (!lm->rev.bloom_filter_settings)
+ return true;
+
+ if (commit_graph_generation(origin) == GENERATION_NUMBER_INFINITY)
+ return true;
+
+ filter = get_bloom_filter(lm->rev.repo, origin);
+ if (!filter)
+ return true;
+
+ hashmap_for_each_entry(&lm->paths, &iter, ent, hashent) {
+ if (bloom_filter_contains(filter, &ent->key,
+ lm->rev.bloom_filter_settings))
+ return true;
+ }
+ return false;
+}
+
static int last_modified_run(struct last_modified *lm)
{
struct last_modified_callback_data data = { .lm = lm };
&data.commit->object.oid, "",
&lm->rev.diffopt);
diff_flush(&lm->rev.diffopt);
- } else {
- log_tree_commit(&lm->rev, data.commit);
+
+ break;
}
+
+ if (!maybe_changed_path(lm, data.commit))
+ continue;
+
+ log_tree_commit(&lm->rev, data.commit);
}
return 0;
return argc;
}
+ lm->rev.bloom_filter_settings = get_bloom_filter_settings(lm->rev.repo);
+
if (populate_paths_from_revs(lm) < 0)
return error(_("unable to setup last-modified"));