3 #include "run-command.h"
5 int add_submodule_odb(const char *path
)
7 struct strbuf objects_directory
= STRBUF_INIT
;
8 struct alternate_object_database
*alt_odb
;
10 strbuf_addf(&objects_directory
, "%s/.git/objects/", path
);
11 if (!is_directory(objects_directory
.buf
))
14 /* avoid adding it twice */
15 for (alt_odb
= alt_odb_list
; alt_odb
; alt_odb
= alt_odb
->next
)
16 if (alt_odb
->name
- alt_odb
->base
== objects_directory
.len
&&
17 !strncmp(alt_odb
->base
, objects_directory
.buf
,
18 objects_directory
.len
))
21 alt_odb
= xmalloc(objects_directory
.len
+ 42 + sizeof(*alt_odb
));
22 alt_odb
->next
= alt_odb_list
;
23 strcpy(alt_odb
->base
, objects_directory
.buf
);
24 alt_odb
->name
= alt_odb
->base
+ objects_directory
.len
;
25 alt_odb
->name
[2] = '/';
26 alt_odb
->name
[40] = '\0';
27 alt_odb
->name
[41] = '\0';
28 alt_odb_list
= alt_odb
;
33 void show_submodule_summary(FILE *f
, const char *path
,
34 unsigned char one
[20], unsigned char two
[20],
35 const char *del
, const char *add
, const char *reset
)
37 struct strbuf sb
= STRBUF_INIT
;
38 const char *message
= NULL
;
40 if (add_submodule_odb(path
))
41 message
= "(not checked out)";
42 else if (is_null_sha1(one
))
43 message
= "(new submodule)";
44 else if (is_null_sha1(two
))
45 message
= "(submodule deleted)";
48 struct child_process child
;
49 struct strbuf range
= STRBUF_INIT
, git_dir
= STRBUF_INIT
;
50 const char* argv
[] = {
51 NULL
, "log", "--pretty=format: %m %s", "--left-right",
55 strbuf_addf(&range
, "%s...%s",
56 sha1_to_hex(one
), sha1_to_hex(two
));
57 strbuf_addf(&git_dir
, "--git-dir=%s/.git", path
);
58 argv
[0] = git_dir
.buf
;
60 memset(&child
, 0, sizeof(child
));
63 child
.out
= dup(fileno(f
));
64 child
.err
= dup(fileno(stderr
));
67 fprintf(f
, "Submodule %s %s:\n", path
, range
.buf
);
71 strbuf_release(&range
);
75 strbuf_addf(&sb
, "Submodule %s %s...%s %s\n", path
,
76 find_unique_abbrev(one
, DEFAULT_ABBREV
),
77 find_unique_abbrev(two
, DEFAULT_ABBREV
),
79 fprintf(f
, "%s", sb
.buf
);