Commit 1ecbcd8e by Colomban Wendling

Fix ident replacement to match Git behavior

Git inserts a space after the SHA1 (as of 2.1.4 at least), so do the
same.
parent c11daac9
...@@ -56,7 +56,7 @@ static int ident_insert_id( ...@@ -56,7 +56,7 @@ static int ident_insert_id(
return GIT_PASSTHROUGH; return GIT_PASSTHROUGH;
need_size = (size_t)(id_start - from->ptr) + need_size = (size_t)(id_start - from->ptr) +
5 /* "$Id: " */ + GIT_OID_HEXSZ + 1 /* "$" */ + 5 /* "$Id: " */ + GIT_OID_HEXSZ + 2 /* " $" */ +
(size_t)(from_end - id_end); (size_t)(from_end - id_end);
if (git_buf_grow(to, need_size) < 0) if (git_buf_grow(to, need_size) < 0)
...@@ -65,7 +65,7 @@ static int ident_insert_id( ...@@ -65,7 +65,7 @@ static int ident_insert_id(
git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr)); git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
git_buf_put(to, "$Id: ", 5); git_buf_put(to, "$Id: ", 5);
git_buf_put(to, oid, GIT_OID_HEXSZ); git_buf_put(to, oid, GIT_OID_HEXSZ);
git_buf_putc(to, '$'); git_buf_put(to, " $", 2);
git_buf_put(to, id_end, (size_t)(from_end - id_end)); git_buf_put(to, id_end, (size_t)(from_end - id_end));
return git_buf_oom(to) ? -1 : 0; return git_buf_oom(to) ? -1 : 0;
......
...@@ -221,29 +221,29 @@ void test_checkout_crlf__with_ident(void) ...@@ -221,29 +221,29 @@ void test_checkout_crlf__with_ident(void)
if (GIT_EOL_NATIVE == GIT_EOL_LF) { if (GIT_EOL_NATIVE == GIT_EOL_LF) {
cl_assert_equal_file( cl_assert_equal_file(
ALL_LF_TEXT_RAW ALL_LF_TEXT_RAW
"\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\n", "\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\n",
0, "crlf/lf.ident"); 0, "crlf/lf.ident");
cl_assert_equal_file( cl_assert_equal_file(
ALL_CRLF_TEXT_AS_LF ALL_CRLF_TEXT_AS_LF
"\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857$\n\n", "\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\n\n",
0, "crlf/crlf.ident"); 0, "crlf/crlf.ident");
} else { } else {
cl_assert_equal_file( cl_assert_equal_file(
ALL_LF_TEXT_AS_CRLF ALL_LF_TEXT_AS_CRLF
"\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\r\n", "\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467 $\r\n",
0, "crlf/lf.ident"); 0, "crlf/lf.ident");
cl_assert_equal_file( cl_assert_equal_file(
ALL_CRLF_TEXT_RAW ALL_CRLF_TEXT_RAW
"\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857$\r\n\r\n", "\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857 $\r\n\r\n",
0, "crlf/crlf.ident"); 0, "crlf/crlf.ident");
} }
cl_assert_equal_file( cl_assert_equal_file(
"$Id: f7830382dac1f1583422be5530fdfbd26289431b$\n" "$Id: f7830382dac1f1583422be5530fdfbd26289431b $\n"
MORE_LF_TEXT_AS_LF, 0, "crlf/more1.identlf"); MORE_LF_TEXT_AS_LF, 0, "crlf/more1.identlf");
cl_assert_equal_file( cl_assert_equal_file(
"\r\n$Id: 74677a68413012ce8d7e7cfc3f12603df3a3eac4$\r\n" "\r\n$Id: 74677a68413012ce8d7e7cfc3f12603df3a3eac4 $\r\n"
MORE_CRLF_TEXT_AS_CRLF, 0, "crlf/more2.identcrlf"); MORE_CRLF_TEXT_AS_CRLF, 0, "crlf/more2.identcrlf");
git_index_free(index); git_index_free(index);
......
...@@ -105,11 +105,11 @@ void test_filter_blob__ident(void) ...@@ -105,11 +105,11 @@ void test_filter_blob__ident(void)
cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identcrlf", 1)); cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identcrlf", 1));
cl_assert_equal_s( cl_assert_equal_s(
"Some text\r\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845$\r\nGoes there\r\n", buf.ptr); "Some text\r\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845 $\r\nGoes there\r\n", buf.ptr);
cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identlf", 1)); cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identlf", 1));
cl_assert_equal_s( cl_assert_equal_s(
"Some text\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845$\nGoes there\n", buf.ptr); "Some text\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845 $\nGoes there\n", buf.ptr);
git_buf_free(&buf); git_buf_free(&buf);
git_blob_free(blob); git_blob_free(blob);
......
...@@ -318,7 +318,7 @@ void test_filter_custom__order_dependency(void) ...@@ -318,7 +318,7 @@ void test_filter_custom__order_dependency(void)
/* expansion because reverse was applied at checkin and at ident time, /* expansion because reverse was applied at checkin and at ident time,
* reverse is not applied yet */ * reverse is not applied yet */
cl_assert_equal_s( cl_assert_equal_s(
"Another test\n$59001fe193103b1016b27027c0c827d036fd0ac8 :dI$\nCrazy!\n", buf.ptr); "Another test\n$ 59001fe193103b1016b27027c0c827d036fd0ac8 :dI$\nCrazy!\n", buf.ptr);
cl_assert_equal_i(0, git_oid_strcmp( cl_assert_equal_i(0, git_oid_strcmp(
git_blob_id(blob), "8ca0df630d728c0c72072b6101b301391ef10095")); git_blob_id(blob), "8ca0df630d728c0c72072b6101b301391ef10095"));
git_blob_free(blob); git_blob_free(blob);
......
...@@ -49,22 +49,22 @@ void test_filter_ident__to_worktree(void) ...@@ -49,22 +49,22 @@ void test_filter_ident__to_worktree(void)
add_blob_and_filter( add_blob_and_filter(
"Hello\n$Id$\nFun stuff\n", fl, "Hello\n$Id$\nFun stuff\n", fl,
"Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30$\nFun stuff\n"); "Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30 $\nFun stuff\n");
add_blob_and_filter( add_blob_and_filter(
"Hello\n$Id: Junky$\nFun stuff\n", fl, "Hello\n$Id: Junky$\nFun stuff\n", fl,
"Hello\n$Id: 45cd107a7102911cb2a7df08404674327fa050b9$\nFun stuff\n"); "Hello\n$Id: 45cd107a7102911cb2a7df08404674327fa050b9 $\nFun stuff\n");
add_blob_and_filter( add_blob_and_filter(
"$Id$\nAt the start\n", fl, "$Id$\nAt the start\n", fl,
"$Id: b13415c767abc196fb95bd17070e8c1113e32160$\nAt the start\n"); "$Id: b13415c767abc196fb95bd17070e8c1113e32160 $\nAt the start\n");
add_blob_and_filter( add_blob_and_filter(
"At the end\n$Id$", fl, "At the end\n$Id$", fl,
"At the end\n$Id: 1344925c6bc65b34c5a7b50f86bf688e48e9a272$"); "At the end\n$Id: 1344925c6bc65b34c5a7b50f86bf688e48e9a272 $");
add_blob_and_filter( add_blob_and_filter(
"$Id$", fl, "$Id$", fl,
"$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1$"); "$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1 $");
add_blob_and_filter( add_blob_and_filter(
"$Id: Some sort of junk goes here$", fl, "$Id: Some sort of junk goes here$", fl,
"$Id: ab2dd3853c7c9a4bff55aca2bea077a73c32ac06$"); "$Id: ab2dd3853c7c9a4bff55aca2bea077a73c32ac06 $");
add_blob_and_filter("$Id: ", fl, "$Id: "); add_blob_and_filter("$Id: ", fl, "$Id: ");
add_blob_and_filter("$Id", fl, "$Id"); add_blob_and_filter("$Id", fl, "$Id");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment