Skip to content

Commit 84f8925

Browse files
stefanbellergitster
authored andcommitted
submodules: introduce check to see whether to touch a submodule
In later patches we introduce the --recurse-submodule flag for commands that modify the working directory, e.g. git-checkout. It is potentially expensive to check if a submodule needs an update, because a common theme to interact with submodules is to spawn a child process for each interaction. So let's introduce a function that checks if a submodule needs to be checked for an update before attempting the update. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf055e4 commit 84f8925

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

submodule.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,22 @@ void set_config_update_recurse_submodules(int value)
548548
config_update_recurse_submodules = value;
549549
}
550550

551+
int should_update_submodules(void)
552+
{
553+
return config_update_recurse_submodules == RECURSE_SUBMODULES_ON;
554+
}
555+
556+
const struct submodule *submodule_from_ce(const struct cache_entry *ce)
557+
{
558+
if (!S_ISGITLINK(ce->ce_mode))
559+
return NULL;
560+
561+
if (!should_update_submodules())
562+
return NULL;
563+
564+
return submodule_from_path(null_sha1, ce->name);
565+
}
566+
551567
static int has_remote(const char *refname, const struct object_id *oid,
552568
int flags, void *cb_data)
553569
{

submodule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ extern void show_submodule_inline_diff(FILE *f, const char *path,
6565
const struct diff_options *opt);
6666
extern void set_config_fetch_recurse_submodules(int value);
6767
extern void set_config_update_recurse_submodules(int value);
68+
/* Check if we want to update any submodule.*/
69+
extern int should_update_submodules(void);
70+
/*
71+
* Returns the submodule struct if the given ce entry is a submodule
72+
* and it should be updated. Returns NULL otherwise.
73+
*/
74+
extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
6875
extern void check_for_new_submodule_commits(unsigned char new_sha1[20]);
6976
extern int fetch_populated_submodules(const struct argv_array *options,
7077
const char *prefix, int command_line_option,

0 commit comments

Comments
 (0)