32
#include "promisor-remote.h"
33
#include "revision.h"
34
#include "strmap.h"
35
+#include "submodule-config.h"
36
#include "submodule.h"
37
#include "tree.h"
38
#include "unpack-trees.h"
1500
xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
1501
oid_to_hex(&a->object.oid));
1502
repo_init_revisions(repo, &revs, NULL);
1502
- rev_opts.submodule = path;
1503
/* FIXME: can't handle linked worktrees in submodules yet */
1504
revs.single_worktree = path != NULL;
1505
setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
1509
die("revision walk setup failed");
1510
while ((commit = get_revision(&revs)) != NULL) {
1511
struct object *o = &(commit->object);
1512
- if (in_merge_bases(b, commit))
1512
+ if (repo_in_merge_bases(repo, b, commit))
1513
add_object_array(o, NULL, &merges);
1514
}
1515
reset_revision_walk();
1524
contains_another = 0;
1525
for (j = 0; j < merges.nr; j++) {
1526
struct commit *m2 = (struct commit *) merges.objects[j].item;
1527
- if (i != j && in_merge_bases(m2, m1)) {
1527
+ if (i != j && repo_in_merge_bases(repo, m2, m1)) {
1528
contains_another = 1;
1529
break;
1530
}
1545
const struct object_id *b,
1546
struct object_id *result)
1547
{
1548
+ struct repository subrepo;
1549
+ struct strbuf sb = STRBUF_INIT;
1550
+ int ret = 0;
1551
struct commit *commit_o, *commit_a, *commit_b;
1552
int parent_count;
1553
struct object_array merges;
1551
- struct strbuf sb = STRBUF_INIT;
1554
1555
int i;
1556
int search = !opt->priv->call_depth;
1566
if (is_null_oid(b))
1567
return 0;
1568
1569
+ /*
1570
+ * NEEDSWORK: Remove this when all submodule object accesses are
1571
+ * through explicitly specified repositores.
1572
+ */
1573
if (add_submodule_odb(path)) {
1574
path_msg(opt, path, 0,
1575
_("Failed to merge submodule %s (not checked out)"),
1577
return 0;
1578
}
1579
1574
- if (!(commit_o = lookup_commit_reference(opt->repo, o)) ||
1575
- !(commit_a = lookup_commit_reference(opt->repo, a)) ||
1576
- !(commit_b = lookup_commit_reference(opt->repo, b))) {
1580
+ if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1581
+ path_msg(opt, path, 0,
1582
+ _("Failed to merge submodule %s (not checked out)"),
1583
+ path);
1584
+ return 0;
1585
+ }
1586
+
1587
+ if (!(commit_o = lookup_commit_reference(&subrepo, o)) ||
1588
+ !(commit_a = lookup_commit_reference(&subrepo, a)) ||
1589
+ !(commit_b = lookup_commit_reference(&subrepo, b))) {
1590
path_msg(opt, path, 0,
1591
_("Failed to merge submodule %s (commits not present)"),
1592
path);
1580
- return 0;
1593
+ goto cleanup;
1594
}
1595
1596
/* check whether both changes are forward */
1584
- if (!in_merge_bases(commit_o, commit_a) ||
1585
- !in_merge_bases(commit_o, commit_b)) {
1597
+ if (!repo_in_merge_bases(&subrepo, commit_o, commit_a) ||
1598
+ !repo_in_merge_bases(&subrepo, commit_o, commit_b)) {
1599
path_msg(opt, path, 0,
1600
_("Failed to merge submodule %s "
1601
"(commits don't follow merge-base)"),
1602
path);
1590
- return 0;
1603
+ goto cleanup;
1604
}
1605
1606
/* Case #1: a is contained in b or vice versa */
1594
- if (in_merge_bases(commit_a, commit_b)) {
1607
+ if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
1608
oidcpy(result, b);
1609
path_msg(opt, path, 1,
1610
_("Note: Fast-forwarding submodule %s to %s"),
1611
path, oid_to_hex(b));
1599
- return 1;
1612
+ ret = 1;
1613
+ goto cleanup;
1614
}
1601
- if (in_merge_bases(commit_b, commit_a)) {
1615
+ if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
1616
oidcpy(result, a);
1617
path_msg(opt, path, 1,
1618
_("Note: Fast-forwarding submodule %s to %s"),
1619
path, oid_to_hex(a));
1606
- return 1;
1620
+ ret = 1;
1621
+ goto cleanup;
1622
}
1623
1624
/*
1630
1631
/* Skip the search if makes no sense to the calling context. */
1632
if (!search)
1618
- return 0;
1633
+ goto cleanup;
1634
1635
/* find commit which merges them */
1621
- parent_count = find_first_merges(opt->repo, path, commit_a, commit_b,
1636
+ parent_count = find_first_merges(&subrepo, path, commit_a, commit_b,
1637
&merges);
1638
switch (parent_count) {
1639
case 0:
1667
}
1668
1669
object_array_clear(&merges);
1655
- return 0;
1670
+cleanup:
1671
+ repo_clear(&subrepo);
1672
+ return ret;
1673
}
1674
1675
static void initialize_attr_index(struct merge_options *opt)