~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to merge-base.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20070422133105-xg8fnm18r2cxcbg1
Tags: upstream-1.5.1.2
ImportĀ upstreamĀ versionĀ 1.5.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdlib.h>
2
 
#include "cache.h"
3
 
#include "commit.h"
4
 
 
5
 
static int show_all;
6
 
 
7
 
static int merge_base(struct commit *rev1, struct commit *rev2)
8
 
{
9
 
        struct commit_list *result = get_merge_bases(rev1, rev2, 0);
10
 
 
11
 
        if (!result)
12
 
                return 1;
13
 
 
14
 
        while (result) {
15
 
                printf("%s\n", sha1_to_hex(result->item->object.sha1));
16
 
                if (!show_all)
17
 
                        return 0;
18
 
                result = result->next;
19
 
        }
20
 
 
21
 
        return 0;
22
 
}
23
 
 
24
 
static const char merge_base_usage[] =
25
 
"git-merge-base [--all] <commit-id> <commit-id>";
26
 
 
27
 
int main(int argc, char **argv)
28
 
{
29
 
        struct commit *rev1, *rev2;
30
 
        unsigned char rev1key[20], rev2key[20];
31
 
 
32
 
        setup_git_directory();
33
 
        git_config(git_default_config);
34
 
 
35
 
        while (1 < argc && argv[1][0] == '-') {
36
 
                char *arg = argv[1];
37
 
                if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
38
 
                        show_all = 1;
39
 
                else
40
 
                        usage(merge_base_usage);
41
 
                argc--; argv++;
42
 
        }
43
 
        if (argc != 3)
44
 
                usage(merge_base_usage);
45
 
        if (get_sha1(argv[1], rev1key))
46
 
                die("Not a valid object name %s", argv[1]);
47
 
        if (get_sha1(argv[2], rev2key))
48
 
                die("Not a valid object name %s", argv[2]);
49
 
        rev1 = lookup_commit_reference(rev1key);
50
 
        rev2 = lookup_commit_reference(rev2key);
51
 
        if (!rev1 || !rev2)
52
 
                return 1;
53
 
        return merge_base(rev1, rev2);
54
 
}