simplify the "no changes added to commit" message
[gitweb.git] / builtin-log.c
index fedb0137bc5e3ba50ecb90ce560ce9ce9290d8df..a59b4acef1bc45f07f15e10c0501aa23de3eed7d 100644 (file)
@@ -10,8 +10,9 @@
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
-#include <time.h>
-#include <sys/time.h>
+#include "tag.h"
+
+static int default_show_root = 1;
 
 /* this is in builtin-diff.c */
 void add_head(struct rev_info *revs);
@@ -19,14 +20,27 @@ void add_head(struct rev_info *revs);
 static void cmd_log_init(int argc, const char **argv, const char *prefix,
                      struct rev_info *rev)
 {
+       int i;
+
        rev->abbrev = DEFAULT_ABBREV;
        rev->commit_format = CMIT_FMT_DEFAULT;
        rev->verbose_header = 1;
+       rev->show_root_diff = default_show_root;
        argc = setup_revisions(argc, argv, rev, "HEAD");
        if (rev->diffopt.pickaxe || rev->diffopt.filter)
                rev->always_show_header = 0;
-       if (argc > 1)
-               die("unrecognized argument: %s", argv[1]);
+       for (i = 1; i < argc; i++) {
+               const char *arg = argv[i];
+               if (!strncmp(arg, "--encoding=", 11)) {
+                       arg += 11;
+                       if (strcmp(arg, "none"))
+                               git_log_output_encoding = strdup(arg);
+                       else
+                               git_log_output_encoding = "";
+               }
+               else
+                       die("unrecognized argument: %s", arg);
+       }
 }
 
 static int cmd_log_walk(struct rev_info *rev)
@@ -44,11 +58,20 @@ static int cmd_log_walk(struct rev_info *rev)
        return 0;
 }
 
+static int git_log_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "log.showroot")) {
+               default_show_root = git_config_bool(var, value);
+               return 0;
+       }
+       return git_diff_ui_config(var, value);
+}
+
 int cmd_whatchanged(int argc, const char **argv, const char *prefix)
 {
        struct rev_info rev;
 
-       git_config(git_diff_ui_config);
+       git_config(git_log_config);
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.diffopt.recursive = 1;
@@ -59,11 +82,45 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
        return cmd_log_walk(&rev);
 }
 
+static int show_object(const unsigned char *sha1, int suppress_header)
+{
+       unsigned long size;
+       char type[20];
+       char *buf = read_sha1_file(sha1, type, &size);
+       int offset = 0;
+
+       if (!buf)
+               return error("Could not read object %s", sha1_to_hex(sha1));
+
+       if (suppress_header)
+               while (offset < size && buf[offset++] != '\n') {
+                       int new_offset = offset;
+                       while (new_offset < size && buf[new_offset++] != '\n')
+                               ; /* do nothing */
+                       offset = new_offset;
+               }
+
+       if (offset < size)
+               fwrite(buf + offset, size - offset, 1, stdout);
+       free(buf);
+       return 0;
+}
+
+static int show_tree_object(const unsigned char *sha1,
+               const char *base, int baselen,
+               const char *pathname, unsigned mode, int stage)
+{
+       printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
+       return 0;
+}
+
 int cmd_show(int argc, const char **argv, const char *prefix)
 {
        struct rev_info rev;
+       struct object_array_entry *objects;
+       int i, count, ret = 0;
 
-       git_config(git_diff_ui_config);
+       git_config(git_log_config);
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.diffopt.recursive = 1;
@@ -73,14 +130,59 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        rev.ignore_merges = 0;
        rev.no_walk = 1;
        cmd_log_init(argc, argv, prefix, &rev);
-       return cmd_log_walk(&rev);
+
+       count = rev.pending.nr;
+       objects = rev.pending.objects;
+       for (i = 0; i < count && !ret; i++) {
+               struct object *o = objects[i].item;
+               const char *name = objects[i].name;
+               switch (o->type) {
+               case OBJ_BLOB:
+                       ret = show_object(o->sha1, 0);
+                       break;
+               case OBJ_TAG: {
+                       struct tag *t = (struct tag *)o;
+
+                       printf("%stag %s%s\n\n",
+                                       diff_get_color(rev.diffopt.color_diff,
+                                               DIFF_COMMIT),
+                                       t->tag,
+                                       diff_get_color(rev.diffopt.color_diff,
+                                               DIFF_RESET));
+                       ret = show_object(o->sha1, 1);
+                       objects[i].item = (struct object *)t->tagged;
+                       i--;
+                       break;
+               }
+               case OBJ_TREE:
+                       printf("%stree %s%s\n\n",
+                                       diff_get_color(rev.diffopt.color_diff,
+                                               DIFF_COMMIT),
+                                       name,
+                                       diff_get_color(rev.diffopt.color_diff,
+                                               DIFF_RESET));
+                       read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
+                                       show_tree_object);
+                       break;
+               case OBJ_COMMIT:
+                       rev.pending.nr = rev.pending.alloc = 0;
+                       rev.pending.objects = NULL;
+                       add_object_array(o, name, &rev.pending);
+                       ret = cmd_log_walk(&rev);
+                       break;
+               default:
+                       ret = error("Unknown type: %d", o->type);
+               }
+       }
+       free(objects);
+       return ret;
 }
 
 int cmd_log(int argc, const char **argv, const char *prefix)
 {
        struct rev_info rev;
 
-       git_config(git_diff_ui_config);
+       git_config(git_log_config);
        init_revisions(&rev, prefix);
        rev.always_show_header = 1;
        cmd_log_init(argc, argv, prefix, &rev);
@@ -106,10 +208,10 @@ static int git_format_config(const char *var, const char *value)
                strcat(extra_headers, value);
                return 0;
        }
-       if (!strcmp(var, "diff.color")) {
+       if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
                return 0;
        }
-       return git_diff_ui_config(var, value);
+       return git_log_config(var, value);
 }