From: Erick Mattos <erick.mattos@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Erick Mattos <erick.mattos@gmail.com>
Subject: [PATCH] Changed timestamp behavior of options -c/-C/--amend
Date: Fri, 30 Oct 2009 17:36:34 -0200 [thread overview]
Message-ID: <1256931394-9338-1-git-send-email-erick.mattos@gmail.com> (raw)
The code herein changes commit timestamp recording from a source in a
more intuitive way.
Description:
When we use one of the options above we are normally trying to do mainly
two things: one is using the source as a template and second is to
recreate a commit with corrections.
In the first case timestamp should by default be taken by the time we
are doing the commit, not by the source. On the second case the actual
behavior is acceptable.
Anyway this update creates new options for choosing the source timestamp
or a new one. And set as default for -c option (editing one) to take a
new timestamp and for -C option the source timestamp. That is because
we are normally using the source as template when we we are editing and
as a correction when we are just copying it.
Those options are also useful for --amend option which is by default
behaving the same.
Signed-off-by: Erick Mattos <erick.mattos@gmail.com>
---
Documentation/git-commit.txt | 10 ++++++++--
builtin-commit.c | 15 ++++++++++++---
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 0578a40..27c61d2 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -10,6 +10,7 @@ SYNOPSIS
[verse]
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
[(-c | -C) <commit>] [-F <file> | -m <msg>]
+ [(--old-timestamp | --new-timestamp)]
[--allow-empty] [--no-verify] [-e] [--author=<author>]
[--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -61,13 +62,16 @@ OPTIONS
-C <commit>::
--reuse-message=<commit>::
Take an existing commit object, and reuse the log message
- and the authorship information (including the timestamp)
- when creating the commit.
+ and the authorship information when creating the commit.
+ By default, timestamp is taken from specified commit unless
+ option --new-timestamp is included.
-c <commit>::
--reedit-message=<commit>::
Like '-C', but with '-c' the editor is invoked, so that
the user can further edit the commit message.
+ By default, timestamp is recalculated and not taken from
+ specified commit unless option --old-timestamp is included.
-F <file>::
--file=<file>::
@@ -134,6 +138,8 @@ OPTIONS
current tip -- if it was a merge, it will have the parents of
the current tip as parents -- so the current top commit is
discarded.
+ By default, timestamp is taken from latest commit unless option
+ --new-timestamp is included.
+
--
It is a rough equivalent for:
diff --git a/builtin-commit.c b/builtin-commit.c
index c395cbf..a924584 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -52,6 +52,7 @@ static char *edit_message, *use_message;
static char *author_name, *author_email, *author_date;
static int all, edit_flag, also, interactive, only, amend, signoff;
static int quiet, verbose, no_verify, allow_empty, dry_run;
+static int old_timestamp, new_timestamp;
static char *untracked_files_arg;
/*
* The default commit message cleanup mode will remove the lines
@@ -91,8 +92,10 @@ static struct option builtin_commit_options[] = {
OPT_FILENAME('F', "file", &logfile, "read log from file"),
OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
- OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "),
+ OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
+ OPT_BOOLEAN(0, "old-timestamp", &old_timestamp, "reuse previous commit's timestamp"),
+ OPT_BOOLEAN(0, "new-timestamp", &new_timestamp, "regenerate timestamp, ignoring previous one"),
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
@@ -396,7 +399,8 @@ static void determine_author_info(void)
name = xstrndup(a + 8, lb - (a + 8));
email = xstrndup(lb + 2, rb - (lb + 2));
- date = xstrndup(rb + 2, eol - (rb + 2));
+ if (!new_timestamp)
+ date = xstrndup(rb + 2, eol - (rb + 2));
}
if (force_author) {
@@ -763,11 +767,16 @@ static int parse_and_validate_options(int argc, const char *argv[],
die("You have nothing to amend.");
if (amend && in_merge)
die("You are in the middle of a merge -- cannot amend.");
+ if (old_timestamp && new_timestamp)
+ die("You can not use --old-timesamp and --new-timestamp together.");
if (use_message)
f++;
- if (edit_message)
+ if (edit_message) {
+ if (!old_timestamp)
+ new_timestamp = 1;
f++;
+ }
if (logfile)
f++;
if (f > 1)
--
1.6.5.2.102.g3ad0
next reply other threads:[~2009-10-30 19:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-30 19:36 Erick Mattos [this message]
2009-10-30 20:26 ` [PATCH] Changed timestamp behavior of options -c/-C/--amend Jeff King
2009-10-30 21:22 ` Erick Mattos
2009-10-30 21:51 ` Junio C Hamano
2009-10-30 22:10 ` Johannes Sixt
2009-10-31 23:34 ` Paolo Bonzini
2009-10-30 21:34 ` Junio C Hamano
2009-10-30 21:58 ` Junio C Hamano
2009-10-30 22:20 ` Erick Mattos
2009-10-30 22:33 ` Junio C Hamano
2009-10-30 23:12 ` Erick Mattos
2009-10-31 0:10 ` Junio C Hamano
2009-10-31 1:42 ` Erick Mattos
[not found] ` <55bacdd30910301505xe712b74m837dc862a6ee953@mail.gmail.com>
2009-10-30 22:13 ` Erick Mattos
2009-10-30 22:26 ` Junio C Hamano
2009-10-30 22:30 ` Erick Mattos
2009-10-30 21:56 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1256931394-9338-1-git-send-email-erick.mattos@gmail.com \
--to=erick.mattos@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).