Skip to contentSkip to conversation

fixup ra/rebase-i-more-options

PATCH Superseded Phillip Wood 7 participants 130 messages Apr 7, 2020 – Aug 26, 2020 Documentation Page 2 of 2

lore
Share & tools
lore
#96 lore raw

Re: [PATCH v6 2/5] rebase -i: support --committer-date-is-author-date

In reply to Đoàn Trần Công Danh

Hi Danh

Quoted 41 lines · Đoàn Trần Công Danh

Hi Phillip,

Quoted 25 lines · Phillip Wood
Quoted 17 lines

sequencer.c static int try_to_commit(struct repository *r, · line 1378

Quoted 7 lines

[...]

sequencer.c +6 -0
+	if (opts->committer_date_is_author_date) {
+		struct ident_split ident;
+		struct strbuf date = STRBUF_INIT;
+
+		if (split_ident_line(&ident, author, (int)strlen(author)) < 0) {
+			res = error(_("malformed ident line '%s'"), author);

I've checked with the translation for my native language (vi). The translators seem to misread ident (as in identity) as indent (as in indentation).

The translation in po/vi.po:25045 (of v2.28.0-rc0) reads:

#~ msgid "malformed ident line"
#~ msgstr "thụt đầu dòng dị hình"

Quoted 7 lines

Translating back to English, it reads: "malformed indentation".

Hence, I think it would read better if we write:

	res = error(_("malformed identity line '%s'"), author);

3 more characters is not that much :)

Quoted 8 lines

Looking through the existing strings "invalid ident line: %.*s" is already used by am so maybe we should reuse that (log.c also contains "invalid ident
line: %s"). Is the translation correct?

#: builtin/am.c:1270
#, c-format
msgid "invalid ident line: %.*s"
msgstr "dòng thụt lề không hợp lệ: %.*s"

That translation isn't correct either.
It seems like it's recurring pattern.
I'll take it to the Vietnamese translation team.

Quoted 6 lines

Anyway, I've checked with other translation that I can understand in part. I think

invalid ident line: %s

is better candidate for the message.

Yes I realized after sending my email that the string we're printing is NUL terminated so we don't need to specify the length with '*'. I think the best thing would be to change the message in this patch to 'invalid ident line: %s' and then have a follow up after this is merged to change all the "invalid ident line" messages to use "identity" instead. Would you be interested in taking on the follow up patch?

Best Wishes

Phillip

Quoted 173 lines

Since Spanish translation also mis-translates the message:

	es.po:9836:msgid "invalid ident line: %.*s"
	es.po-9837-msgstr "sangría no válida: %.*s"

"sangría" also means "indentation" in this context.

Thanks,
-Danh

Quoted 162 lines

Best Wishes

Phillip

Quoted 157 lines
Quoted 144 lines
sequencer.c +32 -1
+			goto out;
+		}
+		if (!ident.date_begin) {
+			res = error(_("corrupted author without date information"));
+			goto out;
+		}
+
+		strbuf_addf(&date, "@%.*s %.*s",
+			    (int)(ident.date_end - ident.date_begin),
+			    ident.date_begin,
+			    (int)(ident.tz_end - ident.tz_begin),
+			    ident.tz_begin);
+		res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
+		strbuf_release(&date);
+
+		if (res)
+			goto out;
+	}
+
   	if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
   		res = error(_("git write-tree failed to write a tree"));
   		goto out;
@@ -2532,6 +2578,11 @@ static int read_populate_opts(struct replay_opts *opts)
   			opts->signoff = 1;
   		}
+		if (file_exists(rebase_path_cdate_is_adate())) {
+			opts->allow_ff = 0;
+			opts->committer_date_is_author_date = 1;
+		}
+
   		if (file_exists(rebase_path_reschedule_failed_exec()))
   			opts->reschedule_failed_exec = 1;
@@ -2622,6 +2673,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
   		write_file(rebase_path_drop_redundant_commits(), "%s", "");
   	if (opts->keep_redundant_commits)
   		write_file(rebase_path_keep_redundant_commits(), "%s", "");
+	if (opts->committer_date_is_author_date)
+		write_file(rebase_path_cdate_is_adate(), "%s", "");
   	if (opts->reschedule_failed_exec)
   		write_file(rebase_path_reschedule_failed_exec(), "%s", "");
@@ -3542,6 +3595,10 @@ static int do_merge(struct repository *r,
   			goto leave_merge;
   		}
+		if (opts->committer_date_is_author_date)
+			argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
+					 author_date_from_env_array(&cmd.env_array));
+
   		cmd.git_cmd = 1;
   		argv_array_push(&cmd.args, "merge");
   		argv_array_push(&cmd.args, "-s");
@@ -3819,7 +3876,8 @@ static int pick_commits(struct repository *r,
   	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
   	if (opts->allow_ff)
   		assert(!(opts->signoff || opts->no_commit ||
-				opts->record_origin || opts->edit));
+				opts->record_origin || opts->edit ||
+				opts->committer_date_is_author_date));
   	if (read_and_refresh_cache(r, opts))
   		return -1;
sequencer.h +1 -0
index 0bee85093e..4ab94119ae 100644
@@ -45,6 +45,7 @@ struct replay_opts {
   	int verbose;
   	int quiet;
   	int reschedule_failed_exec;
+	int committer_date_is_author_date;
   	int mainline;
t/t3422-rebase-incompatible-options.sh +0 -1
index 55ca46786d..c8234062c6 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
   }
   test_rebase_am_only --whitespace=fix
-test_rebase_am_only --committer-date-is-author-date
   test_rebase_am_only -C4
   test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +42 -1
index 4f8a6e51c9..50a63d8ebe 100755
@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe
   . "$TEST_DIRECTORY"/lib-rebase.sh
+GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
+export GIT_AUTHOR_DATE
+
   # This is a special case in which both am and interactive backends
   # provide the same output. It was done intentionally because
   # both the backends fall short of optimal behaviour.
@@ -21,11 +24,20 @@ test_expect_success 'setup' '
   	test_write_lines "line 1" "new line 2" "line 3" >file &&
   	git commit -am "update file" &&
   	git tag side &&
+	test_commit commit1 foo foo1 &&
+	test_commit commit2 foo foo2 &&
+	test_commit commit3 foo foo3 &&
   	git checkout --orphan master &&
+	rm foo &&
   	test_write_lines "line 1" "        line 2" "line 3" >file &&
   	git commit -am "add file" &&
-	git tag main
+	git tag main &&
+
+	mkdir test-bin &&
+	write_script test-bin/git-merge-test <<-\EOF
+	exec git-merge-recursive "$@"
+	EOF
   '
   test_expect_success '--ignore-whitespace works with apply backend' '
@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is remembered when continuing' '
   	git diff --exit-code side
   '
+test_ctime_is_atime () {
+	git log $1 --format=%ai >authortime &&
+	git log $1 --format=%ci >committertime &&
+	test_cmp authortime committertime
+}
+
+test_expect_success '--committer-date-is-author-date works with apply backend' '
+	GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+	git rebase --apply --committer-date-is-author-date HEAD^ &&
+	test_ctime_is_atime -1
+'
+
+test_expect_success '--committer-date-is-author-date works with merge backend' '
+	GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+	git rebase -m --committer-date-is-author-date HEAD^ &&
+	test_ctime_is_atime -1
+'
+
+test_expect_success '--committer-date-is-author-date works with rebase -r' '
+	git checkout side &&
+	GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+	git rebase -r --root --committer-date-is-author-date &&
+	test_ctime_is_atime
+'
+
+test_expect_success '--committer-date-is-author-date works when forking merge' '
+	git checkout side &&
+	GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+	PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \

t/t3436-rebase-more-options.sh test_expect_success '--ignore-whitespace is remembered when continuing' ' · line 104

Quoted 10 lines
t/t3436-rebase-more-options.sh +10 -0
+					--committer-date-is-author-date &&
+	test_ctime_is_atime
+'
+
+test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
+	git checkout commit2 &&
+	GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
+	test_must_fail git rebase -m --committer-date-is-author-date \
+		--onto HEAD^^ HEAD^ &&
+	echo resolved > foo &&

Nitpick: no space after ">" :D

#97 lore raw

Re: [PATCH v6 2/5] rebase -i: support --committer-date-is-author-date

Quoted 53 lines · Phillip Wood

Hi Danh

Quoted 50 lines · Đoàn Trần Công Danh

Hi Phillip,

Quoted 32 lines · Phillip Wood
Quoted 18 lines
Quoted 8 lines

[...]
+    if (opts->committer_date_is_author_date) {
+        struct ident_split ident;
+        struct strbuf date = STRBUF_INIT;
+
+        if (split_ident_line(&ident, author, (int)strlen(author)) < 0) {
+            res = error(_("malformed ident line '%s'"), author);

I've checked with the translation for my native language (vi). The translators seem to misread ident (as in identity) as indent (as in indentation).

The translation in po/vi.po:25045 (of v2.28.0-rc0) reads:

    #~ msgid "malformed ident line"
    #~ msgstr "thụt đầu dòng dị hình"

Quoted 7 lines

Translating back to English, it reads: "malformed indentation".

Hence, I think it would read better if we write:

    res = error(_("malformed identity line '%s'"), author);

3 more characters is not that much :)

Looking through the existing strings "invalid ident line: %.*s" is already
used by am so maybe we should reuse that (log.c also contains "invalid ident
line: %s"). Is the translation correct?

Quoted 4 lines

#: builtin/am.c:1270
#, c-format
msgid "invalid ident line: %.*s"
msgstr "dòng thụt lề không hợp lệ: %.*s"

That translation isn't correct either.
It seems like it's recurring pattern.
I'll take it to the Vietnamese translation team.

Anyway, I've checked with other translation that I can understand in part. I think

    invalid ident line: %s

Quoted 8 lines
Quoted 1 line

is better candidate for the message.

Yes I realized after sending my email that the string we're printing is NUL terminated so we don't need to specify the length with '*'. I think the best thing would be to change the message in this patch to 'invalid ident line: %s' and then have a follow up after this is merged to change all the "invalid ident line" messages to use "identity" instead. Would you be interested in taking on the follow up patch?

In the end I decided it was better just to change the message in this patch to something more descriptive. We can update the other commands separately. For format-patch we should probably update the option description for --from as well as the error message.

Best Wishes

Phillip

Quoted 196 lines

Best Wishes

Phillip

Quoted 191 lines

Since Spanish translation also mis-translates the message:

    es.po:9836:msgid "invalid ident line: %.*s"
    es.po-9837-msgstr "sangría no válida: %.*s"

"sangría" also means "indentation" in this context.

Thanks,
-Danh

Quoted 180 lines

Best Wishes

Phillip

Quoted 175 lines
Quoted 165 lines

+            goto out;
+        }
+        if (!ident.date_begin) {
+            res = error(_("corrupted author without date information"));
+            goto out;
+        }

sequencer.c +13 -0
+
+        strbuf_addf(&date, "@%.*s %.*s",
+                (int)(ident.date_end - ident.date_begin),
+                ident.date_begin,
+                (int)(ident.tz_end - ident.tz_begin),
+                ident.tz_begin);
+        res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
+        strbuf_release(&date);
+
+        if (res)
+            goto out;
+    }
+

       if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
           res = error(_("git write-tree failed to write a tree")); goto out;

sequencer.c +11 -0
@@ -2532,6 +2578,11 @@ static int read_populate_opts(struct
 replay_opts *opts)
                opts->signoff = 1;
            }
+        if (file_exists(rebase_path_cdate_is_adate())) {
+            opts->allow_ff = 0;
+            opts->committer_date_is_author_date = 1;
+        }
+
            if (file_exists(rebase_path_reschedule_failed_exec()))
                opts->reschedule_failed_exec = 1;
@@ -2622,6 +2673,8 @@ int write_basic_state(struct replay_opts
 *opts, const char *head_name,
            write_file(rebase_path_drop_redundant_commits(), "%s", "");
        if (opts->keep_redundant_commits)
            write_file(rebase_path_keep_redundant_commits(), "%s", "");
+    if (opts->committer_date_is_author_date)
+        write_file(rebase_path_cdate_is_adate(), "%s", "");
        if (opts->reschedule_failed_exec)
            write_file(rebase_path_reschedule_failed_exec(), "%s", "");
@@ -3542,6 +3595,10 @@ static int do_merge(struct repository *r,
                goto leave_merge;
            }
+        if (opts->committer_date_is_author_date)
+            argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
+                     author_date_from_env_array(&cmd.env_array));
+
            cmd.git_cmd = 1;
            argv_array_push(&cmd.args, "merge");
            argv_array_push(&cmd.args, "-s");
@@ -3819,7 +3876,8 @@ static int pick_commits(struct repository *r,
        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
        if (opts->allow_ff)

           assert(!(opts->signoff || opts->no_commit ||

-                opts->record_origin || opts->edit));
+                opts->record_origin || opts->edit ||

+                opts->committer_date_is_author_date)); if (read_and_refresh_cache(r, opts)) return -1;

sequencer.h +1 -0
index 0bee85093e..4ab94119ae 100644
@@ -45,6 +45,7 @@ struct replay_opts {
        int verbose;
        int quiet;
        int reschedule_failed_exec;
+    int committer_date_is_author_date;
        int mainline;
t/t3422-rebase-incompatible-options.sh +0 -0
index 55ca46786d..c8234062c6 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
    }

   test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
   test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '

t/t3436-rebase-more-options.sh +0 -0
index 4f8a6e51c9..50a63d8ebe 100755
@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility

between am and interactive backe
   . "$TEST_DIRECTORY"/lib-rebase.sh

t/t3436-rebase-more-options.sh +3 -0
+GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
+export GIT_AUTHOR_DATE
+

   # This is a special case in which both am and interactive backends

   # provide the same output. It was done intentionally because
   # both the backends fall short of optimal behaviour.
t/t3436-rebase-more-options.sh +0 -0
@@ -21,11 +24,20 @@ test_expect_success 'setup' '

       test_write_lines "line 1" "new line 2" "line 3" >file && git commit -am "update file" &&
       git tag side &&
+    test_commit commit1 foo foo1 &&
+    test_commit commit2 foo foo2 &&
+    test_commit commit3 foo foo3 &&
       git checkout --orphan master &&
+    rm foo &&
       test_write_lines "line 1" "        line 2" "line 3" >file && git commit -am "add file" &&
-    git tag main
+    git tag main &&
+
+    mkdir test-bin &&
+    write_script test-bin/git-merge-test <<-\EOF
+    exec git-merge-recursive "$@"
+    EOF
   '
   test_expect_success '--ignore-whitespace works with apply backend' '

t/t3436-rebase-more-options.sh +0 -0
@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is

remembered when continuing' '
       git diff --exit-code side
   '

t/t3436-rebase-more-options.sh +7 -0
+test_ctime_is_atime () {
+    git log $1 --format=%ai >authortime &&
+    git log $1 --format=%ci >committertime &&
+    test_cmp authortime committertime
+}
+
+test_expect_success '--committer-date-is-author-date works with

apply backend' '
+    GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+    git rebase --apply --committer-date-is-author-date HEAD^ && +    test_ctime_is_atime -1
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works with

merge backend' '
+    GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+    git rebase -m --committer-date-is-author-date HEAD^ && +    test_ctime_is_atime -1
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works with

rebase -r' '
+    git checkout side &&
+    GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && +    git rebase -r --root --committer-date-is-author-date && +    test_ctime_is_atime
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works when

