diff options
Diffstat (limited to 'debian/patches/0007-Revert-Add-a-helper-function-to-compare-file-contents.diff')
-rw-r--r-- | debian/patches/0007-Revert-Add-a-helper-function-to-compare-file-contents.diff | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/debian/patches/0007-Revert-Add-a-helper-function-to-compare-file-contents.diff b/debian/patches/0007-Revert-Add-a-helper-function-to-compare-file-contents.diff new file mode 100644 index 0000000..6cf2874 --- /dev/null +++ b/debian/patches/0007-Revert-Add-a-helper-function-to-compare-file-contents.diff @@ -0,0 +1,185 @@ +From 13b17dea6c851b21ceb9ce163cdd7338f1ec4ecf Mon Sep 17 00:00:00 2001 +From: Johannes Schindelin <johannes.schindelin@gmx.de> +Date: Sat, 18 May 2024 10:32:46 +0000 +Subject: Revert "Add a helper function to compare file contents" + +commit 851218a8af645b0abd64882d2b88bc984aa762e9 upstream. + +Now that during a `git clone`, the hooks' contents are no longer +compared to the templates' files', the caller for which the +`do_files_match()` function was introduced is gone, and therefore this +function can be retired, too. + +This reverts commit 584de0b4c23 (Add a helper function to compare file +contents, 2024-03-30). + +Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> +Signed-off-by: Junio C Hamano <gitster@pobox.com> +Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> +--- + copy.c | 58 -------------------------------------- + copy.h | 14 --------- + t/helper/test-path-utils.c | 10 ------- + t/t0060-path-utils.sh | 41 --------------------------- + 4 files changed, 123 deletions(-) + +diff --git a/copy.c b/copy.c +index 3df156f6cea..d9d20920126 100644 +--- a/copy.c ++++ b/copy.c +@@ -70,61 +70,3 @@ int copy_file_with_time(const char *dst, const char *src, int mode) + return copy_times(dst, src); + return status; + } +- +-static int do_symlinks_match(const char *path1, const char *path2) +-{ +- struct strbuf buf1 = STRBUF_INIT, buf2 = STRBUF_INIT; +- int ret = 0; +- +- if (!strbuf_readlink(&buf1, path1, 0) && +- !strbuf_readlink(&buf2, path2, 0)) +- ret = !strcmp(buf1.buf, buf2.buf); +- +- strbuf_release(&buf1); +- strbuf_release(&buf2); +- return ret; +-} +- +-int do_files_match(const char *path1, const char *path2) +-{ +- struct stat st1, st2; +- int fd1 = -1, fd2 = -1, ret = 1; +- char buf1[8192], buf2[8192]; +- +- if ((fd1 = open_nofollow(path1, O_RDONLY)) < 0 || +- fstat(fd1, &st1) || !S_ISREG(st1.st_mode)) { +- if (fd1 < 0 && errno == ELOOP) +- /* maybe this is a symbolic link? */ +- return do_symlinks_match(path1, path2); +- ret = 0; +- } else if ((fd2 = open_nofollow(path2, O_RDONLY)) < 0 || +- fstat(fd2, &st2) || !S_ISREG(st2.st_mode)) { +- ret = 0; +- } +- +- if (ret) +- /* to match, neither must be executable, or both */ +- ret = !(st1.st_mode & 0111) == !(st2.st_mode & 0111); +- +- if (ret) +- ret = st1.st_size == st2.st_size; +- +- while (ret) { +- ssize_t len1 = read_in_full(fd1, buf1, sizeof(buf1)); +- ssize_t len2 = read_in_full(fd2, buf2, sizeof(buf2)); +- +- if (len1 < 0 || len2 < 0 || len1 != len2) +- ret = 0; /* read error or different file size */ +- else if (!len1) /* len2 is also 0; hit EOF on both */ +- break; /* ret is still true */ +- else +- ret = !memcmp(buf1, buf2, len1); +- } +- +- if (fd1 >= 0) +- close(fd1); +- if (fd2 >= 0) +- close(fd2); +- +- return ret; +-} +diff --git a/copy.h b/copy.h +index 057259a3a7a..2af77cba864 100644 +--- a/copy.h ++++ b/copy.h +@@ -7,18 +7,4 @@ int copy_fd(int ifd, int ofd); + int copy_file(const char *dst, const char *src, int mode); + int copy_file_with_time(const char *dst, const char *src, int mode); + +-/* +- * Compare the file mode and contents of two given files. +- * +- * If both files are actually symbolic links, the function returns 1 if the link +- * targets are identical or 0 if they are not. +- * +- * If any of the two files cannot be accessed or in case of read failures, this +- * function returns 0. +- * +- * If the file modes and contents are identical, the function returns 1, +- * otherwise it returns 0. +- */ +-int do_files_match(const char *path1, const char *path2); +- + #endif /* COPY_H */ +diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c +index 023ed2e1a78..bf0e23ed505 100644 +--- a/t/helper/test-path-utils.c ++++ b/t/helper/test-path-utils.c +@@ -501,16 +501,6 @@ int cmd__path_utils(int argc, const char **argv) + return !!res; + } + +- if (argc == 4 && !strcmp(argv[1], "do_files_match")) { +- int ret = do_files_match(argv[2], argv[3]); +- +- if (ret) +- printf("equal\n"); +- else +- printf("different\n"); +- return !ret; +- } +- + fprintf(stderr, "%s: unknown function name: %s\n", argv[0], + argv[1] ? argv[1] : "(there was none)"); + return 1; +diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh +index 85686ee15da..0afa3d0d312 100755 +--- a/t/t0060-path-utils.sh ++++ b/t/t0060-path-utils.sh +@@ -610,45 +610,4 @@ test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' + test_cmp expect actual + ' + +-test_expect_success 'do_files_match()' ' +- test_seq 0 10 >0-10.txt && +- test_seq -1 10 >-1-10.txt && +- test_seq 1 10 >1-10.txt && +- test_seq 1 9 >1-9.txt && +- test_seq 0 8 >0-8.txt && +- +- test-tool path-utils do_files_match 0-10.txt 0-10.txt >out && +- +- assert_fails() { +- test_must_fail \ +- test-tool path-utils do_files_match "$1" "$2" >out && +- grep different out +- } && +- +- assert_fails 0-8.txt 1-9.txt && +- assert_fails -1-10.txt 0-10.txt && +- assert_fails 1-10.txt 1-9.txt && +- assert_fails 1-10.txt .git && +- assert_fails does-not-exist 1-10.txt && +- +- if test_have_prereq FILEMODE +- then +- cp 0-10.txt 0-10.x && +- chmod a+x 0-10.x && +- assert_fails 0-10.txt 0-10.x +- fi && +- +- if test_have_prereq SYMLINKS +- then +- ln -sf 0-10.txt symlink && +- ln -s 0-10.txt another-symlink && +- ln -s over-the-ocean yet-another-symlink && +- ln -s "$PWD/0-10.txt" absolute-symlink && +- assert_fails 0-10.txt symlink && +- test-tool path-utils do_files_match symlink another-symlink && +- assert_fails symlink yet-another-symlink && +- assert_fails symlink absolute-symlink +- fi +-' +- + test_done |