Skip to content

Commit a762e51

Browse files
hvoigtgitster
authored andcommitted
Refactor submodule push check to use string list instead of integer
This allows us to tell the user which submodules have not been pushed. Additionally this is helpful when we want to automatically try to push submodules that have not been pushed. Signed-off-by: Heiko Voigt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bcc0a3e commit a762e51

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

submodule.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,19 @@ static void collect_submodules_from_diff(struct diff_queue_struct *q,
357357
void *data)
358358
{
359359
int i;
360-
int *needs_pushing = data;
360+
struct string_list *needs_pushing = data;
361361

362362
for (i = 0; i < q->nr; i++) {
363363
struct diff_filepair *p = q->queue[i];
364364
if (!S_ISGITLINK(p->two->mode))
365365
continue;
366-
if (submodule_needs_pushing(p->two->path, p->two->sha1)) {
367-
*needs_pushing = 1;
368-
break;
369-
}
366+
if (submodule_needs_pushing(p->two->path, p->two->sha1))
367+
string_list_insert(needs_pushing, p->two->path);
370368
}
371369
}
372370

373-
374-
static void commit_need_pushing(struct commit *commit, int *needs_pushing)
371+
static void find_unpushed_submodule_commits(struct commit *commit,
372+
struct string_list *needs_pushing)
375373
{
376374
struct rev_info rev;
377375

@@ -382,14 +380,15 @@ static void commit_need_pushing(struct commit *commit, int *needs_pushing)
382380
diff_tree_combined_merge(commit, 1, &rev);
383381
}
384382

385-
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name)
383+
int find_unpushed_submodules(unsigned char new_sha1[20],
384+
const char *remotes_name, struct string_list *needs_pushing)
386385
{
387386
struct rev_info rev;
388387
struct commit *commit;
389388
const char *argv[] = {NULL, NULL, "--not", "NULL", NULL};
390389
int argc = ARRAY_SIZE(argv) - 1;
391390
char *sha1_copy;
392-
int needs_pushing = 0;
391+
393392
struct strbuf remotes_arg = STRBUF_INIT;
394393

395394
strbuf_addf(&remotes_arg, "--remotes=%s", remotes_name);
@@ -401,14 +400,14 @@ int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remote
401400
if (prepare_revision_walk(&rev))
402401
die("revision walk setup failed");
403402

404-
while ((commit = get_revision(&rev)) && !needs_pushing)
405-
commit_need_pushing(commit, &needs_pushing);
403+
while ((commit = get_revision(&rev)) != NULL)
404+
find_unpushed_submodule_commits(commit, needs_pushing);
406405

407406
reset_revision_walk();
408407
free(sha1_copy);
409408
strbuf_release(&remotes_arg);
410409

411-
return needs_pushing;
410+
return needs_pushing->nr;
412411
}
413412

414413
static int is_submodule_commit_present(const char *path, unsigned char sha1[20])

submodule.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int fetch_populated_submodules(int num_options, const char **options,
2929
unsigned is_submodule_modified(const char *path, int ignore_untracked);
3030
int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],
3131
const unsigned char a[20], const unsigned char b[20], int search);
32-
int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name);
32+
int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name,
33+
struct string_list *needs_pushing);
3334

3435
#endif

transport.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "branch.h"
1212
#include "url.h"
1313
#include "submodule.h"
14+
#include "string-list.h"
1415

1516
/* rsync support */
1617

@@ -1000,6 +1001,20 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
10001001
transport->progress = force_progress || (verbosity >= 0 && isatty(2));
10011002
}
10021003

1004+
static void die_with_unpushed_submodules(struct string_list *needs_pushing)
1005+
{
1006+
int i;
1007+
1008+
fprintf(stderr, "The following submodule paths contain changes that can\n"
1009+
"not be found on any remote:\n");
1010+
for (i = 0; i < needs_pushing->nr; i++)
1011+
printf(" %s\n", needs_pushing->items[i].string);
1012+
1013+
string_list_clear(needs_pushing, 0);
1014+
1015+
die("Aborting.");
1016+
}
1017+
10031018
int transport_push(struct transport *transport,
10041019
int refspec_nr, const char **refspec, int flags,
10051020
int *nonfastforward)
@@ -1040,10 +1055,15 @@ int transport_push(struct transport *transport,
10401055

10411056
if ((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) && !is_bare_repository()) {
10421057
struct ref *ref = remote_refs;
1058+
struct string_list needs_pushing;
1059+
1060+
memset(&needs_pushing, 0, sizeof(struct string_list));
1061+
needs_pushing.strdup_strings = 1;
10431062
for (; ref; ref = ref->next)
10441063
if (!is_null_sha1(ref->new_sha1) &&
1045-
check_submodule_needs_pushing(ref->new_sha1,transport->remote->name))
1046-
die("There are unpushed submodules, aborting.");
1064+
find_unpushed_submodules(ref->new_sha1,
1065+
transport->remote->name, &needs_pushing))
1066+
die_with_unpushed_submodules(&needs_pushing);
10471067
}
10481068

10491069
push_ret = transport->push_refs(transport, remote_refs, flags);

0 commit comments

Comments
 (0)