forking merge' '
+    git checkout side &&
+    GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && +    PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
+                    --committer-date-is-author-date && +    test_ctime_is_atime
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works when
Quoted 7 lines

committing conflict resolution' '
+    git checkout commit2 &&
+    GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
+    test_must_fail git rebase -m --committer-date-is-author-date \
+        --onto HEAD^^ HEAD^ &&
+    echo resolved > foo &&

Nitpick: no space after ">" :D

#98 lore raw

Re: [PATCH v6 2/5] rebase -i: support --committer-date-is-author-date

Quoted 18 lines · Phillip Wood
Quoted 9 lines
Quoted 9 lines

That translation isn't correct either.
It seems like it's recurring pattern.
I'll take it to the Vietnamese translation team.

Anyway, I've checked with other translation that I can understand in part. I think

    invalid ident line: %s

Quoted 8 lines
Quoted 1 line

is better candidate for the message.

Yes I realized after sending my email that the string we're printing is NUL terminated so we don't need to specify the length with '*'. I think the best thing would be to change the message in this patch to 'invalid ident line: %s' and then have a follow up after this is merged to change all the "invalid ident line" messages to use "identity" instead. Would you be interested in taking on the follow up patch?

Quoted 4 lines

In the end I decided it was better just to change the message in this patch to something more descriptive. We can update the other commands separately. For format-patch we should probably update the option description for --from as well as the error message.

Yes, I also think we should leave the other messages there for now. When this topic get merged, we will come back to see which one should be updated/changed.

All other parts look sane to me.

I don't mind get my hand wet if noone steps in.

Thanks,
Danh

Quoted 202 lines

Best Wishes

Phillip

Quoted 196 lines

Best Wishes

Phillip

Quoted 191 lines

Since Spanish translation also mis-translates the message:

    es.po:9836:msgid "invalid ident line: %.*s"
    es.po-9837-msgstr "sangría no válida: %.*s"

"sangría" also means "indentation" in this context.

Thanks,
-Danh

Quoted 180 lines

Best Wishes

Phillip

Quoted 175 lines
Quoted 165 lines

+            goto out;
+        }
+        if (!ident.date_begin) {
+            res = error(_("corrupted author without date information"));
+            goto out;
+        }

sequencer.c +13 -0
+
+        strbuf_addf(&date, "@%.*s %.*s",
+                (int)(ident.date_end - ident.date_begin),
+                ident.date_begin,
+                (int)(ident.tz_end - ident.tz_begin),
+                ident.tz_begin);
+        res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
+        strbuf_release(&date);
+
+        if (res)
+            goto out;
+    }
+

       if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
           res = error(_("git write-tree failed to write a tree")); goto out;

sequencer.c +11 -0
@@ -2532,6 +2578,11 @@ static int read_populate_opts(struct
 replay_opts *opts)
                opts->signoff = 1;
            }
+        if (file_exists(rebase_path_cdate_is_adate())) {
+            opts->allow_ff = 0;
+            opts->committer_date_is_author_date = 1;
+        }
+
            if (file_exists(rebase_path_reschedule_failed_exec()))
                opts->reschedule_failed_exec = 1;
@@ -2622,6 +2673,8 @@ int write_basic_state(struct replay_opts
 *opts, const char *head_name,
            write_file(rebase_path_drop_redundant_commits(), "%s", "");
        if (opts->keep_redundant_commits)
            write_file(rebase_path_keep_redundant_commits(), "%s", "");
+    if (opts->committer_date_is_author_date)
+        write_file(rebase_path_cdate_is_adate(), "%s", "");
        if (opts->reschedule_failed_exec)
            write_file(rebase_path_reschedule_failed_exec(), "%s", "");
@@ -3542,6 +3595,10 @@ static int do_merge(struct repository *r,
                goto leave_merge;
            }
+        if (opts->committer_date_is_author_date)
+            argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
+                     author_date_from_env_array(&cmd.env_array));
+
            cmd.git_cmd = 1;
            argv_array_push(&cmd.args, "merge");
            argv_array_push(&cmd.args, "-s");
@@ -3819,7 +3876,8 @@ static int pick_commits(struct repository *r,
        setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
        if (opts->allow_ff)

           assert(!(opts->signoff || opts->no_commit ||

-                opts->record_origin || opts->edit));
+                opts->record_origin || opts->edit ||

+                opts->committer_date_is_author_date)); if (read_and_refresh_cache(r, opts)) return -1;

sequencer.h +1 -0
index 0bee85093e..4ab94119ae 100644
@@ -45,6 +45,7 @@ struct replay_opts {
        int verbose;
        int quiet;
        int reschedule_failed_exec;
+    int committer_date_is_author_date;
        int mainline;
t/t3422-rebase-incompatible-options.sh +0 -0
index 55ca46786d..c8234062c6 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
    }

   test_rebase_am_only --whitespace=fix -test_rebase_am_only --committer-date-is-author-date test_rebase_am_only -C4
   test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '

t/t3436-rebase-more-options.sh +0 -0
index 4f8a6e51c9..50a63d8ebe 100755
@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility

between am and interactive backe
   . "$TEST_DIRECTORY"/lib-rebase.sh

t/t3436-rebase-more-options.sh +3 -0
+GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
+export GIT_AUTHOR_DATE
+

   # This is a special case in which both am and interactive backends

   # provide the same output. It was done intentionally because
   # both the backends fall short of optimal behaviour.
t/t3436-rebase-more-options.sh +0 -0
@@ -21,11 +24,20 @@ test_expect_success 'setup' '

       test_write_lines "line 1" "new line 2" "line 3" >file && git commit -am "update file" &&
       git tag side &&
+    test_commit commit1 foo foo1 &&
+    test_commit commit2 foo foo2 &&
+    test_commit commit3 foo foo3 &&
       git checkout --orphan master &&
+    rm foo &&
       test_write_lines "line 1" "        line 2" "line 3" >file && git commit -am "add file" &&
-    git tag main
+    git tag main &&
+
+    mkdir test-bin &&
+    write_script test-bin/git-merge-test <<-\EOF
+    exec git-merge-recursive "$@"
+    EOF
   '
   test_expect_success '--ignore-whitespace works with apply backend' '

t/t3436-rebase-more-options.sh +0 -0
@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is

remembered when continuing' '
       git diff --exit-code side
   '

t/t3436-rebase-more-options.sh +7 -0
+test_ctime_is_atime () {
+    git log $1 --format=%ai >authortime &&
+    git log $1 --format=%ci >committertime &&
+    test_cmp authortime committertime
+}
+
+test_expect_success '--committer-date-is-author-date works with

apply backend' '
+    GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+    git rebase --apply --committer-date-is-author-date HEAD^ && +    test_ctime_is_atime -1
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works with

merge backend' '
+    GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+    git rebase -m --committer-date-is-author-date HEAD^ && +    test_ctime_is_atime -1
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works with

rebase -r' '
+    git checkout side &&
+    GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && +    git rebase -r --root --committer-date-is-author-date && +    test_ctime_is_atime
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works when

forking merge' '
+    git checkout side &&
+    GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 && +    PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
+                    --committer-date-is-author-date && +    test_ctime_is_atime
+'

t/t3436-rebase-more-options.sh +2 -0
+
+test_expect_success '--committer-date-is-author-date works when
Quoted 7 lines

committing conflict resolution' '
+    git checkout commit2 &&
+    GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
+    test_must_fail git rebase -m --committer-date-is-author-date \
+        --onto HEAD^^ HEAD^ &&
+    echo resolved > foo &&

Nitpick: no space after ">" :D

Signature · 1 line
Danh
#99 lore raw

PATCH v6 3/5 sequencer: rename amend_author to author_to_free

In reply to Phillip Wood

From: Rohit Ashiwal <[email protected]>

The purpose of amend_author was to free() the malloc()'d string obtained from get_author() when amending a commit. But we can also use the variable to free() the author at our convenience. Rename it to convey this meaning.

---
 sequencer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sequencer.c +3 -3
