@matheusbsbs / matheus-bagliano / commits / ebd124c678
Fork 0

make commit message a little more consistent and conforting

It is nicer to let the user know when a commit succeeded all the time, not only the first time. Also the commit sha1 is much more useful than the tree sha1 in this case. This patch also introduces a -q switch to supress this message as well as the summary of created/deleted files. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Dec 14, 2006 at 23:15 UTC ebd124c6783da5e064963611ee17741cd173f6b5
9 files changed +84 -29
Documentation/core-tutorial.txt
+3 -11
@@ -336,17 +336,9 @@ $ commit=$(echo 'Initial commit' | git-commit-tree $tree)
336 $ git-update-ref HEAD $commit
337 ------------------------------------------------
338
339 -which will say:
340 -
341 -----------------
342 -Committing initial tree 8988da15d077d4829fc51d8544c097def6644dbb
343 -----------------
344 -
345 -just to warn you about the fact that it created a totally new commit
346 -that is not related to anything else. Normally you do this only *once*
347 -for a project ever, and all later commits will be parented on top of an
348 -earlier commit, and you'll never see this "Committing initial tree"
349 -message ever again.
339 +In this case this creates a totally new commit that is not related to
340 +anything else. Normally you do this only *once* for a project ever, and
341 +all later commits will be parented on top of an earlier commit.
342
343 Again, normally you'd never actually do this by hand. There is a
344 helpful script called `git commit` that will do all of this for you. So
Documentation/diff-options.txt
+5
@@ -21,6 +21,11 @@
21 deleted lines in decimal notation and pathname without
22 abbreviation, to make it more machine friendly.
23
24 +--shortstat::
25 + Output only the last line of the --stat format containing total
26 + number of modified files, as well as number of added and deleted
27 + lines.
28 +
29 --summary::
30 Output a condensed summary of extended header information
31 such as creations, renames and mode changes.
Documentation/git-commit.txt
+3
@@ -113,6 +113,9 @@ but can be used to amend a merge commit.
113 as well. This is usually not what you want unless you
114 are concluding a conflicted merge.
115
116 +-q|--quiet::
117 + Supress commit summary message.
118 +
119 \--::
120 Do not interpret any more arguments as options.
121
Documentation/tutorial-2.txt
+20 -9
@@ -22,14 +22,14 @@ defaulting to local storage area
22 $ echo 'hello world' > file.txt
23 $ git add .
24 $ git commit -a -m "initial commit"
25 -Committing initial tree 92b8b694ffb1675e5975148e1121810081dbdffe
25 +Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7
26 create mode 100644 file.txt
27 $ echo 'hello world!' >file.txt
28 $ git commit -a -m "add emphasis"
29 +Created commit c4d59f390b9cfd4318117afde11d601c1085f241
30 ------------------------------------------------
31
31 -What are the 40 digits of hex that git responded to the first commit
32 -with?
32 +What are the 40 digits of hex that git responded to the commit with?
33
34 We saw in part one of the tutorial that commits have names like this.
35 It turns out that every object in the git history is stored under
@@ -39,13 +39,25 @@ the same data twice (since identical data is given an identical SHA1
39 name), and that the contents of a git object will never change (since
40 that would change the object's name as well).
41
42 +It is expected that the content of the commit object you created while
43 +following the example above generates a different SHA1 hash than
44 +the one shown above because the commit object records the time when
45 +it was created and the name of the person performing the commit.
46 +
47 We can ask git about this particular object with the cat-file
43 -command--just cut-and-paste from the reply to the initial commit, to
44 -save yourself typing all 40 hex digits:
48 +command. Don't copy the 40 hex digits from this example but use those
49 +from your own version. Note that you can shorten it to only a few
50 +characters to save yourself typing all 40 hex digits:
51
52 ------------------------------------------------
47 -$ git cat-file -t 92b8b694ffb1675e5975148e1121810081dbdffe
48 -tree
53 +$ git-cat-file -t 54196cc2
54 +commit
55 +$ git-cat-file commit 54196cc2
56 +tree 92b8b694ffb1675e5975148e1121810081dbdffe
57 +author J. Bruce Fields <bfields@puzzle.fieldses.org> 1143414668 -0500
58 +committer J. Bruce Fields <bfields@puzzle.fieldses.org> 1143414668 -0500
59 +
60 +initial commit
61 ------------------------------------------------
62
63 A tree can refer to one or more "blob" objects, each corresponding to
@@ -102,8 +114,7 @@ $ find .git/objects/
114
115 and the contents of these files is just the compressed data plus a
116 header identifying their length and their type. The type is either a
105 -blob, a tree, a commit, or a tag. We've seen a blob and a tree now,
106 -so next we should look at a commit.
117 +blob, a tree, a commit, or a tag.
118
119 The simplest commit to find is the HEAD commit, which we can find
120 from .git/HEAD:
builtin-commit-tree.c
-2
@@ -107,8 +107,6 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
107 if (new_parent(parents))
108 parents++;
109 }
110 - if (!parents)
111 - fprintf(stderr, "Committing initial tree %s\n", argv[1]);
110
111 init_buffer(&buffer, &size);
112 add_buffer(&buffer, &size, "tree %s\n", sha1_to_hex(tree_sha1));
diff.c
+37 -1
@@ -801,6 +801,35 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
801 set, total_files, adds, dels, reset);
802 }
803
804 +static void show_shortstats(struct diffstat_t* data)
805 +{
806 + int i, adds = 0, dels = 0, total_files = data->nr;
807 +
808 + if (data->nr == 0)
809 + return;
810 +
811 + for (i = 0; i < data->nr; i++) {
812 + if (!data->files[i]->is_binary &&
813 + !data->files[i]->is_unmerged) {
814 + int added = data->files[i]->added;
815 + int deleted= data->files[i]->deleted;
816 + if (!data->files[i]->is_renamed &&
817 + (added + deleted == 0)) {
818 + total_files--;
819 + } else {
820 + adds += added;
821 + dels += deleted;
822 + }
823 + }
824 + free(data->files[i]->name);
825 + free(data->files[i]);
826 + }
827 + free(data->files);
828 +
829 + printf(" %d files changed, %d insertions(+), %d deletions(-)\n",
830 + total_files, adds, dels);
831 +}
832 +
833 static void show_numstat(struct diffstat_t* data, struct diff_options *options)
834 {
835 int i;
@@ -1771,6 +1800,7 @@ int diff_setup_done(struct diff_options *options)
1800 options->output_format &= ~(DIFF_FORMAT_RAW |
1801 DIFF_FORMAT_NUMSTAT |
1802 DIFF_FORMAT_DIFFSTAT |
1803 + DIFF_FORMAT_SHORTSTAT |
1804 DIFF_FORMAT_SUMMARY |
1805 DIFF_FORMAT_PATCH);
1806
@@ -1781,6 +1811,7 @@ int diff_setup_done(struct diff_options *options)
1811 if (options->output_format & (DIFF_FORMAT_PATCH |
1812 DIFF_FORMAT_NUMSTAT |
1813 DIFF_FORMAT_DIFFSTAT |
1814 + DIFF_FORMAT_SHORTSTAT |
1815 DIFF_FORMAT_SUMMARY |
1816 DIFF_FORMAT_CHECKDIFF))
1817 options->recursive = 1;
@@ -1872,6 +1903,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1903 else if (!strcmp(arg, "--numstat")) {
1904 options->output_format |= DIFF_FORMAT_NUMSTAT;
1905 }
1906 + else if (!strcmp(arg, "--shortstat")) {
1907 + options->output_format |= DIFF_FORMAT_SHORTSTAT;
1908 + }
1909 else if (!strncmp(arg, "--stat", 6)) {
1910 char *end;
1911 int width = options->stat_width;
@@ -2646,7 +2680,7 @@ void diff_flush(struct diff_options *options)
2680 separator++;
2681 }
2682
2649 - if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_NUMSTAT)) {
2683 + if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT)) {
2684 struct diffstat_t diffstat;
2685
2686 memset(&diffstat, 0, sizeof(struct diffstat_t));
@@ -2660,6 +2694,8 @@ void diff_flush(struct diff_options *options)
2694 show_numstat(&diffstat, options);
2695 if (output_format & DIFF_FORMAT_DIFFSTAT)
2696 show_stats(&diffstat, options);
2697 + else if (output_format & DIFF_FORMAT_SHORTSTAT)
2698 + show_shortstats(&diffstat);
2699 separator++;
2700 }
2701
diff.h
+1
@@ -29,6 +29,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
29 #define DIFF_FORMAT_NUMSTAT 0x0004
30 #define DIFF_FORMAT_SUMMARY 0x0008
31 #define DIFF_FORMAT_PATCH 0x0010
32 +#define DIFF_FORMAT_SHORTSTAT 0x0020
33
34 /* These override all above */
35 #define DIFF_FORMAT_NAME 0x0100
git-commit.sh
+15 -4
@@ -80,6 +80,7 @@ no_edit=
80 log_given=
81 log_message=
82 verify=t
83 +quiet=
84 verbose=
85 signoff=
86 force_author=
@@ -241,6 +242,10 @@ $1"
242 signoff=t
243 shift
244 ;;
245 + -q|--q|--qu|--qui|--quie|--quiet)
246 + quiet=t
247 + shift
248 + ;;
249 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
250 verbose=t
251 shift
@@ -615,11 +620,17 @@ then
620 git-rerere
621 fi
622
618 -if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
623 +if test "$ret" = 0
624 then
620 - "$GIT_DIR"/hooks/post-commit
625 + if test -x "$GIT_DIR"/hooks/post-commit
626 + then
627 + "$GIT_DIR"/hooks/post-commit
628 + fi
629 + if test -z "$quiet"
630 + then
631 + echo "Created${initial_commit:+ initial} commit $commit"
632 + git-diff-tree --shortstat --summary --root --no-commit-id HEAD
633 + fi
634 fi
635
623 -test "$ret" = 0 && git-diff-tree --summary --root --no-commit-id HEAD
624 -
636 exit "$ret"
t/t1200-tutorial.sh
-2
@@ -37,8 +37,6 @@ test_expect_success 'tree' "test 8988da15d077d4829fc51d8544c097def6644dbb = $tre
37
38 output="$(echo "Initial commit" | git-commit-tree $(git-write-tree) 2>&1 > .git/refs/heads/master)"
39
40 -test_expect_success 'commit' "test 'Committing initial tree 8988da15d077d4829fc51d8544c097def6644dbb' = \"$output\""
41 -
40 git-diff-index -p HEAD > diff.output
41 test_expect_success 'git-diff-index -p HEAD' 'cmp diff.expect diff.output'
42