git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Changed timestamp behavior of options -c/-C/--amend

From
Erick Mattos <erick.mattos@gmail.com>
Date
Oct 30, 2009, 19:36 UTC
Message-ID
<1256931394-9338-1-git-send-email-erick.mattos@gmail.com>

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: Jeff King
Message 1 of 17 in “Changed timestamp behavior of options -c/-C/--amend”
  1. Changed timestamp behavior of options -c/-C/--amendErick Mattos, Oct 30, 2009
  2. Jeff KingOct 30, 2009
  3. Erick MattosOct 30, 2009
  4. Junio C HamanoOct 30, 2009
  5. Johannes SixtOct 30, 2009
  6. Paolo BonziniOct 31, 2009
  7. Junio C HamanoOct 30, 2009
  8. Junio C HamanoOct 30, 2009
  9. Erick MattosOct 30, 2009
  10. Junio C HamanoOct 30, 2009
  11. Erick MattosOct 30, 2009
  12. Junio C HamanoOct 31, 2009
  13. Erick MattosOct 31, 2009
  14. Johannes SixtOct 30, 2009
  15. Erick MattosOct 30, 2009
  16. Junio C HamanoOct 30, 2009
  17. Erick MattosOct 30, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.