Make git-mailinfo a builtin
[jc: with a bit of constness tightening] Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
e690e84315
commit
34488e3c37
14
Makefile
14
Makefile
@ -151,7 +151,7 @@ PROGRAMS = \
|
|||||||
git-checkout-index$X git-clone-pack$X \
|
git-checkout-index$X git-clone-pack$X \
|
||||||
git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
|
git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \
|
||||||
git-hash-object$X git-index-pack$X git-local-fetch$X \
|
git-hash-object$X git-index-pack$X git-local-fetch$X \
|
||||||
git-mailinfo$X git-merge-base$X \
|
git-merge-base$X \
|
||||||
git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
|
git-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \
|
||||||
git-peek-remote$X git-prune-packed$X git-receive-pack$X \
|
git-peek-remote$X git-prune-packed$X git-receive-pack$X \
|
||||||
git-send-pack$X git-shell$X \
|
git-send-pack$X git-shell$X \
|
||||||
@ -166,7 +166,7 @@ PROGRAMS = \
|
|||||||
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
|
BUILT_INS = git-log$X git-whatchanged$X git-show$X \
|
||||||
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
|
git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
|
||||||
git-grep$X git-add$X git-rm$X git-rev-list$X \
|
git-grep$X git-add$X git-rm$X git-rev-list$X \
|
||||||
git-check-ref-format$X git-rev-parse$X \
|
git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
|
||||||
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
|
git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
|
||||||
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
|
git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
|
||||||
git-read-tree$X git-commit-tree$X git-write-tree$X \
|
git-read-tree$X git-commit-tree$X git-write-tree$X \
|
||||||
@ -223,7 +223,7 @@ BUILTIN_OBJS = \
|
|||||||
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
|
builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
|
||||||
builtin-tar-tree.o builtin-upload-tar.o \
|
builtin-tar-tree.o builtin-upload-tar.o \
|
||||||
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
|
builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
|
||||||
builtin-read-tree.o builtin-commit-tree.o \
|
builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
|
||||||
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
|
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
|
||||||
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
|
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
|
||||||
builtin-cat-file.o builtin-mailsplit.o
|
builtin-cat-file.o builtin-mailsplit.o
|
||||||
@ -379,9 +379,7 @@ ifdef NEEDS_LIBICONV
|
|||||||
else
|
else
|
||||||
ICONV_LINK =
|
ICONV_LINK =
|
||||||
endif
|
endif
|
||||||
LIB_4_ICONV = $(ICONV_LINK) -liconv
|
LIBS += $(ICONV_LINK) -liconv
|
||||||
else
|
|
||||||
LIB_4_ICONV =
|
|
||||||
endif
|
endif
|
||||||
ifdef NEEDS_SOCKET
|
ifdef NEEDS_SOCKET
|
||||||
LIBS += -lsocket
|
LIBS += -lsocket
|
||||||
@ -564,10 +562,6 @@ $(SIMPLE_PROGRAMS) : git-%$X : %.o
|
|||||||
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
|
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
|
||||||
$(LIB_FILE) $(SIMPLE_LIB)
|
$(LIB_FILE) $(SIMPLE_LIB)
|
||||||
|
|
||||||
git-mailinfo$X: mailinfo.o $(LIB_FILE)
|
|
||||||
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
|
|
||||||
$(LIB_FILE) $(SIMPLE_LIB) $(LIB_4_ICONV)
|
|
||||||
|
|
||||||
git-local-fetch$X: fetch.o
|
git-local-fetch$X: fetch.o
|
||||||
git-ssh-fetch$X: rsh.o fetch.o
|
git-ssh-fetch$X: rsh.o fetch.o
|
||||||
git-ssh-upload$X: rsh.o
|
git-ssh-upload$X: rsh.o
|
||||||
|
@ -12,11 +12,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "builtin.h"
|
||||||
|
|
||||||
static FILE *cmitmsg, *patchfile;
|
static FILE *cmitmsg, *patchfile, *fin, *fout;
|
||||||
|
|
||||||
static int keep_subject = 0;
|
static int keep_subject = 0;
|
||||||
static char *metainfo_charset = NULL;
|
static const char *metainfo_charset = NULL;
|
||||||
static char line[1000];
|
static char line[1000];
|
||||||
static char date[1000];
|
static char date[1000];
|
||||||
static char name[1000];
|
static char name[1000];
|
||||||
@ -49,7 +50,7 @@ static int bogus_from(char *line)
|
|||||||
|
|
||||||
/* This is fallback, so do not bother if we already have an
|
/* This is fallback, so do not bother if we already have an
|
||||||
* e-mail address.
|
* e-mail address.
|
||||||
*/
|
*/
|
||||||
if (*email)
|
if (*email)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -322,13 +323,13 @@ static char *cleanup_subject(char *subject)
|
|||||||
if (remove <= len *2) {
|
if (remove <= len *2) {
|
||||||
subject = p+1;
|
subject = p+1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
eatspace(subject);
|
eatspace(subject);
|
||||||
return subject;
|
return subject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup_space(char *buf)
|
static void cleanup_space(char *buf)
|
||||||
{
|
{
|
||||||
@ -648,7 +649,7 @@ static void handle_info(void)
|
|||||||
cleanup_space(email);
|
cleanup_space(email);
|
||||||
cleanup_space(sub);
|
cleanup_space(sub);
|
||||||
|
|
||||||
printf("Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n",
|
fprintf(fout, "Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n",
|
||||||
name, email, sub, date);
|
name, email, sub, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,7 +686,7 @@ static int handle_commit_msg(int *seen)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
fputs(line, cmitmsg);
|
fputs(line, cmitmsg);
|
||||||
} while (fgets(line, sizeof(line), stdin) != NULL);
|
} while (fgets(line, sizeof(line), fin) != NULL);
|
||||||
fclose(cmitmsg);
|
fclose(cmitmsg);
|
||||||
cmitmsg = NULL;
|
cmitmsg = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
@ -706,7 +707,7 @@ static void handle_patch(void)
|
|||||||
decode_transfer_encoding(line);
|
decode_transfer_encoding(line);
|
||||||
fputs(line, patchfile);
|
fputs(line, patchfile);
|
||||||
patch_lines++;
|
patch_lines++;
|
||||||
} while (fgets(line, sizeof(line), stdin) != NULL);
|
} while (fgets(line, sizeof(line), fin) != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* multipart boundary and transfer encoding are set up for us, and we
|
/* multipart boundary and transfer encoding are set up for us, and we
|
||||||
@ -719,7 +720,7 @@ static int handle_multipart_one_part(int *seen)
|
|||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), stdin) != NULL) {
|
while (fgets(line, sizeof(line), fin) != NULL) {
|
||||||
again:
|
again:
|
||||||
n++;
|
n++;
|
||||||
if (is_multipart_boundary(line))
|
if (is_multipart_boundary(line))
|
||||||
@ -740,7 +741,7 @@ static void handle_multipart_body(void)
|
|||||||
int part_num = 0;
|
int part_num = 0;
|
||||||
|
|
||||||
/* Skip up to the first boundary */
|
/* Skip up to the first boundary */
|
||||||
while (fgets(line, sizeof(line), stdin) != NULL)
|
while (fgets(line, sizeof(line), fin) != NULL)
|
||||||
if (is_multipart_boundary(line)) {
|
if (is_multipart_boundary(line)) {
|
||||||
part_num = 1;
|
part_num = 1;
|
||||||
break;
|
break;
|
||||||
@ -749,7 +750,7 @@ static void handle_multipart_body(void)
|
|||||||
return;
|
return;
|
||||||
/* We are on boundary line. Start slurping the subhead. */
|
/* We are on boundary line. Start slurping the subhead. */
|
||||||
while (1) {
|
while (1) {
|
||||||
int hdr = read_one_header_line(line, sizeof(line), stdin);
|
int hdr = read_one_header_line(line, sizeof(line), fin);
|
||||||
if (!hdr) {
|
if (!hdr) {
|
||||||
if (handle_multipart_one_part(&seen) < 0)
|
if (handle_multipart_one_part(&seen) < 0)
|
||||||
return;
|
return;
|
||||||
@ -781,10 +782,45 @@ static void handle_body(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
|
||||||
|
const char *msg, const char *patch)
|
||||||
|
{
|
||||||
|
keep_subject = ks;
|
||||||
|
metainfo_charset = encoding;
|
||||||
|
fin = in;
|
||||||
|
fout = out;
|
||||||
|
|
||||||
|
cmitmsg = fopen(msg, "w");
|
||||||
|
if (!cmitmsg) {
|
||||||
|
perror(msg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
patchfile = fopen(patch, "w");
|
||||||
|
if (!patchfile) {
|
||||||
|
perror(patch);
|
||||||
|
fclose(cmitmsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
while (1) {
|
||||||
|
int hdr = read_one_header_line(line, sizeof(line), fin);
|
||||||
|
if (!hdr) {
|
||||||
|
if (multipart_boundary[0])
|
||||||
|
handle_multipart_body();
|
||||||
|
else
|
||||||
|
handle_body();
|
||||||
|
handle_info();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
check_header_line(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const char mailinfo_usage[] =
|
static const char mailinfo_usage[] =
|
||||||
"git-mailinfo [-k] [-u | --encoding=<encoding>] msg patch <mail >info";
|
"git-mailinfo [-k] [-u | --encoding=<encoding>] msg patch <mail >info";
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int cmd_mailinfo(int argc, const char **argv, char **envp)
|
||||||
{
|
{
|
||||||
/* NEEDSWORK: might want to do the optional .git/ directory
|
/* NEEDSWORK: might want to do the optional .git/ directory
|
||||||
* discovery
|
* discovery
|
||||||
@ -805,27 +841,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage(mailinfo_usage);
|
usage(mailinfo_usage);
|
||||||
cmitmsg = fopen(argv[1], "w");
|
|
||||||
if (!cmitmsg) {
|
return !!mailinfo(stdin, stdout, keep_subject, metainfo_charset, argv[1], argv[2]);
|
||||||
perror(argv[1]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
patchfile = fopen(argv[2], "w");
|
|
||||||
if (!patchfile) {
|
|
||||||
perror(argv[2]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
while (1) {
|
|
||||||
int hdr = read_one_header_line(line, sizeof(line), stdin);
|
|
||||||
if (!hdr) {
|
|
||||||
if (multipart_boundary[0])
|
|
||||||
handle_multipart_body();
|
|
||||||
else
|
|
||||||
handle_body();
|
|
||||||
handle_info();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
check_header_line(line);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef BUILTIN_H
|
#ifndef BUILTIN_H
|
||||||
#define BUILTIN_H
|
#define BUILTIN_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
#ifndef PATH_MAX
|
||||||
# define PATH_MAX 4096
|
# define PATH_MAX 4096
|
||||||
#endif
|
#endif
|
||||||
@ -51,4 +53,7 @@ extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
|
|||||||
|
|
||||||
extern int cmd_mailsplit(int argc, const char **argv, char **envp);
|
extern int cmd_mailsplit(int argc, const char **argv, char **envp);
|
||||||
extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
|
extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
|
||||||
|
|
||||||
|
extern int cmd_mailinfo(int argc, const char **argv, char **envp);
|
||||||
|
extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);
|
||||||
#endif
|
#endif
|
||||||
|
3
git.c
3
git.c
@ -180,7 +180,8 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
|
|||||||
{ "cat-file", cmd_cat_file },
|
{ "cat-file", cmd_cat_file },
|
||||||
{ "rev-parse", cmd_rev_parse },
|
{ "rev-parse", cmd_rev_parse },
|
||||||
{ "write-tree", cmd_write_tree },
|
{ "write-tree", cmd_write_tree },
|
||||||
{ "mailsplit", cmd_mailsplit }
|
{ "mailsplit", cmd_mailsplit },
|
||||||
|
{ "mailinfo", cmd_mailinfo }
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user