index 368d397970..29f6d1bc39 100644
@@ -1335,7 +1335,7 @@ static int try_to_commit(struct repository *r,
 	struct commit_extra_header *extra = NULL;
 	struct strbuf err = STRBUF_INIT;
 	struct strbuf commit_msg = STRBUF_INIT;
-	char *amend_author = NULL;
+	char *author_to_free = NULL;
 	const char *hook_commit = NULL;
 	enum commit_msg_cleanup_mode cleanup;
 	int res = 0;
@@ -1357,7 +1357,7 @@ static int try_to_commit(struct repository *r,
 			strbuf_addstr(msg, orig_message);
 			hook_commit = "HEAD";
 		}
-		author = amend_author = get_author(message);
+		author = author_to_free = get_author(message);
 		unuse_commit_buffer(current_head, message);
 		if (!author) {
 			res = error(_("unable to parse commit author"));
@@ -1474,7 +1474,7 @@ static int try_to_commit(struct repository *r,
 	free_commit_extra_headers(extra);
 	strbuf_release(&err);
 	strbuf_release(&commit_msg);
-	free(amend_author);
+	free(author_to_free);
 
 	return res;
 }
Signature · 1 line
2.27.0
#100 lore raw

PATCH v6 4/5 rebase -i: support --ignore-date

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.

---
 Documentation/git-rebase.txt   |  7 +++--
 builtin/rebase.c               | 13 +++++---
 sequencer.c                    | 50 ++++++++++++++++++++++++++++--
 sequencer.h                    |  1 +
 t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++++++++++++
 5 files changed, 117 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +4 -3
index dfa70263e6..e2717e20e6 100644
@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below.
 	date. This option implies --force-rebase.
 
 --ignore-date::
-	This flag is passed to 'git am' to change the author date
-	of each rebased commit (see linkgit:git-am[1]).
+	Instead of using the author date of the original commit, use
+	the current time as the	author date of the rebased commit.  This
+	option implies `--force-rebase`.
 +
 See also INCOMPATIBLE OPTIONS below.
 
@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS
 The following options:
 
  * --apply
- * --ignore-date
  * --whitespace
  * -C
 
@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --empty=
  * --preserve-merges and --ignore-whitespace
  * --preserve-merges and --committer-date-is-author-date
+ * --preserve-merges and --ignore-date
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +8 -5
index 2579380729..583ac96fc7 100644
@@ -89,6 +89,7 @@ struct rebase_options {
 	char *gpg_sign_opt;
 	int autostash;
 	int committer_date_is_author_date;
+	int ignore_date;
 	char *cmd;
 	int allow_empty_message;
 	int rebase_merges, rebase_cousins;
@@ -127,6 +128,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
 	replay.committer_date_is_author_date =
 					opts->committer_date_is_author_date;
+	replay.ignore_date = opts->ignore_date;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
 
@@ -1503,8 +1505,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "committer-date-is-author-date",
 			 &options.committer_date_is_author_date,
 			 N_("make committer date match author date")),
-		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
-				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
+		OPT_BOOL(0, "ignore-date", &options.ignore_date,
+			 N_("ignore author date and use current date")),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
 		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
@@ -1797,13 +1799,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	    options.autosquash) {
 		allow_preemptive_ff = 0;
 	}
-	if (options.committer_date_is_author_date)
+	if (options.committer_date_is_author_date || options.ignore_date)
 		options.flags |= REBASE_FORCE;
 
 	for (i = 0; i < options.git_am_opts.argc; i++) {
 		const char *option = options.git_am_opts.argv[i], *p;
-		if (!strcmp(option, "--ignore-date") ||
-		    !strcmp(option, "--whitespace=fix") ||
+		if (!strcmp(option, "--whitespace=fix") ||
 		    !strcmp(option, "--whitespace=strip"))
 			allow_preemptive_ff = 0;
 		else if (skip_prefix(option, "-C", &p)) {
@@ -1862,6 +1863,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		if (options.committer_date_is_author_date)
 			argv_array_push(&options.git_am_opts,
 					"--committer-date-is-author-date");
+		if (options.ignore_date)
+			argv_array_push(&options.git_am_opts, "--ignore-date");
 	} else {
 		/* REBASE_MERGE and PRESERVE_MERGES */
 		if (ignore_whitespace) {
sequencer.c +48 -2

106 lines not on this page · raw message

sequencer.h +1 -0
index 4ab94119ae..3587878e3b 100644
@@ -46,6 +46,7 @@ struct replay_opts {
 	int quiet;
 	int reschedule_failed_exec;
 	int committer_date_is_author_date;
+	int ignore_date;
 
 	int mainline;
 
t/t3436-rebase-more-options.sh +56 -0

62 lines not on this page · raw message

Signature · 1 line
2.27.0
#101 lore raw

PATCH v6 5/5 rebase: add --reset-author-date

In reply to Phillip Wood

From: Rohit Ashiwal <[email protected]>

The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.

---
 Documentation/git-rebase.txt   |  1 +
 builtin/rebase.c               |  4 +++-
 t/t3436-rebase-more-options.sh | 34 +++++++++++++++++++++-------------
 3 files changed, 25 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -0
index e2717e20e6..a5f82913fb 100644
@@ -450,6 +450,7 @@ See also INCOMPATIBLE OPTIONS below.
 	date. This option implies --force-rebase.
 
 --ignore-date::
+--reset-author-date::
 	Instead of using the author date of the original commit, use
 	the current time as the	author date of the rebased commit.  This
 	option implies `--force-rebase`.
builtin/rebase.c +3 -1
index 583ac96fc7..b126fbe940 100644
@@ -1505,8 +1505,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "committer-date-is-author-date",
 			 &options.committer_date_is_author_date,
 			 N_("make committer date match author date")),
-		OPT_BOOL(0, "ignore-date", &options.ignore_date,
+		OPT_BOOL(0, "reset-author-date", &options.ignore_date,
 			 N_("ignore author date and use current date")),
+		OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date,
+				N_("synonym of --reset-author-date")),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
 		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
t/t3436-rebase-more-options.sh +21 -13
index 0ede2b8900..5b8963272a 100755
@@ -117,53 +117,61 @@ test_ctime_is_ignored () {
 	! grep -v +0000 authortime
 }
 
-test_expect_success '--ignore-date works with apply backend' '
+test_expect_success '--reset-author-date works with apply backend' '
 	git commit --amend --date="$GIT_AUTHOR_DATE" &&
-	git rebase --apply --ignore-date HEAD^ &&
+	git rebase --apply --reset-author-date HEAD^ &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works with merge backend' '
+test_expect_success '--reset-author-date works with merge backend' '
 	git commit --amend --date="$GIT_AUTHOR_DATE" &&
-	git rebase --ignore-date -m HEAD^ &&
+	git rebase --reset-author-date -m HEAD^ &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works after conflict resolution' '
-	test_must_fail git rebase --ignore-date -m \
+test_expect_success '--reset-author-date works after conflict resolution' '
+	test_must_fail git rebase --reset-author-date -m \
 		--onto commit2^^ commit2^ commit2 &&
 	echo resolved >foo &&
 	git add foo &&
 	git rebase --continue &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works with rebase -r' '
+test_expect_success '--reset-author-date works with rebase -r' '
 	git checkout side &&
 	git merge --no-ff commit3 &&
-	git rebase -r --root --ignore-date &&
+	git rebase -r --root --reset-author-date &&
 	test_ctime_is_ignored
 '
 
-test_expect_success '--ignore-date with --committer-date-is-author-date works' '
+test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
 	test_must_fail git rebase -m --committer-date-is-author-date \
-		--ignore-date --onto commit2^^ commit2^ commit3 &&
+		--reset-author-date --onto commit2^^ commit2^ commit3 &&
 	git checkout --theirs foo &&
 	git add foo &&
 	git rebase --continue &&
 	test_ctime_is_atime -2 &&
 	test_ctime_is_ignored -2
 '
 
-test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
+test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
 	GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
 		PATH="./test-bin:$PATH" git rebase -i --strategy=test \
-				--ignore-date --committer-date-is-author-date \
-				side side &&
+				--reset-author-date \
+				--committer-date-is-author-date side side &&
 	test_ctime_is_atime -1 &&
 	test_ctime_is_ignored -1
  '
 
+test_expect_success '--ignore-date is an alias for --reset-author-date' '
+	git commit --amend --date="$GIT_AUTHOR_DATE" &&
+	git rebase --apply --ignore-date HEAD^ &&
+	git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
+	git rebase -m --ignore-date HEAD^ &&
+	test_ctime_is_ignored -2
+'
+
 # This must be the last test in this file
 test_expect_success '$EDITOR and friends are unchanged' '
 	test_editor_unchanged
Signature · 1 line
2.27.0
#102 lore raw
In reply to Phillip Wood
Quoted 8 lines · Phillip Wood

Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date

Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date

Thanks for polishing them further.

Will queue; with help from others, this can be one of the early topics to be merged after 2.28 gets tagged, hopefully?

#103 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Phillip Wood

Phillip Wood (2):

   rebase -i: support --committer-date-is-author-date
   rebase -i: support --ignore-date

Rohit Ashiwal (3):

   rebase -i: add --ignore-whitespace flag
   sequencer: rename amend_author to author_to_free
   rebase: add --reset-author-date
Quoted 4 lines

Thanks for polishing them further.

Will queue; with help from others, this can be one of the early topics to be merged after 2.28 gets tagged, hopefully?

Yes I hope so, I'm not aware of any outstanding issues (lets see if the reviewers agree)

Best Wishes

Phillip

#104 lore raw

v7 cover cleanup ra/rebase-i-more-options

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Danh pointed out that the word "ident" gets misinterpreted by translators as "indentation" leading to incorrect translations so I've reworded an error message.

format-patch and am could do with having their similar messages updated in the future

Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date

Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date

 Documentation/git-rebase.txt           |  33 ++++-
 builtin/rebase.c                       |  47 +++++--
 sequencer.c                            | 112 ++++++++++++++-
 sequencer.h                            |   2 +
 t/t3422-rebase-incompatible-options.sh |   2 -
 t/t3436-rebase-more-options.sh         | 180 +++++++++++++++++++++++++
 6 files changed, 353 insertions(+), 23 deletions(-)
 create mode 100755 t/t3436-rebase-more-options.sh

Range-diff against v6:
1: 0fc90eaff1 ! 1: 3865fdf461 rebase -i: support --ignore-date

    @@ sequencer.c: static const char *author_date_from_env_array(const struct argv_arr
     +	struct strbuf new_author = STRBUF_INIT;
     +
     +	if (split_ident_line(&ident, author, strlen(author)) < 0) {
    -+		error(_("malformed ident line '%s'"), author);
    ++		error(_("invalid author identity: %s"), author);
     +		return NULL;
     +	}
     +

2: 21cf5e5512 = 2: 0b6b19cb68 rebase: add --reset-author-date

Signature · 1 line
2.27.0
#105 lore raw

PATCH v7 1/5 rebase -i: add --ignore-whitespace flag

From: Rohit Ashiwal <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.

---
 Documentation/git-rebase.txt           | 19 +++++++-
 builtin/rebase.c                       | 19 ++++++--
 t/t3422-rebase-incompatible-options.sh |  1 -
 t/t3436-rebase-more-options.sh         | 60 ++++++++++++++++++++++++++
 4 files changed, 93 insertions(+), 6 deletions(-)
 create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +17 -2
index f7a6033607..b003784f01 100644
@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used
 with `--keep-base` in order to drop those commits from your branch.
 
 --ignore-whitespace::
+	Ignore whitespace differences when trying to reconcile
+differences. Currently, each backend implements an approximation of
+this behavior:
++
+apply backend: When applying a patch, ignore changes in whitespace in
+context lines. Unfortunately, this means that if the "old" lines being
+replaced by the patch differ only in whitespace from the existing
+file, you will get a merge conflict instead of a successful patch
+application.
++
+merge backend: Treat lines with only whitespace changes as unchanged
+when merging. Unfortunately, this means that any patch hunks that were
+intended to modify whitespace and nothing else will be dropped, even
+if the other side had no changes that conflicted.
+
 --whitespace=<option>::
-	These flags are passed to the 'git apply' program
+	This flag is passed to the 'git apply' program
 	(see linkgit:git-apply[1]) that applies the patch.
 	Implies --apply.
 +
@@ -572,7 +587,6 @@ The following options:
  * --apply
  * --committer-date-is-author-date
  * --ignore-date
- * --ignore-whitespace
  * --whitespace
  * -C
 
@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --signoff
  * --preserve-merges and --rebase-merges
  * --preserve-merges and --empty=
+ * --preserve-merges and --ignore-whitespace
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +16 -3
index 27a07d4e78..bd93e9742c 100644
@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
+
 	if (opts->strategy_opts)
 		parse_strategy_opts(&replay, opts->strategy_opts);
 
@@ -1466,6 +1467,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	struct strbuf revisions = STRBUF_INIT;
 	struct strbuf buf = STRBUF_INIT;
 	struct object_id merge_base;
+	int ignore_whitespace = 0;
 	enum action action = ACTION_NONE;
 	const char *gpg_sign = NULL;
 	struct string_list exec = STRING_LIST_INIT_NODUP;
@@ -1495,16 +1497,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
 		OPT_BOOL(0, "signoff", &options.signoff,
 			 N_("add a Signed-off-by: line to each commit")),
-		OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts,
-				  NULL, N_("passed to 'git am'"),
-				  PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
 				  &options.git_am_opts, NULL,
 				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
 				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
+		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
+			 N_("ignore changes in whitespace")),
 		OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
 				  N_("action"), N_("passed to 'git apply'"), 0),
 		OPT_BIT('f', "force-rebase", &options.flags,
@@ -1850,6 +1851,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		imply_merge(&options, "--rebase-merges");
 	}
 
+	if (options.type == REBASE_APPLY) {
+		if (ignore_whitespace)
+			argv_array_push(&options.git_am_opts,
+					"--ignore-whitespace");
+	} else {
+		/* REBASE_MERGE and PRESERVE_MERGES */
+		if (ignore_whitespace) {
+			string_list_append(&strategy_options,
+					   "ignore-space-change");
+		}
+	}
+
 	if (strategy_options.nr) {
 		int i;
 
t/t3422-rebase-incompatible-options.sh +0 -1
index 50e7960702..55ca46786d 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
 }
 
 test_rebase_am_only --whitespace=fix
-test_rebase_am_only --ignore-whitespace
 test_rebase_am_only --committer-date-is-author-date
 test_rebase_am_only -C4
 
t/t3436-rebase-more-options.sh new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.27.0
#106 lore raw

PATCH v7 2/5 rebase -i: support --committer-date-is-author-date

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --committer-date-is-author-date option to the merge backend. This option uses the author date of the commit that is being rewritten as the committer date when the new commit is created.

---
 Documentation/git-rebase.txt           | 10 +++--
 builtin/rebase.c                       | 17 +++++---
 sequencer.c                            | 60 +++++++++++++++++++++++++-
 sequencer.h                            |  1 +
 t/t3422-rebase-incompatible-options.sh |  1 -
 t/t3436-rebase-more-options.sh         | 58 ++++++++++++++++++++++++-
 6 files changed, 136 insertions(+), 11 deletions(-)
Documentation/git-rebase.txt +7 -3
index b003784f01..dfa70263e6 100644
@@ -445,9 +445,13 @@ if the other side had no changes that conflicted.
 See also INCOMPATIBLE OPTIONS below.
 
 --committer-date-is-author-date::
+	Instead of using the current time as the committer date, use
+	the author date of the commit being rebased as the committer
+	date. This option implies --force-rebase.
+
 --ignore-date::
-	These flags are passed to 'git am' to easily change the dates
-	of the rebased commits (see linkgit:git-am[1]).
+	This flag is passed to 'git am' to change the author date
+	of each rebased commit (see linkgit:git-am[1]).
 +
 See also INCOMPATIBLE OPTIONS below.
 
@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS
 The following options:
 
  * --apply
- * --committer-date-is-author-date
  * --ignore-date
  * --whitespace
  * -C
@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --rebase-merges
  * --preserve-merges and --empty=
  * --preserve-merges and --ignore-whitespace
+ * --preserve-merges and --committer-date-is-author-date
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +12 -5
index bd93e9742c..2579380729 100644
@@ -88,6 +88,7 @@ struct rebase_options {
 	int autosquash;
 	char *gpg_sign_opt;
 	int autostash;
+	int committer_date_is_author_date;
 	char *cmd;
 	int allow_empty_message;
 	int rebase_merges, rebase_cousins;
@@ -124,6 +125,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.quiet = !(opts->flags & REBASE_NO_QUIET);
 	replay.verbose = opts->flags & REBASE_VERBOSE;
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
+	replay.committer_date_is_author_date =
+					opts->committer_date_is_author_date;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
 
@@ -1497,9 +1500,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
 		OPT_BOOL(0, "signoff", &options.signoff,
 			 N_("add a Signed-off-by: line to each commit")),
-		OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
-				  &options.git_am_opts, NULL,
-				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
+		OPT_BOOL(0, "committer-date-is-author-date",
+			 &options.committer_date_is_author_date,
+			 N_("make committer date match author date")),
 		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
 				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1794,11 +1797,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	    options.autosquash) {
 		allow_preemptive_ff = 0;
 	}
+	if (options.committer_date_is_author_date)
+		options.flags |= REBASE_FORCE;
 
 	for (i = 0; i < options.git_am_opts.argc; i++) {
 		const char *option = options.git_am_opts.argv[i], *p;
-		if (!strcmp(option, "--committer-date-is-author-date") ||
-		    !strcmp(option, "--ignore-date") ||
+		if (!strcmp(option, "--ignore-date") ||
 		    !strcmp(option, "--whitespace=fix") ||
 		    !strcmp(option, "--whitespace=strip"))
 			allow_preemptive_ff = 0;
@@ -1855,6 +1859,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		if (ignore_whitespace)
 			argv_array_push(&options.git_am_opts,
 					"--ignore-whitespace");
+		if (options.committer_date_is_author_date)
+			argv_array_push(&options.git_am_opts,
+					"--committer-date-is-author-date");
 	} else {
 		/* REBASE_MERGE and PRESERVE_MERGES */
 		if (ignore_whitespace) {
sequencer.c +59 -1

108 lines not on this page · raw message

sequencer.h +1 -0
index 0bee85093e..4ab94119ae 100644
@@ -45,6 +45,7 @@ struct replay_opts {
 	int verbose;
 	int quiet;
 	int reschedule_failed_exec;
+	int committer_date_is_author_date;
 
 	int mainline;
 
t/t3422-rebase-incompatible-options.sh +0 -1
index 55ca46786d..c8234062c6 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
 }
 
 test_rebase_am_only --whitespace=fix
-test_rebase_am_only --committer-date-is-author-date
 test_rebase_am_only -C4
 
 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +57 -1

80 lines not on this page · raw message

Signature · 1 line
2.27.0
#107 lore raw

Re: [PATCH v7 2/5] rebase -i: support --committer-date-is-author-date

Hi Phillip,

Quoted 13 lines · Phillip Wood
sequencer.c +9 -0
@@ -1349,6 +1370,31 @@ static int try_to_commit(struct repository *r,
 		commit_list_insert(current_head, &parents);
 	}
 
+	if (opts->committer_date_is_author_date) {
+		struct ident_split ident;
+		struct strbuf date = STRBUF_INIT;
+
+		if (split_ident_line(&ident, author, (int)strlen(author)) < 0) {
+			res = error(_("malformed ident line '%s'"), author);
+			goto out;
+		}
+		if (!ident.date_begin) {

sequencer.c static int try_to_commit(struct repository *r, · line 1391

Quoted 10 lines
sequencer.c +10 -0
+			res = error(_("corrupted author without date information"));
+			goto out;
+		}
+
+		strbuf_addf(&date, "@%.*s %.*s",
+			    (int)(ident.date_end - ident.date_begin),
+			    ident.date_begin,
+			    (int)(ident.tz_end - ident.tz_begin),
+			    ident.tz_begin);
+		res = setenv("GIT_COMMITTER_DATE", date.buf, 1);

I am slightly worried that we do not unset this environment variable (or revert to its previous value, if it had any).

I had a brief look and it seems that there are only two callers of commit_tree_extended() (which uses git_committer_info(IDENT_STRICT) to fill in the committer date), so it _should_ be possible to extend the signature of commit_tree_extended() to specify the committer information explicitly.

The bigger question is whether we _actually_ need this, and I _think_ that the answer is "not right now", so I would be fine with the patch as-is. Just thought that I point it out (and thereby demonstrate that I actually looked at the patch ;-)).

Ciao,
Dscho

Quoted 166 lines
sequencer.c +19 -1
+		strbuf_release(&date);
+
+		if (res)
+			goto out;
+	}
+
 	if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
 		res = error(_("git write-tree failed to write a tree"));
 		goto out;
@@ -2532,6 +2578,11 @@ static int read_populate_opts(struct replay_opts *opts)
 			opts->signoff = 1;
 		}
 
+		if (file_exists(rebase_path_cdate_is_adate())) {
+			opts->allow_ff = 0;
+			opts->committer_date_is_author_date = 1;
+		}
+
 		if (file_exists(rebase_path_reschedule_failed_exec()))
 			opts->reschedule_failed_exec = 1;
 
@@ -2622,6 +2673,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
 		write_file(rebase_path_drop_redundant_commits(), "%s", "");
 	if (opts->keep_redundant_commits)
 		write_file(rebase_path_keep_redundant_commits(), "%s", "");
+	if (opts->committer_date_is_author_date)
+		write_file(rebase_path_cdate_is_adate(), "%s", "");
 	if (opts->reschedule_failed_exec)
 		write_file(rebase_path_reschedule_failed_exec(), "%s", "");
 
@@ -3542,6 +3595,10 @@ static int do_merge(struct repository *r,
 			goto leave_merge;
 		}
 
+		if (opts->committer_date_is_author_date)
+			argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
+					 author_date_from_env_array(&cmd.env_array));
+
 		cmd.git_cmd = 1;
 		argv_array_push(&cmd.args, "merge");
 		argv_array_push(&cmd.args, "-s");
@@ -3819,7 +3876,8 @@ static int pick_commits(struct repository *r,
 	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
 	if (opts->allow_ff)
 		assert(!(opts->signoff || opts->no_commit ||
-				opts->record_origin || opts->edit));
+				opts->record_origin || opts->edit ||
+				opts->committer_date_is_author_date));
 	if (read_and_refresh_cache(r, opts))
 		return -1;
 
sequencer.h +1 -0
index 0bee85093e..4ab94119ae 100644
@@ -45,6 +45,7 @@ struct replay_opts {
 	int verbose;
 	int quiet;
 	int reschedule_failed_exec;
+	int committer_date_is_author_date;
 
 	int mainline;
 
t/t3422-rebase-incompatible-options.sh +0 -1
index 55ca46786d..c8234062c6 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
 }
 
 test_rebase_am_only --whitespace=fix
-test_rebase_am_only --committer-date-is-author-date
 test_rebase_am_only -C4
 
 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +57 -2
index 4f8a6e51c9..50a63d8ebe 100755
@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe
 
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
+GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
+export GIT_AUTHOR_DATE
+
 # This is a special case in which both am and interactive backends
 # provide the same output. It was done intentionally because
 # both the backends fall short of optimal behaviour.
@@ -21,11 +24,20 @@ test_expect_success 'setup' '
 	test_write_lines "line 1" "new line 2" "line 3" >file &&
 	git commit -am "update file" &&
 	git tag side &&
+	test_commit commit1 foo foo1 &&
+	test_commit commit2 foo foo2 &&
+	test_commit commit3 foo foo3 &&
 
 	git checkout --orphan master &&
+	rm foo &&
 	test_write_lines "line 1" "        line 2" "line 3" >file &&
 	git commit -am "add file" &&
-	git tag main
+	git tag main &&
+
+	mkdir test-bin &&
+	write_script test-bin/git-merge-test <<-\EOF
+	exec git-merge-recursive "$@"
+	EOF
 '
 
 test_expect_success '--ignore-whitespace works with apply backend' '
@@ -52,6 +64,50 @@ test_expect_success '--ignore-whitespace is remembered when continuing' '
 	git diff --exit-code side
 '
 
+test_ctime_is_atime () {
+	git log $1 --format=%ai >authortime &&
+	git log $1 --format=%ci >committertime &&
+	test_cmp authortime committertime
+}
+
+test_expect_success '--committer-date-is-author-date works with apply backend' '
+	GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+	git rebase --apply --committer-date-is-author-date HEAD^ &&
+	test_ctime_is_atime -1
+'
+
+test_expect_success '--committer-date-is-author-date works with merge backend' '
+	GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
+	git rebase -m --committer-date-is-author-date HEAD^ &&
+	test_ctime_is_atime -1
+'
+
+test_expect_success '--committer-date-is-author-date works with rebase -r' '
+	git checkout side &&
+	GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+	git rebase -r --root --committer-date-is-author-date &&
+	test_ctime_is_atime
+'
+
+test_expect_success '--committer-date-is-author-date works when forking merge' '
+	git checkout side &&
+	GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
+	PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
+					--committer-date-is-author-date &&
+	test_ctime_is_atime
+'
+
+test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
+	git checkout commit2 &&
+	GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
+	test_must_fail git rebase -m --committer-date-is-author-date \
+		--onto HEAD^^ HEAD^ &&
+	echo resolved > foo &&
+	git add foo &&
+	git rebase --continue &&
+	test_ctime_is_atime -1
+'
+
 # This must be the last test in this file
 test_expect_success '$EDITOR and friends are unchanged' '
 	test_editor_unchanged
--

2.27.0

#108 lore raw

PATCH v7 3/5 sequencer: rename amend_author to author_to_free

In reply to Phillip Wood

From: Rohit Ashiwal <[email protected]>

The purpose of amend_author was to free() the malloc()'d string obtained from get_author() when amending a commit. But we can also use the variable to free() the author at our convenience. Rename it to convey this meaning.

---
 sequencer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sequencer.c +3 -3
index 368d397970..29f6d1bc39 100644
@@ -1335,7 +1335,7 @@ static int try_to_commit(struct repository *r,
 	struct commit_extra_header *extra = NULL;
 	struct strbuf err = STRBUF_INIT;
 	struct strbuf commit_msg = STRBUF_INIT;
-	char *amend_author = NULL;
+	char *author_to_free = NULL;
 	const char *hook_commit = NULL;
 	enum commit_msg_cleanup_mode cleanup;
 	int res = 0;
@@ -1357,7 +1357,7 @@ static int try_to_commit(struct repository *r,
 			strbuf_addstr(msg, orig_message);
 			hook_commit = "HEAD";
 		}
-		author = amend_author = get_author(message);
+		author = author_to_free = get_author(message);
 		unuse_commit_buffer(current_head, message);
 		if (!author) {
 			res = error(_("unable to parse commit author"));
@@ -1474,7 +1474,7 @@ static int try_to_commit(struct repository *r,
 	free_commit_extra_headers(extra);
 	strbuf_release(&err);
 	strbuf_release(&commit_msg);
-	free(amend_author);
+	free(author_to_free);
 
 	return res;
 }
Signature · 1 line
2.27.0
#109 lore raw

PATCH v7 4/5 rebase -i: support --ignore-date

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.

---
 Documentation/git-rebase.txt   |  7 +++--
 builtin/rebase.c               | 13 +++++---
 sequencer.c                    | 50 ++++++++++++++++++++++++++++--
 sequencer.h                    |  1 +
 t/t3436-rebase-more-options.sh | 56 ++++++++++++++++++++++++++++++++++
 5 files changed, 117 insertions(+), 10 deletions(-)
Documentation/git-rebase.txt +4 -3
index dfa70263e6..e2717e20e6 100644
@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below.
 	date. This option implies --force-rebase.
 
 --ignore-date::
-	This flag is passed to 'git am' to change the author date
-	of each rebased commit (see linkgit:git-am[1]).
+	Instead of using the author date of the original commit, use
+	the current time as the	author date of the rebased commit.  This
+	option implies `--force-rebase`.
 +
 See also INCOMPATIBLE OPTIONS below.
 
@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS
 The following options:
 
  * --apply
- * --ignore-date
  * --whitespace
  * -C
 
@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --empty=
  * --preserve-merges and --ignore-whitespace
  * --preserve-merges and --committer-date-is-author-date
+ * --preserve-merges and --ignore-date
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +8 -5
index 2579380729..583ac96fc7 100644
@@ -89,6 +89,7 @@ struct rebase_options {
 	char *gpg_sign_opt;
 	int autostash;
 	int committer_date_is_author_date;
+	int ignore_date;
 	char *cmd;
 	int allow_empty_message;
 	int rebase_merges, rebase_cousins;
@@ -127,6 +128,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
 	replay.committer_date_is_author_date =
 					opts->committer_date_is_author_date;
+	replay.ignore_date = opts->ignore_date;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
 
@@ -1503,8 +1505,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "committer-date-is-author-date",
 			 &options.committer_date_is_author_date,
 			 N_("make committer date match author date")),
-		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
-				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
+		OPT_BOOL(0, "ignore-date", &options.ignore_date,
+			 N_("ignore author date and use current date")),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
 		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
@@ -1797,13 +1799,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	    options.autosquash) {
 		allow_preemptive_ff = 0;
 	}
-	if (options.committer_date_is_author_date)
+	if (options.committer_date_is_author_date || options.ignore_date)
 		options.flags |= REBASE_FORCE;
 
 	for (i = 0; i < options.git_am_opts.argc; i++) {
 		const char *option = options.git_am_opts.argv[i], *p;
-		if (!strcmp(option, "--ignore-date") ||
-		    !strcmp(option, "--whitespace=fix") ||
+		if (!strcmp(option, "--whitespace=fix") ||
 		    !strcmp(option, "--whitespace=strip"))
 			allow_preemptive_ff = 0;
 		else if (skip_prefix(option, "-C", &p)) {
@@ -1862,6 +1863,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		if (options.committer_date_is_author_date)
 			argv_array_push(&options.git_am_opts,
 					"--committer-date-is-author-date");
+		if (options.ignore_date)
+			argv_array_push(&options.git_am_opts, "--ignore-date");
 	} else {
 		/* REBASE_MERGE and PRESERVE_MERGES */
 		if (ignore_whitespace) {
sequencer.c +48 -2

106 lines not on this page · raw message

sequencer.h +1 -0
index 4ab94119ae..3587878e3b 100644
@@ -46,6 +46,7 @@ struct replay_opts {
 	int quiet;
 	int reschedule_failed_exec;
 	int committer_date_is_author_date;
+	int ignore_date;
 
 	int mainline;
 
t/t3436-rebase-more-options.sh +56 -0

62 lines not on this page · raw message

Signature · 1 line
2.27.0
#110 lore raw

Re: [PATCH v7 4/5] rebase -i: support --ignore-date

Hi Phillip,

sequencer.c static int run_git_commit(struct repository *r, · line 983

Quoted 9 lines · Phillip Wood
sequencer.c +4 -0
@@ -957,7 +976,11 @@ static int run_git_commit(struct repository *r,
 
 	if (opts->committer_date_is_author_date)
 		argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
+				 opts->ignore_date ?
+				 "" :
 				 author_date_from_env_array(&cmd.env_array));
+	if (opts->ignore_date)
+		argv_array_push(&cmd.env_array, "GIT_AUTHOR_DATE=");

Technically, if we switched those two if blocks, we would not have to edit the committer date one. But this way is much clearer.

sequencer.c static int try_to_commit(struct repository *r, · line 1415

Quoted 10 lines
sequencer.c +2 -1
 	argv_array_push(&cmd.args, "commit");
 
@@ -1388,7 +1411,8 @@ static int try_to_commit(struct repository *r,
 			    ident.date_begin,
 			    (int)(ident.tz_end - ident.tz_begin),
 			    ident.tz_begin);
-		res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
+		res = setenv("GIT_COMMITTER_DATE",
+			     opts->ignore_date ? "" : date.buf, 1);

Isn't this constructing the date string for nothing, if opts->ignore_date is set?

I would much rather see it done this way:

- if (opts->committer_date_is_author_date) {
+ if (opts->committer_date_is_author_date && opts->ignore_date)
+ setenv("GIT_COMMITTER_DATE", "", 1);
+ else if (opts->committer_date_is_author_date) {

Not enough of a reason to re-roll, though.

Quoted 4 lines
sequencer.c +0 -0
 		strbuf_release(&date);
 
 		if (res)

sequencer.c static int try_to_commit(struct repository *r, · line 1487

Quoted 10 lines
sequencer.c +7 -0
@@ -1454,6 +1478,16 @@ static int try_to_commit(struct repository *r,
 
 	reset_ident_date();
 
+	if (opts->ignore_date) {
+		author = ignore_author_date(author);
+		if (!author) {
+			res = -1;
+			goto out;
+		}
+		free(author_to_free);

A better cadence might be to first free(author_to_free), then assign author = author_to_free = ignore_author_date(author); (at least in my perspective, it reads more naturally).

But again, not a big reason for a re-roll.

The rest of the patch looks good to me.

Thank you,
Dscho

Quoted 133 lines
sequencer.c +3 -0
+		author_to_free = (char *)author;
 
+	}
+
 	if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
 				 oid, author, opts->gpg_sign, extra)) {
sequencer.c +13 -1
 		res = error(_("failed to write commit object"));
@@ -2583,6 +2617,11 @@ static int read_populate_opts(struct replay_opts *opts)
 			opts->committer_date_is_author_date = 1;
 		}
 
+		if (file_exists(rebase_path_ignore_date())) {
+			opts->allow_ff = 0;
+			opts->ignore_date = 1;
+		}
+
 		if (file_exists(rebase_path_reschedule_failed_exec()))
 			opts->reschedule_failed_exec = 1;
 
@@ -2675,6 +2714,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
 		write_file(rebase_path_keep_redundant_commits(), "%s", "");
 	if (opts->committer_date_is_author_date)
 		write_file(rebase_path_cdate_is_adate(), "%s", "");
+	if (opts->ignore_date)
+		write_file(rebase_path_ignore_date(), "%s", "");
 	if (opts->reschedule_failed_exec)
 		write_file(rebase_path_reschedule_failed_exec(), "%s", "");
 
@@ -3597,7 +3638,11 @@ static int do_merge(struct repository *r,
 
 		if (opts->committer_date_is_author_date)
 			argv_array_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
+					 opts->ignore_date ?
+					 "" :
 					 author_date_from_env_array(&cmd.env_array));
+		if (opts->ignore_date)
+			argv_array_push(&cmd.env_array, "GIT_AUTHOR_DATE=");
 
 		cmd.git_cmd = 1;
 		argv_array_push(&cmd.args, "merge");
@@ -3877,7 +3922,8 @@ static int pick_commits(struct repository *r,
 	if (opts->allow_ff)
 		assert(!(opts->signoff || opts->no_commit ||
 				opts->record_origin || opts->edit ||
-				opts->committer_date_is_author_date));
+				opts->committer_date_is_author_date ||
+				opts->ignore_date));
 	if (read_and_refresh_cache(r, opts))
 		return -1;
 
sequencer.h +1 -0
index 4ab94119ae..3587878e3b 100644
@@ -46,6 +46,7 @@ struct replay_opts {
 	int quiet;
 	int reschedule_failed_exec;
 	int committer_date_is_author_date;
+	int ignore_date;
 
 	int mainline;
 
t/t3436-rebase-more-options.sh +56 -1
index 50a63d8ebe..0ede2b8900 100755
@@ -108,6 +108,62 @@ test_expect_success '--committer-date-is-author-date works when committing confl
 	test_ctime_is_atime -1
 '
 
+# Checking for +0000 in the author date is sufficient since the
+# default timezone is UTC but the timezone used while committing is
+# +0530. The inverted logic in the grep is necessary to check all the
+# author dates in the file.
+test_ctime_is_ignored () {
+	git log $1 --format=%ai >authortime &&
+	! grep -v +0000 authortime
+}
+
+test_expect_success '--ignore-date works with apply backend' '
+	git commit --amend --date="$GIT_AUTHOR_DATE" &&
+	git rebase --apply --ignore-date HEAD^ &&
+	test_ctime_is_ignored -1
+'
+
+test_expect_success '--ignore-date works with merge backend' '
+	git commit --amend --date="$GIT_AUTHOR_DATE" &&
+	git rebase --ignore-date -m HEAD^ &&
+	test_ctime_is_ignored -1
+'
+
+test_expect_success '--ignore-date works after conflict resolution' '
+	test_must_fail git rebase --ignore-date -m \
+		--onto commit2^^ commit2^ commit2 &&
+	echo resolved >foo &&
+	git add foo &&
+	git rebase --continue &&
+	test_ctime_is_ignored -1
+'
+
+test_expect_success '--ignore-date works with rebase -r' '
+	git checkout side &&
+	git merge --no-ff commit3 &&
+	git rebase -r --root --ignore-date &&
+	test_ctime_is_ignored
+'
+
+test_expect_success '--ignore-date with --committer-date-is-author-date works' '
+	test_must_fail git rebase -m --committer-date-is-author-date \
+		--ignore-date --onto commit2^^ commit2^ commit3 &&
+	git checkout --theirs foo &&
+	git add foo &&
+	git rebase --continue &&
+	test_ctime_is_atime -2 &&
+	test_ctime_is_ignored -2
+'
+
+test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
+	GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
+		PATH="./test-bin:$PATH" git rebase -i --strategy=test \
+				--ignore-date --committer-date-is-author-date \
+				side side &&
+	test_ctime_is_atime -1 &&
+	test_ctime_is_ignored -1
+ '
+
 # This must be the last test in this file
 test_expect_success '$EDITOR and friends are unchanged' '
 	test_editor_unchanged
--

2.27.0

#111 lore raw

PATCH v7 5/5 rebase: add --reset-author-date

In reply to Phillip Wood

From: Rohit Ashiwal <[email protected]>

The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.

---
 Documentation/git-rebase.txt   |  1 +
 builtin/rebase.c               |  4 +++-
 t/t3436-rebase-more-options.sh | 34 +++++++++++++++++++++-------------
 3 files changed, 25 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -0
index e2717e20e6..a5f82913fb 100644
@@ -450,6 +450,7 @@ See also INCOMPATIBLE OPTIONS below.
 	date. This option implies --force-rebase.
 
 --ignore-date::
+--reset-author-date::
 	Instead of using the author date of the original commit, use
 	the current time as the	author date of the rebased commit.  This
 	option implies `--force-rebase`.
builtin/rebase.c +3 -1
index 583ac96fc7..b126fbe940 100644
@@ -1505,8 +1505,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "committer-date-is-author-date",
 			 &options.committer_date_is_author_date,
 			 N_("make committer date match author date")),
-		OPT_BOOL(0, "ignore-date", &options.ignore_date,
+		OPT_BOOL(0, "reset-author-date", &options.ignore_date,
 			 N_("ignore author date and use current date")),
+		OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date,
+				N_("synonym of --reset-author-date")),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
 		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
t/t3436-rebase-more-options.sh +21 -13
index 0ede2b8900..5b8963272a 100755
@@ -117,53 +117,61 @@ test_ctime_is_ignored () {
 	! grep -v +0000 authortime
 }
 
-test_expect_success '--ignore-date works with apply backend' '
+test_expect_success '--reset-author-date works with apply backend' '
 	git commit --amend --date="$GIT_AUTHOR_DATE" &&
-	git rebase --apply --ignore-date HEAD^ &&
+	git rebase --apply --reset-author-date HEAD^ &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works with merge backend' '
+test_expect_success '--reset-author-date works with merge backend' '
 	git commit --amend --date="$GIT_AUTHOR_DATE" &&
-	git rebase --ignore-date -m HEAD^ &&
+	git rebase --reset-author-date -m HEAD^ &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works after conflict resolution' '
-	test_must_fail git rebase --ignore-date -m \
+test_expect_success '--reset-author-date works after conflict resolution' '
+	test_must_fail git rebase --reset-author-date -m \
 		--onto commit2^^ commit2^ commit2 &&
 	echo resolved >foo &&
 	git add foo &&
 	git rebase --continue &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works with rebase -r' '
+test_expect_success '--reset-author-date works with rebase -r' '
 	git checkout side &&
 	git merge --no-ff commit3 &&
-	git rebase -r --root --ignore-date &&
+	git rebase -r --root --reset-author-date &&
 	test_ctime_is_ignored
 '
 
-test_expect_success '--ignore-date with --committer-date-is-author-date works' '
+test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
 	test_must_fail git rebase -m --committer-date-is-author-date \
-		--ignore-date --onto commit2^^ commit2^ commit3 &&
+		--reset-author-date --onto commit2^^ commit2^ commit3 &&
 	git checkout --theirs foo &&
 	git add foo &&
 	git rebase --continue &&
 	test_ctime_is_atime -2 &&
 	test_ctime_is_ignored -2
 '
 
-test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
+test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
 	GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
 		PATH="./test-bin:$PATH" git rebase -i --strategy=test \
-				--ignore-date --committer-date-is-author-date \
-				side side &&
+				--reset-author-date \
+				--committer-date-is-author-date side side &&
 	test_ctime_is_atime -1 &&
 	test_ctime_is_ignored -1
  '
 
+test_expect_success '--ignore-date is an alias for --reset-author-date' '
+	git commit --amend --date="$GIT_AUTHOR_DATE" &&
+	git rebase --apply --ignore-date HEAD^ &&
+	git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
+	git rebase -m --ignore-date HEAD^ &&
+	test_ctime_is_ignored -2
+'
+
 # This must be the last test in this file
 test_expect_success '$EDITOR and friends are unchanged' '
 	test_editor_unchanged
Signature · 1 line
2.27.0
#112 lore raw

Re: [PATCH v7 0/5] cleanup ra/rebase-i-more-options

In reply to Phillip Wood
Quoted 2 lines · Phillip Wood

format-patch and am could do with having their similar messages updated in the future

That's a good #leftoverbits topic.

#113 lore raw

Re: [PATCH v7 0/5] cleanup ra/rebase-i-more-options

In reply to Phillip Wood

Hi Phillip,

Quoted 8 lines · Phillip Wood

From: Phillip Wood <[email protected]>

Danh pointed out that the word "ident" gets misinterpreted by translators as "indentation" leading to incorrect translations so I've reworded an error message.

format-patch and am could do with having their similar messages updated in the future

Thank you for this patch series!

To be honest, my hope was that I would get support for git rebase -i --whitespace=fix out of that GSoC project... but I take what I can get, and this patch series is in a pretty good shape.

I offered three small suggestions how I think it could be improved, still, but I would be pretty happy with seeing the patches moving to next as-are.

Thank you,
Dscho

Quoted 35 lines

Phillip Wood (2):
rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date

Rohit Ashiwal (3):
rebase -i: add --ignore-whitespace flag
sequencer: rename amend_author to author_to_free
rebase: add --reset-author-date

 Documentation/git-rebase.txt           |  33 ++++-
 builtin/rebase.c                       |  47 +++++--
 sequencer.c                            | 112 ++++++++++++++-
 sequencer.h                            |   2 +
 t/t3422-rebase-incompatible-options.sh |   2 -
 t/t3436-rebase-more-options.sh         | 180 +++++++++++++++++++++++++
 6 files changed, 353 insertions(+), 23 deletions(-)
 create mode 100755 t/t3436-rebase-more-options.sh

Range-diff against v6:
1: 0fc90eaff1 ! 1: 3865fdf461 rebase -i: support --ignore-date

    @@ sequencer.c: static const char *author_date_from_env_array(const struct argv_arr
     +	struct strbuf new_author = STRBUF_INIT;
     +
     +	if (split_ident_line(&ident, author, strlen(author)) < 0) {
    -+		error(_("malformed ident line '%s'"), author);
    ++		error(_("invalid author identity: %s"), author);
     +		return NULL;
     +	}
     +

2: 21cf5e5512 = 2: 0b6b19cb68 rebase: add --reset-author-date --
2.27.0

#114 lore raw

Re: [PATCH v7 0/5] cleanup ra/rebase-i-more-options

Quoted 3 lines · Johannes Schindelin

I offered three small suggestions how I think it could be improved, still, but I would be pretty happy with seeing the patches moving to next as-are.

I tend to agree with those points I saw you mentioned.

The unconditional exporting of the committer-date without undoing looked like a bad pattern waiting to be copied and pasted. I have not yet fully followed the codepath but I tend to agree with your suspicion that commit_tree_extended() might be a better place to do this.

Thanks.

#115 lore raw

Re: [PATCH v7 0/5] cleanup ra/rebase-i-more-options

Quoted 10 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin

I offered three small suggestions how I think it could be improved, still, but I would be pretty happy with seeing the patches moving to next as-are.

I tend to agree with those points I saw you mentioned.

The unconditional exporting of the committer-date without undoing looked like a bad pattern waiting to be copied and pasted.

I think it is copied and pasted from builtin/am.c

Quoted 3 lines

I have not yet fully followed the codepath but I tend to agree with your suspicion that commit_tree_extended() might be a better place to do this.

It looks like it should be simple enough to do that, I'll reroll

Thanks for your comments dscho

Phillip

Quoted 2 lines

Thanks.

#116 lore raw

v8 cover cleanup ra/rebase-i-more-options

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Thanks to dscho for his comments on v7. Patch 2 is new, it extends commit_tree_extended() to take an explicit committer and changes am to use that rather than exporting GIT_COMMITTER_DATE. The old patch 3 is gone as it renamed a variable in preparation for repurposing it in the next patch but it is no longer repurposed. The changes in patches 3 & 4 use the new argument to commit_tree_extended() rather than exporting GIT_COMMITTER_DATE in try_to_commit().

Phillip Wood (3):
am: stop exporting GIT_COMMITTER_DATE rebase -i: support --committer-date-is-author-date rebase -i: support --ignore-date

Rohit Ashiwal (2):
rebase -i: add --ignore-whitespace flag
rebase: add --reset-author-date

 Documentation/git-rebase.txt           |  33 ++++-
 builtin/am.c                           |  28 +++-
 builtin/commit.c                       |   4 +-
 builtin/rebase.c                       |  47 +++++--
 commit.c                               |  11 +-
 commit.h                               |   7 +-
 ident.c                                |  24 ++--
 sequencer.c                            | 130 +++++++++++++++++-
 sequencer.h                            |   4 +
 t/t3422-rebase-incompatible-options.sh |   2 -
 t/t3436-rebase-more-options.sh         | 180 +++++++++++++++++++++++++
 11 files changed, 422 insertions(+), 48 deletions(-)
 create mode 100755 t/t3436-rebase-more-options.sh

Range-diff against v7:

1:  5bb4226007 = 1:  5bb4226007 rebase -i: add --ignore-whitespace flag
-:  ---------- > 2:  33f62dd2a0 am: stop exporting GIT_COMMITTER_DATE
2:  e5fdb574ed ! 3:  34431945c8 rebase -i: support --committer-date-is-author-date
    @@ Documentation/git-rebase.txt: if the other side had no changes that conflicted.
      --committer-date-is-author-date::
     +	Instead of using the current time as the committer date, use
     +	the author date of the commit being rebased as the committer
    -+	date. This option implies --force-rebase.
    ++	date. This option implies `--force-rebase`.
     +
      --ignore-date::
     -	These flags are passed to 'git am' to easily change the dates
    @@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs
      static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
      static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
      static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
    +@@ sequencer.c: int sequencer_remove_state(struct replay_opts *opts)
    + 		}
    + 	}
    + 
    ++	free(opts->committer_name);
    ++	free(opts->committer_email);
    + 	free(opts->gpg_sign);
    + 	free(opts->strategy);
    + 	for (i = 0; i < opts->xopts_nr; i++)
     @@ sequencer.c: static char *get_author(const char *message)
      	return NULL;
      }
    @@ sequencer.c: static int run_git_commit(struct repository *r,
      
      	if (!(flags & VERIFY_MSG))
     @@ sequencer.c: static int try_to_commit(struct repository *r,
    - 		commit_list_insert(current_head, &parents);
    + 	struct strbuf err = STRBUF_INIT;
    + 	struct strbuf commit_msg = STRBUF_INIT;
    + 	char *amend_author = NULL;
    ++	const char *committer = NULL;
    + 	const char *hook_commit = NULL;
    + 	enum commit_msg_cleanup_mode cleanup;
    + 	int res = 0;
    +@@ sequencer.c: static int try_to_commit(struct repository *r,
    + 		goto out;
      	}
      
    +-	reset_ident_date();
     +	if (opts->committer_date_is_author_date) {
    -+		struct ident_split ident;
    ++		struct ident_split id;
     +		struct strbuf date = STRBUF_INIT;
     +
    -+		if (split_ident_line(&ident, author, (int)strlen(author)) < 0) {
    -+			res = error(_("malformed ident line '%s'"), author);
    ++		if (split_ident_line(&id, author, (int)strlen(author)) < 0) {
    ++			res = error(_("invalid author identity '%s'"), author);
     +			goto out;
     +		}
    -+		if (!ident.date_begin) {
    -+			res = error(_("corrupted author without date information"));
    ++		if (!id.date_begin) {
    ++			res = error(_("corrupt author: missing date information"));
     +			goto out;
     +		}
    -+
     +		strbuf_addf(&date, "@%.*s %.*s",
    -+			    (int)(ident.date_end - ident.date_begin),
    -+			    ident.date_begin,
    -+			    (int)(ident.tz_end - ident.tz_begin),
    -+			    ident.tz_begin);
    -+		res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
    ++			    (int)(id.date_end - id.date_begin), id.date_begin,
    ++			    (int)(id.tz_end - id.tz_begin), id.tz_begin);
    ++		committer = fmt_ident(opts->committer_name,
    ++				      opts->committer_email,
    ++				      WANT_COMMITTER_IDENT, date.buf,
    ++				      IDENT_STRICT);
     +		strbuf_release(&date);
    -+
    -+		if (res)
    -+			goto out;
    ++	} else {
    ++		reset_ident_date();
     +	}
    -+
    - 	if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
    - 		res = error(_("git write-tree failed to write a tree"));
    + 
    + 	if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid,
    +-				 author, NULL, opts->gpg_sign, extra)) {
    ++				 author, committer, opts->gpg_sign, extra)) {
    + 		res = error(_("failed to write commit object"));
      		goto out;
    + 	}
     @@ sequencer.c: static int read_populate_opts(struct replay_opts *opts)
      			opts->signoff = 1;
      		}
    @@ sequencer.c: static int pick_commits(struct repository *r,
      	if (opts->allow_ff)
      		assert(!(opts->signoff || opts->no_commit ||
     -				opts->record_origin || opts->edit));
    -+				opts->record_origin || opts->edit ||
    -+				opts->committer_date_is_author_date));
    ++			 opts->record_origin || opts->edit ||
    ++			 opts->committer_date_is_author_date));
      	if (read_and_refresh_cache(r, opts))
      		return -1;
      
    +@@ sequencer.c: static int commit_staged_changes(struct repository *r,
    + 	return 0;
    + }
    + 
    ++static int init_committer(struct replay_opts *opts)
    ++{
    ++	struct ident_split id;
    ++	const char *committer;
    ++
    ++	committer = git_committer_info(IDENT_STRICT);
    ++	if (split_ident_line(&id, committer, strlen(committer)) < 0)
    ++		return error(_("invalid committer '%s'"), committer);
    ++	opts->committer_name =
    ++		xmemdupz(id.name_begin, id.name_end - id.name_begin);
    ++	opts->committer_email =
    ++		xmemdupz(id.mail_begin, id.mail_end - id.mail_end);
    ++
    ++	return 0;
    ++}
    ++
    + int sequencer_continue(struct repository *r, struct replay_opts *opts)
    + {
    + 	struct todo_list todo_list = TODO_LIST_INIT;
    +@@ sequencer.c: int sequencer_continue(struct repository *r, struct replay_opts *opts)
    + 	if (read_populate_opts(opts))
    + 		return -1;
    + 	if (is_rebase_i(opts)) {
    ++		if (opts->committer_date_is_author_date && init_committer(opts))
    ++			return -1;
    ++
    + 		if ((res = read_populate_todo(r, &todo_list, opts)))
    + 			goto release_todo_list;
    + 
    +@@ sequencer.c: int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
    + 
    + 	res = -1;
    + 
    ++	if (opts->committer_date_is_author_date && init_committer(opts))
    ++		goto cleanup;
    ++
    + 	if (checkout_onto(r, opts, onto_name, &oid, orig_head))
    + 		goto cleanup;
    + 
     
      ## sequencer.h ##
     @@ sequencer.h: struct replay_opts {
    @@ sequencer.h: struct replay_opts {
      
      	int mainline;
      
    ++	char *committer_name;
    ++	char *committer_email;
    + 	char *gpg_sign;
    + 	enum commit_msg_cleanup_mode default_msg_cleanup;
    + 	int explicit_cleanup;
     
      ## t/t3422-rebase-incompatible-options.sh ##
     @@ t/t3422-rebase-incompatible-options.sh: test_rebase_am_only () {
3:  cf5c9a2456 < -:  ---------- sequencer: rename amend_author to author_to_free
4:  3865fdf461 ! 4:  060c0ea2d0 rebase -i: support --ignore-date
    @@ Commit message
     
      ## Documentation/git-rebase.txt ##
     @@ Documentation/git-rebase.txt: See also INCOMPATIBLE OPTIONS below.
    - 	date. This option implies --force-rebase.
    + 	date. This option implies `--force-rebase`.
      
      --ignore-date::
     -	This flag is passed to 'git am' to change the author date
    @@ sequencer.c: static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs
      static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
      static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
      static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
    -@@ sequencer.c: static const char *author_date_from_env_array(const struct argv_array *env)
    - 	BUG("GIT_AUTHOR_DATE missing from author script");
    - }
    - 
    -+/* Construct a free()able author string with current time as the author date */
    -+static char *ignore_author_date(const char *author)
    -+{
    -+	int len;
    -+	struct ident_split ident;
    -+	struct strbuf new_author = STRBUF_INIT;
    -+
    -+	if (split_ident_line(&ident, author, strlen(author)) < 0) {
    -+		error(_("invalid author identity: %s"), author);
    -+		return NULL;
    -+	}
    -+
    -+	len = ident.mail_end - ident.name_begin + 1;
    -+	strbuf_addf(&new_author, "%.*s ", len, ident.name_begin);
    -+	datestamp(&new_author);
    -+	return strbuf_detach(&new_author, NULL);
    -+}
    -+
    - static const char staged_changes_advice[] =
    - N_("you have staged changes in your working tree\n"
    - "If these changes are meant to be squashed into the previous commit, run:\n"
     @@ sequencer.c: static int run_git_commit(struct repository *r,
      
      	if (opts->committer_date_is_author_date)
    @@ sequencer.c: static int run_git_commit(struct repository *r,
      	argv_array_push(&cmd.args, "commit");
      
     @@ sequencer.c: static int try_to_commit(struct repository *r,
    - 			    ident.date_begin,
    - 			    (int)(ident.tz_end - ident.tz_begin),
    - 			    ident.tz_begin);
    --		res = setenv("GIT_COMMITTER_DATE", date.buf, 1);
    -+		res = setenv("GIT_COMMITTER_DATE",
    -+			     opts->ignore_date ? "" : date.buf, 1);
    + 		struct ident_split id;
    + 		struct strbuf date = STRBUF_INIT;
    + 
    +-		if (split_ident_line(&id, author, (int)strlen(author)) < 0) {
    +-			res = error(_("invalid author identity '%s'"), author);
    +-			goto out;
    ++		if (!opts->ignore_date) {
    ++			if (split_ident_line(&id, author, (int)strlen(author)) < 0) {
    ++				res = error(_("invalid author identity '%s'"),
    ++					    author);
    ++				goto out;
    ++			}
    ++			if (!id.date_begin) {
    ++				res = error(_(
    ++					"corrupt author: missing date information"));
    ++				goto out;
    ++			}
    ++			strbuf_addf(&date, "@%.*s %.*s",
    ++				    (int)(id.date_end - id.date_begin),
    ++				    id.date_begin,
    ++				    (int)(id.tz_end - id.tz_begin),
    ++				    id.tz_begin);
    ++		} else {
    ++			reset_ident_date();
    + 		}
    +-		if (!id.date_begin) {
    +-			res = error(_("corrupt author: missing date information"));
    +-			goto out;
    +-		}
    +-		strbuf_addf(&date, "@%.*s %.*s",
    +-			    (int)(id.date_end - id.date_begin), id.date_begin,
    +-			    (int)(id.tz_end - id.tz_begin), id.tz_begin);
    + 		committer = fmt_ident(opts->committer_name,
    + 				      opts->committer_email,
    +-				      WANT_COMMITTER_IDENT, date.buf,
    ++				      WANT_COMMITTER_IDENT,
    ++				      opts->ignore_date ? NULL : date.buf,
    + 				      IDENT_STRICT);
      		strbuf_release(&date);
    - 
    - 		if (res)
    -@@ sequencer.c: static int try_to_commit(struct repository *r,
    - 
    - 	reset_ident_date();
    + 	} else {
    + 		reset_ident_date();
    + 	}
      
     +	if (opts->ignore_date) {
    -+		author = ignore_author_date(author);
    -+		if (!author) {
    -+			res = -1;
    ++		struct ident_split id;
    ++		char *name, *email;
    ++
    ++		if (split_ident_line(&id, author, strlen(author)) < 0) {
    ++			error(_("invalid author identity '%s'"), author);
     +			goto out;
     +		}
    -+		free(author_to_free);
    -+		author_to_free = (char *)author;
    ++		name = xmemdupz(id.name_begin, id.name_end - id.name_begin);
    ++		email = xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
    ++		author = fmt_ident(name, email, WANT_AUTHOR_IDENT, NULL,
    ++				   IDENT_STRICT);
    ++		free(name);
    ++		free(email);
     +	}
     +
    - 	if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
    - 				 oid, author, opts->gpg_sign, extra)) {
    + 	if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid,
    + 				 author, committer, opts->gpg_sign, extra)) {
      		res = error(_("failed to write commit object"));
     @@ sequencer.c: static int read_populate_opts(struct replay_opts *opts)
      			opts->committer_date_is_author_date = 1;
    @@ sequencer.c: static int do_merge(struct repository *r,
     @@ sequencer.c: static int pick_commits(struct repository *r,
      	if (opts->allow_ff)
      		assert(!(opts->signoff || opts->no_commit ||
    - 				opts->record_origin || opts->edit ||
    --				opts->committer_date_is_author_date));
    -+				opts->committer_date_is_author_date ||
    -+				opts->ignore_date));
    + 			 opts->record_origin || opts->edit ||
    +-			 opts->committer_date_is_author_date));
    ++			 opts->committer_date_is_author_date ||
    ++			 opts->ignore_date));
      	if (read_and_refresh_cache(r, opts))
      		return -1;

5: 0b6b19cb68 ! 5: 92ed3bed9f rebase: add --reset-author-date
@@ Commit message

## Documentation/git-rebase.txt ##
@@ Documentation/git-rebase.txt: See also INCOMPATIBLE OPTIONS below.
- date. This option implies --force-rebase.
+ date. This option implies --force-rebase.

--ignore-date::
+--reset-author-date::

Signature · 1 line
2.28.0
#117 lore raw

PATCH v8 1/5 rebase -i: add --ignore-whitespace flag

From: Rohit Ashiwal <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-whitespace option to the merge backend. This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.

---
 Documentation/git-rebase.txt           | 19 +++++++-
 builtin/rebase.c                       | 19 ++++++--
 t/t3422-rebase-incompatible-options.sh |  1 -
 t/t3436-rebase-more-options.sh         | 60 ++++++++++++++++++++++++++
 4 files changed, 93 insertions(+), 6 deletions(-)
 create mode 100755 t/t3436-rebase-more-options.sh
Documentation/git-rebase.txt +17 -2
index f7a6033607..b003784f01 100644
@@ -422,8 +422,23 @@ your branch contains commits which were dropped, this option can be used
 with `--keep-base` in order to drop those commits from your branch.
 
 --ignore-whitespace::
+	Ignore whitespace differences when trying to reconcile
+differences. Currently, each backend implements an approximation of
+this behavior:
++
+apply backend: When applying a patch, ignore changes in whitespace in
+context lines. Unfortunately, this means that if the "old" lines being
+replaced by the patch differ only in whitespace from the existing
+file, you will get a merge conflict instead of a successful patch
+application.
++
+merge backend: Treat lines with only whitespace changes as unchanged
+when merging. Unfortunately, this means that any patch hunks that were
+intended to modify whitespace and nothing else will be dropped, even
+if the other side had no changes that conflicted.
+
 --whitespace=<option>::
-	These flags are passed to the 'git apply' program
+	This flag is passed to the 'git apply' program
 	(see linkgit:git-apply[1]) that applies the patch.
 	Implies --apply.
 +
@@ -572,7 +587,6 @@ The following options:
  * --apply
  * --committer-date-is-author-date
  * --ignore-date
- * --ignore-whitespace
  * --whitespace
  * -C
 
@@ -598,6 +612,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --signoff
  * --preserve-merges and --rebase-merges
  * --preserve-merges and --empty=
+ * --preserve-merges and --ignore-whitespace
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +16 -3
index 27a07d4e78..bd93e9742c 100644
@@ -126,6 +126,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
+
 	if (opts->strategy_opts)
 		parse_strategy_opts(&replay, opts->strategy_opts);
 
@@ -1466,6 +1467,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	struct strbuf revisions = STRBUF_INIT;
 	struct strbuf buf = STRBUF_INIT;
 	struct object_id merge_base;
+	int ignore_whitespace = 0;
 	enum action action = ACTION_NONE;
 	const char *gpg_sign = NULL;
 	struct string_list exec = STRING_LIST_INIT_NODUP;
@@ -1495,16 +1497,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
 		OPT_BOOL(0, "signoff", &options.signoff,
 			 N_("add a Signed-off-by: line to each commit")),
-		OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts,
-				  NULL, N_("passed to 'git am'"),
-				  PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
 				  &options.git_am_opts, NULL,
 				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
 				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
+		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
+			 N_("ignore changes in whitespace")),
 		OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
 				  N_("action"), N_("passed to 'git apply'"), 0),
 		OPT_BIT('f', "force-rebase", &options.flags,
@@ -1850,6 +1851,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		imply_merge(&options, "--rebase-merges");
 	}
 
+	if (options.type == REBASE_APPLY) {
+		if (ignore_whitespace)
+			argv_array_push(&options.git_am_opts,
+					"--ignore-whitespace");
+	} else {
+		/* REBASE_MERGE and PRESERVE_MERGES */
+		if (ignore_whitespace) {
+			string_list_append(&strategy_options,
+					   "ignore-space-change");
+		}
+	}
+
 	if (strategy_options.nr) {
 		int i;
 
t/t3422-rebase-incompatible-options.sh +0 -1
index 50e7960702..55ca46786d 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
 }
 
 test_rebase_am_only --whitespace=fix
-test_rebase_am_only --ignore-whitespace
 test_rebase_am_only --committer-date-is-author-date
 test_rebase_am_only -C4
 
t/t3436-rebase-more-options.sh new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.28.0
#118 lore raw

PATCH v8 2/5 am: stop exporting GIT_COMMITTER_DATE

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

The implementation of --committer-date-is-author-date exports GIT_COMMITTER_DATE to override the default committer date but does not reset GIT_COMMITTER_DATE in the environment after creating the commit so it is set in the environment of any hooks that get run. We're about to add the same functionality to the sequencer and do not want to have GIT_COMMITTER_DATE set when running hooks or exec commands so lets update commit_tree_extended() to take an explicit committer so we override the default date without setting GIT_COMMITTER_DATE in the environment.

---
 builtin/am.c     | 28 +++++++++++++++++++++++-----
 builtin/commit.c |  4 ++--
 commit.c         | 11 +++++++----
 commit.h         |  7 +++----
 ident.c          | 24 ++++++++++++++----------
 sequencer.c      |  4 ++--
 6 files changed, 51 insertions(+), 27 deletions(-)
builtin/am.c +23 -5
index e3dfd93c25..896cd0f827 100644
@@ -98,6 +98,8 @@ struct am_state {
 	char *author_name;
 	char *author_email;
 	char *author_date;
+	char *committer_name;
+	char *committer_email;
 	char *msg;
 	size_t msg_len;
 
@@ -130,6 +132,8 @@ struct am_state {
  */
 static void am_state_init(struct am_state *state)
 {
+	const char *committer;
+	struct ident_split id;
 	int gpgsign;
 
 	memset(state, 0, sizeof(*state));
@@ -150,6 +154,14 @@ static void am_state_init(struct am_state *state)
 
 	if (!git_config_get_bool("commit.gpgsign", &gpgsign))
 		state->sign_commit = gpgsign ? "" : NULL;
+
+	committer = git_committer_info(IDENT_STRICT);
+	if (split_ident_line(&id, committer, strlen(committer)) < 0)
+		die(_("invalid committer: %s"), committer);
+	state->committer_name =
+		xmemdupz(id.name_begin, id.name_end - id.name_begin);
+	state->committer_email =
+		xmemdupz(id.mail_begin, id.mail_end - id.mail_end);
 }
 
 /**
@@ -161,6 +173,8 @@ static void am_state_release(struct am_state *state)
 	free(state->author_name);
 	free(state->author_email);
 	free(state->author_date);
+	free(state->committer_name);
+	free(state->committer_email);
 	free(state->msg);
 	argv_array_clear(&state->git_apply_opts);
 }
@@ -1556,7 +1570,7 @@ static void do_commit(const struct am_state *state)
 	struct object_id tree, parent, commit;
 	const struct object_id *old_oid;
 	struct commit_list *parents = NULL;
-	const char *reflog_msg, *author;
+	const char *reflog_msg, *author, *committer = NULL;
 	struct strbuf sb = STRBUF_INIT;
 
 	if (run_hook_le(NULL, "pre-applypatch", NULL))
@@ -1580,11 +1594,15 @@ static void do_commit(const struct am_state *state)
 			IDENT_STRICT);
 
 	if (state->committer_date_is_author_date)
-		setenv("GIT_COMMITTER_DATE",
-			state->ignore_date ? "" : state->author_date, 1);
+		committer = fmt_ident(state->committer_name,
+				      state->author_email, WANT_COMMITTER_IDENT,
+				      state->ignore_date ? NULL
+							 : state->author_date,
+				      IDENT_STRICT);
 
-	if (commit_tree(state->msg, state->msg_len, &tree, parents, &commit,
-			author, state->sign_commit))
+	if (commit_tree_extended(state->msg, state->msg_len, &tree, parents,
+				 &commit, author, committer, state->sign_commit,
+				 NULL))
 		die(_("failed to write commit object"));
 
 	reflog_msg = getenv("GIT_REFLOG_ACTION");
builtin/commit.c +2 -2
index d3e7781e65..2785344fed 100644
@@ -1675,8 +1675,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	}
 
 	if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
-				 parents, &oid, author_ident.buf, sign_commit,
-				 extra)) {
+				 parents, &oid, author_ident.buf, NULL,
+				 sign_commit, extra)) {
 		rollback_index_files();
 		die(_("failed to write commit object"));
 	}
commit.c +7 -4
index c7099daeac..fb63c22cc1 100644
@@ -1324,8 +1324,8 @@ int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree,
 	int result;
 
 	append_merge_tag_headers(parents, &tail);
-	result = commit_tree_extended(msg, msg_len, tree, parents, ret,
-				      author, sign_commit, extra);
+	result = commit_tree_extended(msg, msg_len, tree, parents, ret, author,
+				      NULL, sign_commit, extra);
 	free_commit_extra_headers(extra);
 	return result;
 }
@@ -1448,7 +1448,8 @@ N_("Warning: commit message did not conform to UTF-8.\n"
 int commit_tree_extended(const char *msg, size_t msg_len,
 			 const struct object_id *tree,
 			 struct commit_list *parents, struct object_id *ret,
-			 const char *author, const char *sign_commit,
+			 const char *author, const char *committer,
+			 const char *sign_commit,
 			 struct commit_extra_header *extra)
 {
 	int result;
@@ -1481,7 +1482,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 	if (!author)
 		author = git_author_info(IDENT_STRICT);
 	strbuf_addf(&buffer, "author %s\n", author);
-	strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_STRICT));
+	if (!committer)
+		committer = git_committer_info(IDENT_STRICT);
+	strbuf_addf(&buffer, "committer %s\n", committer);
 	if (!encoding_is_utf8)
 		strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
 
commit.h +3 -4
index 008a0fa4a0..8f4227ae5c 100644
@@ -316,10 +316,9 @@ int commit_tree(const char *msg, size_t msg_len,
 
 int commit_tree_extended(const char *msg, size_t msg_len,
 			 const struct object_id *tree,
-			 struct commit_list *parents,
-			 struct object_id *ret, const char *author,
-			 const char *sign_commit,
-			 struct commit_extra_header *);
+			 struct commit_list *parents, struct object_id *ret,
+			 const char *author, const char *committer,
+			 const char *sign_commit, struct commit_extra_header *);
 
 struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
 
ident.c +14 -10
index e666ee4e59..7cbf223350 100644
@@ -361,11 +361,15 @@ N_("\n"
 const char *fmt_ident(const char *name, const char *email,
 		      enum want_ident whose_ident, const char *date_str, int flag)
 {
-	static struct strbuf ident = STRBUF_INIT;
+	static int index;
+	static struct strbuf ident_pool[2] = { STRBUF_INIT, STRBUF_INIT };
 	int strict = (flag & IDENT_STRICT);
 	int want_date = !(flag & IDENT_NO_DATE);
 	int want_name = !(flag & IDENT_NO_NAME);
 
+	struct strbuf *ident = &ident_pool[index];
+	index = (index + 1) % ARRAY_SIZE(ident_pool);
+
 	if (!email) {
 		if (whose_ident == WANT_AUTHOR_IDENT && git_author_email.len)
 			email = git_author_email.buf;
@@ -421,25 +425,25 @@ const char *fmt_ident(const char *name, const char *email,
 			die(_("name consists only of disallowed characters: %s"), name);
 	}
 
-	strbuf_reset(&ident);
+	strbuf_reset(ident);
 	if (want_name) {
-		strbuf_addstr_without_crud(&ident, name);
-		strbuf_addstr(&ident, " <");
+		strbuf_addstr_without_crud(ident, name);
+		strbuf_addstr(ident, " <");
 	}
-	strbuf_addstr_without_crud(&ident, email);
+	strbuf_addstr_without_crud(ident, email);
 	if (want_name)
-			strbuf_addch(&ident, '>');
+		strbuf_addch(ident, '>');
 	if (want_date) {
-		strbuf_addch(&ident, ' ');
+		strbuf_addch(ident, ' ');
 		if (date_str && date_str[0]) {
-			if (parse_date(date_str, &ident) < 0)
+			if (parse_date(date_str, ident) < 0)
 				die(_("invalid date format: %s"), date_str);
 		}
 		else
-			strbuf_addstr(&ident, ident_default_date());
+			strbuf_addstr(ident, ident_default_date());
 	}
 
-	return ident.buf;
+	return ident->buf;
 }
 
 const char *fmt_name(enum want_ident whose_ident)
sequencer.c +2 -2
index 6fd2674632..968a2d4ef3 100644
@@ -1408,8 +1408,8 @@ static int try_to_commit(struct repository *r,
 
 	reset_ident_date();
 
-	if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
-				 oid, author, opts->gpg_sign, extra)) {
+	if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid,
+				 author, NULL, opts->gpg_sign, extra)) {
 		res = error(_("failed to write commit object"));
 		goto out;
 	}
Signature · 1 line
2.28.0
#119 lore raw

Re: [PATCH v8 2/5] am: stop exporting GIT_COMMITTER_DATE

Quoted 13 lines · Phillip Wood

From: Phillip Wood <[email protected]>

The implementation of --committer-date-is-author-date exports GIT_COMMITTER_DATE to override the default committer date but does not reset GIT_COMMITTER_DATE in the environment after creating the commit so it is set in the environment of any hooks that get run. We're about to add the same functionality to the sequencer and do not want to have GIT_COMMITTER_DATE set when running hooks or exec commands so lets update commit_tree_extended() to take an explicit committer so we override the default date without setting GIT_COMMITTER_DATE in the environment.

Quoted 8 lines
---
 builtin/am.c     | 28 +++++++++++++++++++++++-----
 builtin/commit.c |  4 ++--
 commit.c         | 11 +++++++----
 commit.h         |  7 +++----
 ident.c          | 24 ++++++++++++++----------
 sequencer.c      |  4 ++--
 6 files changed, 51 insertions(+), 27 deletions(-)

Nice.

Obviously this would affect the environment while am is running, and the change is observable by post-applypatch hook. I am not sure if this change-in-behaviour would negatively affect people's hooks, but given the large end-user population we have, somebody somewhere will get hit.

Quoted 7 lines
ident.c +0 -0
index e666ee4e59..7cbf223350 100644
@@ -361,11 +361,15 @@ N_("\n"
 const char *fmt_ident(const char *name, const char *email,
 		      enum want_ident whose_ident, const char *date_str, int flag)

ident.c N_("\n" · line 371

Quoted 10 lines
ident.c +4 -1
 {
-	static struct strbuf ident = STRBUF_INIT;
+	static int index;
+	static struct strbuf ident_pool[2] = { STRBUF_INIT, STRBUF_INIT };
 	int strict = (flag & IDENT_STRICT);
 	int want_date = !(flag & IDENT_NO_DATE);
 	int want_name = !(flag & IDENT_NO_NAME);
 
+	struct strbuf *ident = &ident_pool[index];
+	index = (index + 1) % ARRAY_SIZE(ident_pool);

2-element rotating buffer because we happen to care at most two idents at the same time, author's and committer's?

How many callers of fmt_ident() do we have these days? I wonder if we can introduce a new API that lets/forces the caller to prepare a strbuf and migrate the current callers of this function to it, of if it is too large a churn for the purpose of this series.

Thanks.

#120 lore raw

Re: [PATCH v8 2/5] am: stop exporting GIT_COMMITTER_DATE

Quoted 24 lines · Junio C Hamano
Quoted 13 lines · Phillip Wood

From: Phillip Wood <[email protected]>

The implementation of --committer-date-is-author-date exports GIT_COMMITTER_DATE to override the default committer date but does not reset GIT_COMMITTER_DATE in the environment after creating the commit so it is set in the environment of any hooks that get run. We're about to add the same functionality to the sequencer and do not want to have GIT_COMMITTER_DATE set when running hooks or exec commands so lets update commit_tree_extended() to take an explicit committer so we override the default date without setting GIT_COMMITTER_DATE in the environment.

Quoted 8 lines
---
 builtin/am.c     | 28 +++++++++++++++++++++++-----
 builtin/commit.c |  4 ++--
 commit.c         | 11 +++++++----
 commit.h         |  7 +++----
 ident.c          | 24 ++++++++++++++----------
 sequencer.c      |  4 ++--
 6 files changed, 51 insertions(+), 27 deletions(-)
Quoted 7 lines

Nice.

Obviously this would affect the environment while am is running, and the change is observable by post-applypatch hook. I am not sure if this change-in-behaviour would negatively affect people's hooks, but given the large end-user population we have, somebody somewhere will get hit.

Yes I did think about that but decided it was probably better to fix it. At the moment the pre-applypatch gets GIT_COMMITTER_DATE set to the date of the last commit which does not make much sense. If anyone does need the committer date in the post-applypatch hook they can look at HEAD. We should perhaps mention that in the release notes

Quoted 21 lines
Quoted 7 lines
ident.c +0 -0
index e666ee4e59..7cbf223350 100644
@@ -361,11 +361,15 @@ N_("\n"
 const char *fmt_ident(const char *name, const char *email,
 		      enum want_ident whose_ident, const char *date_str, int flag)

ident.c N_("\n" · line 371

Quoted 10 lines
ident.c +4 -1
 {
-	static struct strbuf ident = STRBUF_INIT;
+	static int index;
+	static struct strbuf ident_pool[2] = { STRBUF_INIT, STRBUF_INIT };
 	int strict = (flag & IDENT_STRICT);
 	int want_date = !(flag & IDENT_NO_DATE);
 	int want_name = !(flag & IDENT_NO_NAME);
 
+	struct strbuf *ident = &ident_pool[index];
+	index = (index + 1) % ARRAY_SIZE(ident_pool);

2-element rotating buffer because we happen to care at most two idents at the same time, author's and committer's?

Quoted 4 lines

How many callers of fmt_ident() do we have these days? I wonder if we can introduce a new API that lets/forces the caller to prepare a strbuf and migrate the current callers of this function to it, of if it is too large a churn for the purpose of this series.

After this series is applied there are the following callers

blame.c:207: ident = fmt_ident("Not Committed Yet", "not.committed.yet", builtin/am.c:1591: author = fmt_ident(state->author_name, state->author_email,
builtin/am.c:1597: committer = fmt_ident(state->committer_name, builtin/commit.c:638: strbuf_addstr(author_ident, fmt_ident(name, email, WANT_AUTHOR_IDENT, date,
ident.c:466: return fmt_ident(name, email, whose_ident, NULL, ident.c:476: return fmt_ident(getenv("GIT_AUTHOR_NAME"), ident.c:489: return fmt_ident(getenv("GIT_COMMITTER_NAME"), sequencer.c:1461: committer = fmt_ident(opts->committer_name, sequencer.c:1481: author = fmt_ident(name, email, WANT_AUTHOR_IDENT, NULL,

In blame.c we'd have to add an strbuf to pass in,

The caller in builtin/commit.c would obviously be easy to convert as it is stuffing the result into an strbuf already.

For am and the sequencer fmt_ident() is in a function which is called from a loop and it is convenient not to have to worry about passing an strbuf around or allocating and freeing it on each function call

The callers in ident (fmt_name(), git_author_info() and git_committer_info()) return the string so they would need their own strbuf or have to be changed so the caller passed one in. There are quite a few callers of those functions and they seem to either immediately call split_ident_line() or duplicate the returned string (mostly the latter).

So it would be a bit of work to do it but not an enormous amount (assuming we don't change the signature of git_author_info() etc in ident.c, although given the pattern of callers it might be worth doing that if they are mostly duplicating the returned string anyway)

I'm going to be off line for 10-14 days from the beginning of next week, I could take a look at it after that, or we could leave it for a future improvement - what do you think?

Best Wishes

Phillip

Quoted 3 lines

Thanks.

#121 lore raw

Re: [PATCH v8 2/5] am: stop exporting GIT_COMMITTER_DATE

Quoted 3 lines · Phillip Wood

For am and the sequencer fmt_ident() is in a function which is called from a loop and it is convenient not to have to worry about passing an strbuf around or allocating and freeing it on each function call

That's strbuf on caller's stack, right? The actual string pointed by the strbuf's buf pointer will be needed and on the heap with or without the clean-up on top of the patch we are discussing, so I do not think alloc/free would be in the picture when considering the pros-and-cons.

Quoted 11 lines

The callers in ident (fmt_name(), git_author_info() and git_committer_info()) return the string so they would need their own strbuf or have to be changed so the caller passed one in. There are quite a few callers of those functions and they seem to either immediately call split_ident_line() or duplicate the returned string (mostly the latter).

So it would be a bit of work to do it but not an enormous amount (assuming we don't change the signature of git_author_info() etc in ident.c, although given the pattern of callers it might be worth doing that if they are mostly duplicating the returned string anyway)

I'd say that is more than "while at it" clean-up. It would be easier to review and slightly easier to do if done before this patch introduces rotating strbuf, but ...

Quoted 3 lines

I'm going to be off line for 10-14 days from the beginning of next week, I could take a look at it after that, or we could leave it for a future improvement - what do you think?

... I can be talked into punting it for later, at least for now.

Thanks.

#122 lore raw

Re: [PATCH v8 2/5] am: stop exporting GIT_COMMITTER_DATE

Quoted 11 lines · Junio C Hamano
Quoted 3 lines · Phillip Wood

For am and the sequencer fmt_ident() is in a function which is called from a loop and it is convenient not to have to worry about passing an strbuf around or allocating and freeing it on each function call

That's strbuf on caller's stack, right? The actual string pointed by the strbuf's buf pointer will be needed and on the heap with or without the clean-up on top of the patch we are discussing, so I do not think alloc/free would be in the picture when considering the pros-and-cons.

At the moment we use the same allocation for the whole program (ignoring reallocation if the string grows). If we were to add an strbuf as a local variable in the function that gets called by the commit picking loop we either need to make it static and accept the leak or alloc and free the string each time the function is called. Either way I'd be amazed if it has any effect on the performance given we're performing a merge with each loop iteration.

Quoted 16 lines
Quoted 11 lines

The callers in ident (fmt_name(), git_author_info() and git_committer_info()) return the string so they would need their own strbuf or have to be changed so the caller passed one in. There are quite a few callers of those functions and they seem to either immediately call split_ident_line() or duplicate the returned string (mostly the latter).

So it would be a bit of work to do it but not an enormous amount (assuming we don't change the signature of git_author_info() etc in ident.c, although given the pattern of callers it might be worth doing that if they are mostly duplicating the returned string anyway)

I'd say that is more than "while at it" clean-up. It would be easier to review and slightly easier to do if done before this patch introduces rotating strbuf, but ...

Quoted 5 lines
Quoted 3 lines

I'm going to be off line for 10-14 days from the beginning of next week, I could take a look at it after that, or we could leave it for a future improvement - what do you think?

... I can be talked into punting it for later, at least for now.

I'm tempted to say leave it for now but if this isn't in next by the time I'm back online I'll look at rerolling.

Best Wishes

Phillip

Quoted 3 lines

Thanks.

#123 lore raw

PATCH v8 3/5 rebase -i: support --committer-date-is-author-date

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --committer-date-is-author-date option to the merge backend. This option uses the author date of the commit that is being rewritten as the committer date when the new commit is created.

---
 Documentation/git-rebase.txt           | 10 ++-
 builtin/rebase.c                       | 17 +++--
 sequencer.c                            | 86 +++++++++++++++++++++++++-
 sequencer.h                            |  3 +
 t/t3422-rebase-incompatible-options.sh |  1 -
 t/t3436-rebase-more-options.sh         | 58 ++++++++++++++++-
 6 files changed, 162 insertions(+), 13 deletions(-)
Documentation/git-rebase.txt +7 -3
index b003784f01..f9ddfe2e77 100644
@@ -445,9 +445,13 @@ if the other side had no changes that conflicted.
 See also INCOMPATIBLE OPTIONS below.
 
 --committer-date-is-author-date::
+	Instead of using the current time as the committer date, use
+	the author date of the commit being rebased as the committer
+	date. This option implies `--force-rebase`.
+
 --ignore-date::
-	These flags are passed to 'git am' to easily change the dates
-	of the rebased commits (see linkgit:git-am[1]).
+	This flag is passed to 'git am' to change the author date
+	of each rebased commit (see linkgit:git-am[1]).
 +
 See also INCOMPATIBLE OPTIONS below.
 
@@ -585,7 +589,6 @@ INCOMPATIBLE OPTIONS
 The following options:
 
  * --apply
- * --committer-date-is-author-date
  * --ignore-date
  * --whitespace
  * -C
@@ -613,6 +616,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --rebase-merges
  * --preserve-merges and --empty=
  * --preserve-merges and --ignore-whitespace
+ * --preserve-merges and --committer-date-is-author-date
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +12 -5
index bd93e9742c..2579380729 100644
@@ -88,6 +88,7 @@ struct rebase_options {
 	int autosquash;
 	char *gpg_sign_opt;
 	int autostash;
+	int committer_date_is_author_date;
 	char *cmd;
 	int allow_empty_message;
 	int rebase_merges, rebase_cousins;
@@ -124,6 +125,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.quiet = !(opts->flags & REBASE_NO_QUIET);
 	replay.verbose = opts->flags & REBASE_VERBOSE;
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
+	replay.committer_date_is_author_date =
+					opts->committer_date_is_author_date;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
 
@@ -1497,9 +1500,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
 		OPT_BOOL(0, "signoff", &options.signoff,
 			 N_("add a Signed-off-by: line to each commit")),
-		OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
-				  &options.git_am_opts, NULL,
-				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
+		OPT_BOOL(0, "committer-date-is-author-date",
+			 &options.committer_date_is_author_date,
+			 N_("make committer date match author date")),
 		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
 				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
@@ -1794,11 +1797,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	    options.autosquash) {
 		allow_preemptive_ff = 0;
 	}
+	if (options.committer_date_is_author_date)
+		options.flags |= REBASE_FORCE;
 
 	for (i = 0; i < options.git_am_opts.argc; i++) {
 		const char *option = options.git_am_opts.argv[i], *p;
-		if (!strcmp(option, "--committer-date-is-author-date") ||
-		    !strcmp(option, "--ignore-date") ||
+		if (!strcmp(option, "--ignore-date") ||
 		    !strcmp(option, "--whitespace=fix") ||
 		    !strcmp(option, "--whitespace=strip"))
 			allow_preemptive_ff = 0;
@@ -1855,6 +1859,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		if (ignore_whitespace)
 			argv_array_push(&options.git_am_opts,
 					"--ignore-whitespace");
+		if (options.committer_date_is_author_date)
+			argv_array_push(&options.git_am_opts,
+					"--committer-date-is-author-date");
 	} else {
 		/* REBASE_MERGE and PRESERVE_MERGES */
 		if (ignore_whitespace) {
sequencer.c +83 -3

166 lines not on this page · raw message

sequencer.h +3 -0
index 0bee85093e..7ca657fe2c 100644
@@ -45,9 +45,12 @@ struct replay_opts {
 	int verbose;
 	int quiet;
 	int reschedule_failed_exec;
+	int committer_date_is_author_date;
 
 	int mainline;
 
+	char *committer_name;
+	char *committer_email;
 	char *gpg_sign;
 	enum commit_msg_cleanup_mode default_msg_cleanup;
 	int explicit_cleanup;
t/t3422-rebase-incompatible-options.sh +0 -1
index 55ca46786d..c8234062c6 100755
@@ -61,7 +61,6 @@ test_rebase_am_only () {
 }
 
 test_rebase_am_only --whitespace=fix
-test_rebase_am_only --committer-date-is-author-date
 test_rebase_am_only -C4
 
 test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
t/t3436-rebase-more-options.sh +57 -1

80 lines not on this page · raw message

Signature · 1 line
2.28.0
#124 lore raw

Re: [PATCH v8 3/5] rebase -i: support --committer-date-is-author-date

Quoted 15 lines · Phillip Wood
t/t3436-rebase-more-options.sh +3 -0
index 4f8a6e51c9..50a63d8ebe 100755
@@ -9,6 +9,9 @@ test_description='tests to ensure compatibility between am and interactive backe
 
 . "$TEST_DIRECTORY"/lib-rebase.sh
 
+GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
+export GIT_AUTHOR_DATE
+
 # This is a special case in which both am and interactive backends
 # provide the same output. It was done intentionally because
 # both the backends fall short of optimal behaviour.

t/t3436-rebase-more-options.sh test_expect_success 'setup' ' · line 29

Quoted 6 lines
t/t3436-rebase-more-options.sh +4 -0
@@ -21,11 +24,20 @@ test_expect_success 'setup' '
 	test_write_lines "line 1" "new line 2" "line 3" >file &&
 	git commit -am "update file" &&
+ ...
+	mkdir test-bin &&
+	write_script test-bin/git-merge-test <<-\EOF
+	exec git-merge-recursive "$@"

This should be

exec git merge-recursive "$@"

Quoted 2 lines
t/t3436-rebase-more-options.sh +1 -0
+	EOF
 '
#125 lore raw

PATCH v8 4/5 rebase -i: support --ignore-date

In reply to Phillip Wood

From: Phillip Wood <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.

---
 Documentation/git-rebase.txt   |  7 ++--
 builtin/rebase.c               | 13 ++++---
 sequencer.c                    | 66 +++++++++++++++++++++++++++-------
 sequencer.h                    |  1 +
 t/t3436-rebase-more-options.sh | 56 +++++++++++++++++++++++++++++
 5 files changed, 123 insertions(+), 20 deletions(-)
Documentation/git-rebase.txt +4 -3
index f9ddfe2e77..79cecd2929 100644
@@ -450,8 +450,9 @@ See also INCOMPATIBLE OPTIONS below.
 	date. This option implies `--force-rebase`.
 
 --ignore-date::
-	This flag is passed to 'git am' to change the author date
-	of each rebased commit (see linkgit:git-am[1]).
+	Instead of using the author date of the original commit, use
+	the current time as the	author date of the rebased commit.  This
+	option implies `--force-rebase`.
 +
 See also INCOMPATIBLE OPTIONS below.
 
@@ -589,7 +590,6 @@ INCOMPATIBLE OPTIONS
 The following options:
 
  * --apply
- * --ignore-date
  * --whitespace
  * -C
 
@@ -617,6 +617,7 @@ In addition, the following pairs of options are incompatible:
  * --preserve-merges and --empty=
  * --preserve-merges and --ignore-whitespace
  * --preserve-merges and --committer-date-is-author-date
+ * --preserve-merges and --ignore-date
  * --keep-base and --onto
  * --keep-base and --root
 
builtin/rebase.c +8 -5
index 2579380729..583ac96fc7 100644
@@ -89,6 +89,7 @@ struct rebase_options {
 	char *gpg_sign_opt;
 	int autostash;
 	int committer_date_is_author_date;
+	int ignore_date;
 	char *cmd;
 	int allow_empty_message;
 	int rebase_merges, rebase_cousins;
@@ -127,6 +128,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
 	replay.reschedule_failed_exec = opts->reschedule_failed_exec;
 	replay.committer_date_is_author_date =
 					opts->committer_date_is_author_date;
+	replay.ignore_date = opts->ignore_date;
 	replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
 	replay.strategy = opts->strategy;
 
@@ -1503,8 +1505,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "committer-date-is-author-date",
 			 &options.committer_date_is_author_date,
 			 N_("make committer date match author date")),
-		OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
-				  N_("passed to 'git am'"), PARSE_OPT_NOARG),
+		OPT_BOOL(0, "ignore-date", &options.ignore_date,
+			 N_("ignore author date and use current date")),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
 		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
@@ -1797,13 +1799,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	    options.autosquash) {
 		allow_preemptive_ff = 0;
 	}
-	if (options.committer_date_is_author_date)
+	if (options.committer_date_is_author_date || options.ignore_date)
 		options.flags |= REBASE_FORCE;
 
 	for (i = 0; i < options.git_am_opts.argc; i++) {
 		const char *option = options.git_am_opts.argv[i], *p;
-		if (!strcmp(option, "--ignore-date") ||
-		    !strcmp(option, "--whitespace=fix") ||
+		if (!strcmp(option, "--whitespace=fix") ||
 		    !strcmp(option, "--whitespace=strip"))
 			allow_preemptive_ff = 0;
 		else if (skip_prefix(option, "-C", &p)) {
@@ -1862,6 +1863,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		if (options.committer_date_is_author_date)
 			argv_array_push(&options.git_am_opts,
 					"--committer-date-is-author-date");
+		if (options.ignore_date)
+			argv_array_push(&options.git_am_opts, "--ignore-date");
 	} else {
 		/* REBASE_MERGE and PRESERVE_MERGES */
 		if (ignore_whitespace) {
sequencer.c +54 -12

119 lines not on this page · raw message

sequencer.h +1 -0
index 7ca657fe2c..20493a2be2 100644
@@ -46,6 +46,7 @@ struct replay_opts {
 	int quiet;
 	int reschedule_failed_exec;
 	int committer_date_is_author_date;
+	int ignore_date;
 
 	int mainline;
 
t/t3436-rebase-more-options.sh +56 -0

62 lines not on this page · raw message

Signature · 1 line
2.28.0
#126 lore raw

Re: [PATCH v8 4/5] rebase -i: support --ignore-date

Quoted 31 lines · Phillip Wood

From: Phillip Wood <[email protected]>

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. In particular the apply backend supports a number of options implemented by 'git am' that are not implemented in the merge backend. This means that the available options are different depending on which backend is used which is confusing. This patch adds support for the --ignore-date option to the merge backend. This option uses the current time as the author date rather than reusing the original author date when rewriting commits. We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.

---
 Documentation/git-rebase.txt   |  7 ++--
 builtin/rebase.c               | 13 ++++---
 sequencer.c                    | 66 +++++++++++++++++++++++++++-------
 sequencer.h                    |  1 +
 t/t3436-rebase-more-options.sh | 56 +++++++++++++++++++++++++++++
 5 files changed, 123 insertions(+), 20 deletions(-)

[...]

t/t3436-rebase-more-options.sh +0 -0
index 50a63d8ebe..0ede2b8900 100755
@@ -108,6 +108,62 @@ test_expect_success '--committer-date-is-author-date works when committing confl
 	test_ctime_is_atime -1

t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 118

Quoted 10 lines
t/t3436-rebase-more-options.sh +8 -0
 '
 
+# Checking for +0000 in the author date is sufficient since the
+# default timezone is UTC but the timezone used while committing is
+# +0530. The inverted logic in the grep is necessary to check all the
+# author dates in the file.
+test_ctime_is_ignored () {
+	git log $1 --format=%ai >authortime &&
+	! grep -v +0000 authortime
+}

I don't know what I was thinking when I wrote that - it should be called test_atime_is_ignored() as it's testing the author date

Best Wishes

Phillip

#127 lore raw

Re: [PATCH v8 4/5] rebase -i: support --ignore-date

Quoted 4 lines · Phillip Wood
Quoted 4 lines
t/t3436-rebase-more-options.sh +4 -0
+# Checking for +0000 in the author date is sufficient since the
+# default timezone is UTC but the timezone used while committing is
+# +0530. The inverted logic in the grep is necessary to check all the
+# author dates in the file.
Quoted 8 lines

t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 118

Quoted 4 lines
t/t3436-rebase-more-options.sh +4 -0
+test_ctime_is_ignored () {
+	git log $1 --format=%ai >authortime &&
+	! grep -v +0000 authortime
+}

I don't know what I was thinking when I wrote that - it should be called test_atime_is_ignored() as it's testing the author date

Will tweak locally. No need to resend.

Thanks.

#128 lore raw

Re: [PATCH v8 4/5] rebase -i: support --ignore-date

Quoted 15 lines · Junio C Hamano
Quoted 4 lines · Phillip Wood
Quoted 4 lines
t/t3436-rebase-more-options.sh +4 -0
+# Checking for +0000 in the author date is sufficient since the
+# default timezone is UTC but the timezone used while committing is
+# +0530. The inverted logic in the grep is necessary to check all the
+# author dates in the file.
Quoted 8 lines

t/t3436-rebase-more-options.sh test_expect_success '--committer-date-is-author-date works when committing confl · line 118

Quoted 4 lines
t/t3436-rebase-more-options.sh +4 -0
+test_ctime_is_ignored () {
+	git log $1 --format=%ai >authortime &&
+	! grep -v +0000 authortime
+}

I don't know what I was thinking when I wrote that - it should be called test_atime_is_ignored() as it's testing the author date

Quoted 1 line

Will tweak locally. No need to resend.

Thanks for doing that

Best wishes

Phillip

Quoted 2 lines

Thanks.

#129 lore raw

PATCH v8 5/5 rebase: add --reset-author-date

In reply to Phillip Wood

From: Rohit Ashiwal <[email protected]>

The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored. Add an alias to convey the precise purpose.

---
 Documentation/git-rebase.txt   |  1 +
 builtin/rebase.c               |  4 +++-
 t/t3436-rebase-more-options.sh | 34 +++++++++++++++++++++-------------
 3 files changed, 25 insertions(+), 14 deletions(-)
Documentation/git-rebase.txt +1 -0
index 79cecd2929..1ee3bb4fac 100644
@@ -450,6 +450,7 @@ See also INCOMPATIBLE OPTIONS below.
 	date. This option implies `--force-rebase`.
 
 --ignore-date::
+--reset-author-date::
 	Instead of using the author date of the original commit, use
 	the current time as the	author date of the rebased commit.  This
 	option implies `--force-rebase`.
builtin/rebase.c +3 -1
index 583ac96fc7..b126fbe940 100644
@@ -1505,8 +1505,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "committer-date-is-author-date",
 			 &options.committer_date_is_author_date,
 			 N_("make committer date match author date")),
-		OPT_BOOL(0, "ignore-date", &options.ignore_date,
+		OPT_BOOL(0, "reset-author-date", &options.ignore_date,
 			 N_("ignore author date and use current date")),
+		OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date,
+				N_("synonym of --reset-author-date")),
 		OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
 				  N_("passed to 'git apply'"), 0),
 		OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
t/t3436-rebase-more-options.sh +21 -13
index 0ede2b8900..5b8963272a 100755
@@ -117,53 +117,61 @@ test_ctime_is_ignored () {
 	! grep -v +0000 authortime
 }
 
-test_expect_success '--ignore-date works with apply backend' '
+test_expect_success '--reset-author-date works with apply backend' '
 	git commit --amend --date="$GIT_AUTHOR_DATE" &&
-	git rebase --apply --ignore-date HEAD^ &&
+	git rebase --apply --reset-author-date HEAD^ &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works with merge backend' '
+test_expect_success '--reset-author-date works with merge backend' '
 	git commit --amend --date="$GIT_AUTHOR_DATE" &&
-	git rebase --ignore-date -m HEAD^ &&
+	git rebase --reset-author-date -m HEAD^ &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works after conflict resolution' '
-	test_must_fail git rebase --ignore-date -m \
+test_expect_success '--reset-author-date works after conflict resolution' '
+	test_must_fail git rebase --reset-author-date -m \
 		--onto commit2^^ commit2^ commit2 &&
 	echo resolved >foo &&
 	git add foo &&
 	git rebase --continue &&
 	test_ctime_is_ignored -1
 '
 
-test_expect_success '--ignore-date works with rebase -r' '
+test_expect_success '--reset-author-date works with rebase -r' '
 	git checkout side &&
 	git merge --no-ff commit3 &&
-	git rebase -r --root --ignore-date &&
+	git rebase -r --root --reset-author-date &&
 	test_ctime_is_ignored
 '
 
-test_expect_success '--ignore-date with --committer-date-is-author-date works' '
+test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
 	test_must_fail git rebase -m --committer-date-is-author-date \
-		--ignore-date --onto commit2^^ commit2^ commit3 &&
+		--reset-author-date --onto commit2^^ commit2^ commit3 &&
 	git checkout --theirs foo &&
 	git add foo &&
 	git rebase --continue &&
 	test_ctime_is_atime -2 &&
 	test_ctime_is_ignored -2
 '
 
-test_expect_success '--ignore-date --committer-date-is-author-date works when forking merge' '
+test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
 	GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
 		PATH="./test-bin:$PATH" git rebase -i --strategy=test \
-				--ignore-date --committer-date-is-author-date \
-				side side &&
+				--reset-author-date \
+				--committer-date-is-author-date side side &&
 	test_ctime_is_atime -1 &&
 	test_ctime_is_ignored -1
  '
 
+test_expect_success '--ignore-date is an alias for --reset-author-date' '
+	git commit --amend --date="$GIT_AUTHOR_DATE" &&
+	git rebase --apply --ignore-date HEAD^ &&
+	git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
+	git rebase -m --ignore-date HEAD^ &&
+	test_ctime_is_ignored -2
+'
+
 # This must be the last test in this file
 test_expect_success '$EDITOR and friends are unchanged' '
 	test_editor_unchanged
Signature · 1 line
2.28.0