2018-10-18 00:13:26 +02:00
|
|
|
#ifndef COMMIT_REACH_H
|
|
|
|
#define COMMIT_REACH_H
|
2018-07-20 18:33:02 +02:00
|
|
|
|
commit-reach.h: add missing declarations (hdr-check)
Add the necessary #includes and forward declarations to allow the header
file to pass the 'hdr-check' target.
Note that, since this header includes the commit-slab implementation
header file (indirectly via commit-slab.h), some of the commit-slab
inline functions (e.g contains_cache_at_peek()) will not compile without
the complete type of 'struct commit'. Hence, we replace the forward
declaration of 'struct commit' with the an #include of the 'commit.h'
header file.
It is possible, using the 'commit-slab-{decl,impl}.h' files, to avoid
this inclusion of the 'commit.h' header. Commit a9f1f1f9f8 ("commit-slab.h:
code split", 2018-05-19) separated the commit-slab interface from its
implementation, to allow for the definition of a public commit-slab data
structure. This enabled us to avoid including the commit-slab implementation
in a header file, which could result in the replication of the commit-slab
functions in each compilation unit in which it was included.
Indeed, if you compile with optimizations disabled, then run this script:
$ cat -n dup-static.sh
1 #!/bin/sh
2
3 nm $1 | grep ' t ' | cut -d' ' -f3 | sort | uniq -c |
4 sort -rn | grep -v ' 1'
$
$ ./dup-static.sh git | grep contains
24 init_contains_cache_with_stride
24 init_contains_cache
24 contains_cache_peek
24 contains_cache_at_peek
24 contains_cache_at
24 clear_contains_cache
$
you will find 24 copies of the commit-slab routines for the contains_cache.
Of course, when you enable optimizations again, these duplicate static
functions (mostly) disappear. Compiling with gcc at -O2, leaves two static
functions, thus:
$ nm commit-reach.o | grep contains_cache
0000000000000870 t contains_cache_at_peek.isra.1.constprop.6
$ nm ref-filter.o | grep contains_cache
00000000000002b0 t clear_contains_cache.isra.14
$
However, using a shared 'contains_cache' would result in all six of the
above functions as external public functions in the git binary. At present,
only three of these functions are actually called, so the trade-off
seems to favour letting the compiler inline the commit-slab functions.
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-27 03:53:57 +02:00
|
|
|
#include "commit.h"
|
2018-07-20 18:33:08 +02:00
|
|
|
#include "commit-slab.h"
|
|
|
|
|
2018-07-20 18:33:02 +02:00
|
|
|
struct commit_list;
|
2018-07-20 18:33:08 +02:00
|
|
|
struct ref_filter;
|
commit-reach.h: add missing declarations (hdr-check)
Add the necessary #includes and forward declarations to allow the header
file to pass the 'hdr-check' target.
Note that, since this header includes the commit-slab implementation
header file (indirectly via commit-slab.h), some of the commit-slab
inline functions (e.g contains_cache_at_peek()) will not compile without
the complete type of 'struct commit'. Hence, we replace the forward
declaration of 'struct commit' with the an #include of the 'commit.h'
header file.
It is possible, using the 'commit-slab-{decl,impl}.h' files, to avoid
this inclusion of the 'commit.h' header. Commit a9f1f1f9f8 ("commit-slab.h:
code split", 2018-05-19) separated the commit-slab interface from its
implementation, to allow for the definition of a public commit-slab data
structure. This enabled us to avoid including the commit-slab implementation
in a header file, which could result in the replication of the commit-slab
functions in each compilation unit in which it was included.
Indeed, if you compile with optimizations disabled, then run this script:
$ cat -n dup-static.sh
1 #!/bin/sh
2
3 nm $1 | grep ' t ' | cut -d' ' -f3 | sort | uniq -c |
4 sort -rn | grep -v ' 1'
$
$ ./dup-static.sh git | grep contains
24 init_contains_cache_with_stride
24 init_contains_cache
24 contains_cache_peek
24 contains_cache_at_peek
24 contains_cache_at
24 clear_contains_cache
$
you will find 24 copies of the commit-slab routines for the contains_cache.
Of course, when you enable optimizations again, these duplicate static
functions (mostly) disappear. Compiling with gcc at -O2, leaves two static
functions, thus:
$ nm commit-reach.o | grep contains_cache
0000000000000870 t contains_cache_at_peek.isra.1.constprop.6
$ nm ref-filter.o | grep contains_cache
00000000000002b0 t clear_contains_cache.isra.14
$
However, using a shared 'contains_cache' would result in all six of the
above functions as external public functions in the git binary. At present,
only three of these functions are actually called, so the trade-off
seems to favour letting the compiler inline the commit-slab functions.
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-27 03:53:57 +02:00
|
|
|
struct object_id;
|
|
|
|
struct object_array;
|
2018-07-20 18:33:02 +02:00
|
|
|
|
2018-11-14 01:12:55 +01:00
|
|
|
struct commit_list *repo_get_merge_bases(struct repository *r,
|
|
|
|
struct commit *rev1,
|
|
|
|
struct commit *rev2);
|
|
|
|
struct commit_list *repo_get_merge_bases_many(struct repository *r,
|
|
|
|
struct commit *one, int n,
|
|
|
|
struct commit **twos);
|
2018-07-20 18:33:02 +02:00
|
|
|
/* To be used only when object flags after this call no longer matter */
|
2018-11-14 01:12:55 +01:00
|
|
|
struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
|
|
|
|
struct commit *one, int n,
|
|
|
|
struct commit **twos);
|
|
|
|
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
|
|
|
|
#define get_merge_bases(r1, r2) repo_get_merge_bases(the_repository, r1, r2)
|
|
|
|
#define get_merge_bases_many(one, n, two) repo_get_merge_bases_many(the_repository, one, n, two)
|
|
|
|
#define get_merge_bases_many_dirty(one, n, twos) repo_get_merge_bases_many_dirty(the_repository, one, n, twos)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct commit_list *get_octopus_merge_bases(struct commit_list *in);
|
2018-07-20 18:33:02 +02:00
|
|
|
|
|
|
|
int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
|
2018-11-14 01:12:56 +01:00
|
|
|
int repo_in_merge_bases(struct repository *r,
|
|
|
|
struct commit *commit,
|
|
|
|
struct commit *reference);
|
|
|
|
int repo_in_merge_bases_many(struct repository *r,
|
|
|
|
struct commit *commit,
|
|
|
|
int nr_reference, struct commit **reference);
|
|
|
|
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
|
|
|
|
#define in_merge_bases(c1, c2) repo_in_merge_bases(the_repository, c1, c2)
|
|
|
|
#define in_merge_bases_many(c1, n, cs) repo_in_merge_bases_many(the_repository, c1, n, cs)
|
|
|
|
#endif
|
2018-07-20 18:33:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Takes a list of commits and returns a new list where those
|
|
|
|
* have been removed that can be reached from other commits in
|
|
|
|
* the list. It is useful for, e.g., reducing the commits
|
|
|
|
* randomly thrown at the git-merge command and removing
|
|
|
|
* redundant commits that the user shouldn't have given to it.
|
|
|
|
*
|
|
|
|
* This function destroys the STALE bit of the commit objects'
|
|
|
|
* flags.
|
|
|
|
*/
|
|
|
|
struct commit_list *reduce_heads(struct commit_list *heads);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like `reduce_heads()`, except it replaces the list. Use this
|
|
|
|
* instead of `foo = reduce_heads(foo);` to avoid memory leaks.
|
|
|
|
*/
|
|
|
|
void reduce_heads_replace(struct commit_list **heads);
|
|
|
|
|
2018-07-20 18:33:06 +02:00
|
|
|
int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);
|
|
|
|
|
2018-07-20 18:33:08 +02:00
|
|
|
/*
|
|
|
|
* Unknown has to be "0" here, because that's the default value for
|
|
|
|
* contains_cache slab entries that have not yet been assigned.
|
|
|
|
*/
|
|
|
|
enum contains_result {
|
|
|
|
CONTAINS_UNKNOWN = 0,
|
|
|
|
CONTAINS_NO,
|
|
|
|
CONTAINS_YES
|
|
|
|
};
|
|
|
|
|
|
|
|
define_commit_slab(contains_cache, enum contains_result);
|
|
|
|
|
|
|
|
int commit_contains(struct ref_filter *filter, struct commit *commit,
|
|
|
|
struct commit_list *list, struct contains_cache *cache);
|
|
|
|
|
2018-07-20 18:33:13 +02:00
|
|
|
/*
|
|
|
|
* Determine if every commit in 'from' can reach at least one commit
|
|
|
|
* that is marked with 'with_flag'. As we traverse, use 'assign_flag'
|
|
|
|
* as a marker for commits that are already visited. Do not walk
|
2018-07-20 18:33:28 +02:00
|
|
|
* commits with date below 'min_commit_date' or generation below
|
|
|
|
* 'min_generation'.
|
2018-07-20 18:33:13 +02:00
|
|
|
*/
|
|
|
|
int can_all_from_reach_with_flag(struct object_array *from,
|
|
|
|
unsigned int with_flag,
|
|
|
|
unsigned int assign_flag,
|
2018-07-20 18:33:28 +02:00
|
|
|
time_t min_commit_date,
|
|
|
|
uint32_t min_generation);
|
2018-07-20 18:33:23 +02:00
|
|
|
int can_all_from_reach(struct commit_list *from, struct commit_list *to,
|
|
|
|
int commit_date_cutoff);
|
2018-07-20 18:33:13 +02:00
|
|
|
|
2018-11-02 14:14:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a list of commits containing the commits in the 'to' array
|
|
|
|
* that are reachable from at least one commit in the 'from' array.
|
|
|
|
* Also add the given 'flag' to each of the commits in the returned list.
|
|
|
|
*
|
|
|
|
* This method uses the PARENT1 and PARENT2 flags during its operation,
|
|
|
|
* so be sure these flags are not set before calling the method.
|
|
|
|
*/
|
|
|
|
struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
|
|
|
|
struct commit **to, int nr_to,
|
|
|
|
unsigned int reachable_flag);
|
|
|
|
|
2018-07-20 18:33:02 +02:00
|
|
|
#endif
|