From: Junio C Hamano Date: Fri, 19 May 2006 22:25:57 +0000 (-0700) Subject: Merge part of 'js/fmt-patch' for RFC2822 dates into 'sp/reflog' X-Git-Tag: v1.4.1-rc1~66^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6858d494926437ad7b7e9199ea39953eb90c7bab?ds=inline;hp=-c Merge part of 'js/fmt-patch' for RFC2822 dates into 'sp/reflog' An earlier patch from Shawn Pearce dependes on a change that is only in "next". I do not want to make this series hostage to the yet-to-graduate js/fmt-patch branch, but let's try fixing it by merging the early parts of the branch to see what happens. Right now, 'sp/reflog' will not be in "next" for now, so I won't have to regret this -- if this merge causes problem down the road merging I can always rebuild the topic branch ;-). --- 6858d494926437ad7b7e9199ea39953eb90c7bab diff --combined builtin.h index 7744f7d2f6,94dc0732f9..97e2464468 --- a/builtin.h +++ b/builtin.h @@@ -19,10 -19,6 +19,11 @@@ extern int cmd_version(int argc, const extern int cmd_whatchanged(int argc, const char **argv, char **envp); extern int cmd_show(int argc, const char **argv, char **envp); extern int cmd_log(int argc, const char **argv, char **envp); +extern int cmd_diff(int argc, const char **argv, char **envp); + extern int cmd_format_patch(int argc, const char **argv, char **envp); +extern int cmd_count_objects(int argc, const char **argv, char **envp); + +extern int cmd_push(int argc, const char **argv, char **envp); +extern int cmd_grep(int argc, const char **argv, char **envp); #endif diff --combined cache.h index 2386b95e00,f6c5909598..f01ca436e6 --- a/cache.h +++ b/cache.h @@@ -134,8 -134,6 +134,8 @@@ extern const char *setup_git_directory_ extern const char *setup_git_directory(void); extern const char *prefix_path(const char *prefix, int len, const char *path); extern const char *prefix_filename(const char *prefix, int len, const char *path); +extern void verify_filename(const char *prefix, const char *name); +extern void verify_non_filename(const char *prefix, const char *name); #define alloc_nr(x) (((x)+16)*3/2) @@@ -169,8 -167,7 +169,8 @@@ extern void rollback_index_file(struct /* Environment bits from configuration mechanism */ extern int trust_executable_bit; extern int assume_unchanged; -extern int only_use_symrefs; +extern int prefer_symlink_refs; +extern int log_all_ref_updates; extern int warn_ambiguous_refs; extern int diff_rename_limit_default; extern int shared_repository; @@@ -252,6 -249,7 +252,7 @@@ extern void *read_object_with_reference unsigned char *sha1_ret); const char *show_date(unsigned long time, int timezone); + const char *show_rfc2822_date(unsigned long time, int timezone); int parse_date(const char *date, char *buf, int bufsize); void datestamp(char *buf, int bufsize); unsigned long approxidate(const char *); @@@ -364,8 -362,4 +365,8 @@@ extern int receive_keep_pack(int fd[2] /* pager.c */ extern void setup_pager(void); +/* base85 */ +int decode_85(char *dst, char *line, int linelen); +void encode_85(char *buf, unsigned char *data, int bytes); + #endif /* CACHE_H */ diff --combined commit.c index 4a26070c13,42b44bba52..8317f6d26d --- a/commit.c +++ b/commit.c @@@ -22,33 -22,25 +22,34 @@@ struct sort_nod const char *commit_type = "commit"; +struct cmt_fmt_map { + const char *n; + size_t cmp_len; + enum cmit_fmt v; +} cmt_fmts[] = { + { "raw", 1, CMIT_FMT_RAW }, + { "medium", 1, CMIT_FMT_MEDIUM }, + { "short", 1, CMIT_FMT_SHORT }, ++ { "email", 1, CMIT_FMT_EMAIL }, + { "full", 5, CMIT_FMT_FULL }, + { "fuller", 5, CMIT_FMT_FULLER }, + { "oneline", 1, CMIT_FMT_ONELINE }, +}; + enum cmit_fmt get_commit_format(const char *arg) { - if (!*arg) + int i; + + if (!arg || !*arg) return CMIT_FMT_DEFAULT; - if (!strcmp(arg, "=raw")) - return CMIT_FMT_RAW; - if (!strcmp(arg, "=medium")) - return CMIT_FMT_MEDIUM; - if (!strcmp(arg, "=short")) - return CMIT_FMT_SHORT; - if (!strcmp(arg, "=full")) - return CMIT_FMT_FULL; - if (!strcmp(arg, "=fuller")) - return CMIT_FMT_FULLER; - if (!strcmp(arg, "=email")) - return CMIT_FMT_EMAIL; - if (!strcmp(arg, "=oneline")) - return CMIT_FMT_ONELINE; - die("invalid --pretty format"); + if (*arg == '=') + arg++; + for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) { + if (!strncmp(arg, cmt_fmts[i].n, cmt_fmts[i].cmp_len)) + return cmt_fmts[i].v; + } + + die("invalid --pretty format: %s", arg); } static struct commit *check_commit(struct object *obj, @@@ -438,6 -430,10 +439,10 @@@ static int add_user_info(const char *wh time = strtoul(date, &date, 10); tz = strtol(date, NULL, 10); + if (fmt == CMIT_FMT_EMAIL) { + what = "From"; + filler = ""; + } ret = sprintf(buf, "%s: %.*s%.*s\n", what, (fmt == CMIT_FMT_FULLER) ? 4 : 0, filler, namelen, line); @@@ -445,6 -441,10 +450,10 @@@ case CMIT_FMT_MEDIUM: ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz)); break; + case CMIT_FMT_EMAIL: + ret += sprintf(buf + ret, "Date: %s\n", + show_rfc2822_date(time, tz)); + break; case CMIT_FMT_FULLER: ret += sprintf(buf + ret, "%sDate: %s\n", what, show_date(time, tz)); break; @@@ -455,10 -455,12 +464,12 @@@ return ret; } - static int is_empty_line(const char *line, int len) + static int is_empty_line(const char *line, int *len_p) { + int len = *len_p; while (len && isspace(line[len-1])) len--; + *len_p = len; return !len; } @@@ -467,7 -469,8 +478,8 @@@ static int add_merge_info(enum cmit_fm struct commit_list *parent = commit->parents; int offset; - if ((fmt == CMIT_FMT_ONELINE) || !parent || !parent->next) + if ((fmt == CMIT_FMT_ONELINE) || (fmt == CMIT_FMT_EMAIL) || + !parent || !parent->next) return 0; offset = sprintf(buf, "Merge:"); @@@ -490,9 -493,15 +502,15 @@@ unsigned long pretty_print_commit(enum { int hdr = 1, body = 0; unsigned long offset = 0; - int indent = (fmt == CMIT_FMT_ONELINE) ? 0 : 4; + int indent = 4; int parents_shown = 0; const char *msg = commit->buffer; + const char *subject = NULL; + + if (fmt == CMIT_FMT_EMAIL) + subject = "Subject: [PATCH] "; + if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) + indent = 0; for (;;) { const char *line = msg; @@@ -516,7 -525,7 +534,7 @@@ if (hdr) { if (linelen == 1) { hdr = 0; - if (fmt != CMIT_FMT_ONELINE) + if ((fmt != CMIT_FMT_ONELINE) && !subject) buf[offset++] = '\n'; continue; } @@@ -554,20 -563,29 +572,29 @@@ continue; } - if (is_empty_line(line, linelen)) { + if (is_empty_line(line, &linelen)) { if (!body) continue; + if (subject) + continue; if (fmt == CMIT_FMT_SHORT) break; } else { body = 1; } + if (subject) { + int slen = strlen(subject); + memcpy(buf + offset, subject, slen); + offset += slen; + } memset(buf + offset, ' ', indent); memcpy(buf + offset + indent, line, linelen); offset += linelen + indent; + buf[offset++] = '\n'; if (fmt == CMIT_FMT_ONELINE) break; + subject = NULL; } while (offset && isspace(buf[offset-1])) offset--; diff --combined git.c index a94d9ee5a7,619c6654e4..84803a62e6 --- a/git.c +++ b/git.c @@@ -8,6 -8,7 +8,6 @@@ #include #include #include -#include #include "git-compat-util.h" #include "exec_cmd.h" @@@ -46,10 -47,7 +46,11 @@@ static void handle_internal_command(in { "log", cmd_log }, { "whatchanged", cmd_whatchanged }, { "show", cmd_show }, + { "push", cmd_push }, + { "fmt-patch", cmd_format_patch }, + { "count-objects", cmd_count_objects }, + { "diff", cmd_diff }, + { "grep", cmd_grep }, }; int i; diff --combined log-tree.c index b90ba6762a,aaf2b9423f..2bcf2dfaaa --- a/log-tree.c +++ b/log-tree.c @@@ -3,15 -3,6 +3,15 @@@ #include "commit.h" #include "log-tree.h" +static void show_parents(struct commit *commit, int abbrev) +{ + struct commit_list *p; + for (p = commit->parents; p ; p = p->next) { + struct commit *parent = p->item; + printf(" %s", diff_unique_abbrev(parent->object.sha1, abbrev)); + } +} + void show_log(struct rev_info *opt, struct log_info *log, const char *sep) { static char this_header[16384]; @@@ -23,10 -14,7 +23,10 @@@ opt->loginfo = NULL; if (!opt->verbose_header) { - puts(sha1_to_hex(commit->object.sha1)); + fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); + if (opt->parents) + show_parents(commit, abbrev_commit); + putchar('\n'); return; } @@@ -49,14 -37,20 +49,22 @@@ /* * Print header line of header.. */ - printf("%s%s", - opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", - diff_unique_abbrev(commit->object.sha1, abbrev_commit)); - if (opt->parents) - show_parents(commit, abbrev_commit); - if (parent) - printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit)); - putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + + if (opt->commit_format == CMIT_FMT_EMAIL) + printf("From %s Thu Apr 7 15:13:13 2005\n", + sha1_to_hex(commit->object.sha1)); + else { + printf("%s%s", + opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ", + diff_unique_abbrev(commit->object.sha1, abbrev_commit)); - if (parent) ++ if (opt->parents) ++ show_parents(commit, abbrev_commit); ++ if (parent) + printf(" (from %s)", + diff_unique_abbrev(parent->object.sha1, + abbrev_commit)); + putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n'); + } /* * And then the pretty-printed message itself @@@ -166,15 -160,18 +174,18 @@@ static int log_tree_diff(struct rev_inf int log_tree_commit(struct rev_info *opt, struct commit *commit) { struct log_info log; + int shown; log.commit = commit; log.parent = NULL; opt->loginfo = &log; - if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) { + shown = log_tree_diff(opt, commit, &log); + if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; show_log(opt, opt->loginfo, ""); + shown = 1; } opt->loginfo = NULL; - return 0; + return shown; }