Merge part of 'js/fmt-patch' for RFC2822 dates into 'sp/reflog'
authorJunio C Hamano <junkio@cox.net>
Fri, 19 May 2006 22:25:57 +0000 (15:25 -0700)
committerJunio C Hamano <junkio@cox.net>
Fri, 19 May 2006 22:25:57 +0000 (15:25 -0700)
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 ;-).

1  2 
builtin.h
cache.h
commit.c
git.c
log-tree.c

diff --combined 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
+++ 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
+++ 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);
        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;
        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;
                if (hdr) {
                        if (linelen == 1) {
                                hdr = 0;
-                               if (fmt != CMIT_FMT_ONELINE)
+                               if ((fmt != CMIT_FMT_ONELINE) && !subject)
                                        buf[offset++] = '\n';
                                continue;
                        }
                        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
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -8,6 -8,7 +8,6 @@@
  #include <errno.h>
  #include <limits.h>
  #include <stdarg.h>
 -#include <sys/ioctl.h>
  #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
@@@ -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];
  
        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;
        }
  
        /*
         * 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;
  }