From 0166027e56cd743fabc93191b525647153519f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20Ng=E1=BB=8Dc=20Qu=C3=A2n?= Date: Sat, 14 Dec 2013 14:43:04 +0700 Subject: [PATCH 001/760] l10n: Init Vietnamese translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Trần Ngọc Quân --- po/vi.po | 1351 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1351 insertions(+) create mode 100644 po/vi.po diff --git a/po/vi.po b/po/vi.po new file mode 100644 index 00000000000000..4dfe125a69f04b --- /dev/null +++ b/po/vi.po @@ -0,0 +1,1351 @@ +# Vietnamese translations for gitk package. +# Bản dịch tiếng Việt cho gói gitk. +# This file is distributed under the same license as the gitk package. +# Trần Ngọc Quân , 2013. +# +msgid "" +msgstr "" +"Project-Id-Version: gitk @@GIT_VERSION@@\n" +"Report-Msgid-Bugs-To: Paul Mackerras \n" +"POT-Creation-Date: 2013-12-14 09:24+0700\n" +"PO-Revision-Date: 2013-12-14 14:40+0700\n" +"Last-Translator: Trần Ngọc Quân \n" +"Language-Team: Vietnamese \n" +"Language: vi\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: gitk:140 +msgid "Couldn't get list of unmerged files:" +msgstr "Không thể lấy danh sách các tập-tin chưa được hòa trộn:" + +#: gitk:212 gitk:2353 +msgid "Color words" +msgstr "Tô màu chữ" + +#: gitk:217 gitk:2353 gitk:8103 gitk:8136 +msgid "Markup words" +msgstr "Đánh dấu chữ" + +#: gitk:322 +msgid "Error parsing revisions:" +msgstr "Gặp lỗi khi phân tích điểm xét duyệt:" + +#: gitk:378 +msgid "Error executing --argscmd command:" +msgstr "Gặp lỗi khi thực hiện lệnh --argscmd:" + +#: gitk:391 +msgid "No files selected: --merge specified but no files are unmerged." +msgstr "" +"Chưa chọn tập tin: --merge đã chỉ định nhưng không có tập tin chưa hòa trộn." + +#: gitk:394 +msgid "" +"No files selected: --merge specified but no unmerged files are within file " +"limit." +msgstr "" +"Chưa chọn tập tin: --merge đã chỉ định nhưng không có tập tin chưa hòa trộn " +"trong giới hạn tập tin." + +#: gitk:416 gitk:564 +msgid "Error executing git log:" +msgstr "Gặp lỗi khi thực hiện lệnh git log:" + +#: gitk:434 gitk:580 +msgid "Reading" +msgstr "Đang đọc" + +#: gitk:494 gitk:4429 +msgid "Reading commits..." +msgstr "Đang đọc các lần chuyển giao..." + +#: gitk:497 gitk:1635 gitk:4432 +msgid "No commits selected" +msgstr "Chưa chọn các lần chuyển giao" + +#: gitk:1509 +msgid "Can't parse git log output:" +msgstr "Không thể phân tích kết xuất từ lệnh git log:" + +#: gitk:1738 +msgid "No commit information available" +msgstr "Không có thông tin về lần chuyển giao nào" + +#: gitk:1895 +msgid "mc" +msgstr "mc" + +#: gitk:1930 gitk:4222 gitk:9552 gitk:11122 gitk:11401 +msgid "OK" +msgstr "Đồng ý" + +#: gitk:1932 gitk:4224 gitk:9079 gitk:9158 gitk:9274 gitk:9323 gitk:9554 +#: gitk:11123 gitk:11402 +msgid "Cancel" +msgstr "Thôi" + +#: gitk:2067 +msgid "Update" +msgstr "Cập nhật" + +#: gitk:2068 +msgid "Reload" +msgstr "Tải lại" + +#: gitk:2069 +msgid "Reread references" +msgstr "Đọc lại tham chiếu" + +#: gitk:2070 +msgid "List references" +msgstr "Liệt kê các tham chiếu" + +#: gitk:2072 +msgid "Start git gui" +msgstr "Khởi chạy git gui" + +#: gitk:2074 +msgid "Quit" +msgstr "Thoát" + +#: gitk:2066 +msgid "File" +msgstr "Chính" + +#: gitk:2078 +msgid "Preferences" +msgstr "Cá nhân hóa" + +#: gitk:2077 +msgid "Edit" +msgstr "Chỉnh sửa" + +#: gitk:2082 +msgid "New view..." +msgstr "Thêm trình bày mới..." + +#: gitk:2083 +msgid "Edit view..." +msgstr "Sửa cách trình bày..." + +#: gitk:2084 +msgid "Delete view" +msgstr "Xóa cách trình bày" + +#: gitk:2086 +msgid "All files" +msgstr "Mọi tập tin" + +#: gitk:2081 gitk:3975 +msgid "View" +msgstr "Trình bày" + +#: gitk:2091 gitk:2101 gitk:2945 +msgid "About gitk" +msgstr "Giới thiệu về gitk" + +#: gitk:2092 gitk:2106 +msgid "Key bindings" +msgstr "Tổ hợp phím" + +#: gitk:2090 gitk:2105 +msgid "Help" +msgstr "Trợ giúp" + +#: gitk:2183 gitk:8535 +msgid "SHA1 ID:" +msgstr "SHA1 ID:" + +#: gitk:2227 +msgid "Row" +msgstr "Hàng" + +#: gitk:2265 +msgid "Find" +msgstr "Tìm" + +#: gitk:2266 +msgid "next" +msgstr "tiếp" + +#: gitk:2267 +msgid "prev" +msgstr "trước" + +#: gitk:2268 +msgid "commit" +msgstr "lần chuyển giao" + +#: gitk:2271 gitk:2273 gitk:4590 gitk:4613 gitk:4637 gitk:6653 gitk:6725 +#: gitk:6810 +msgid "containing:" +msgstr "có chứa:" + +#: gitk:2274 gitk:3457 gitk:3462 gitk:4666 +msgid "touching paths:" +msgstr "đang chạm đường dẫn:" + +#: gitk:2275 gitk:4680 +msgid "adding/removing string:" +msgstr "thêm/gỡ bỏ chuỗi:" + +#: gitk:2276 gitk:4682 +msgid "changing lines matching:" +msgstr "những dòng thay đổi khớp mẫu:" + +#: gitk:2285 gitk:2287 gitk:4669 +msgid "Exact" +msgstr "Chính xác" + +#: gitk:2287 gitk:4757 gitk:6621 +msgid "IgnCase" +msgstr "BquaHt" + +#: gitk:2287 gitk:4639 gitk:4755 gitk:6617 +msgid "Regexp" +msgstr "BTCQ" + +#: gitk:2289 gitk:2290 gitk:4777 gitk:4807 gitk:4814 gitk:6746 gitk:6814 +msgid "All fields" +msgstr "Mọi trường" + +#: gitk:2290 gitk:4774 gitk:4807 gitk:6684 +msgid "Headline" +msgstr "Nội dung chính" + +#: gitk:2291 gitk:4774 gitk:6684 gitk:6814 gitk:7283 +msgid "Comments" +msgstr "Ghi chú" + +#: gitk:2291 gitk:4774 gitk:4779 gitk:4814 gitk:6684 gitk:7218 gitk:8713 +#: gitk:8728 +msgid "Author" +msgstr "Tác giả" + +#: gitk:2291 gitk:4774 gitk:6684 gitk:7220 +msgid "Committer" +msgstr "Người chuyển giao" + +#: gitk:2322 +msgid "Search" +msgstr "Tìm kiếm" + +#: gitk:2330 +msgid "Diff" +msgstr "So sánh" + +#: gitk:2332 +msgid "Old version" +msgstr "Phiên bản cũ" + +#: gitk:2334 +msgid "New version" +msgstr "Phiên bản mới" + +#: gitk:2336 +msgid "Lines of context" +msgstr "Các dòng của nội dung" + +#: gitk:2346 +msgid "Ignore space change" +msgstr "Không xét đến thay đổi do khoảng trắng" + +#: gitk:2350 gitk:2352 gitk:7842 gitk:8089 +msgid "Line diff" +msgstr "Khác biệt theo dòng" + +#: gitk:2417 +msgid "Patch" +msgstr "Vá" + +#: gitk:2419 +msgid "Tree" +msgstr "Cây" + +#: gitk:2577 gitk:2597 +msgid "Diff this -> selected" +msgstr "So sánh cái này -> cái đã chọn" + +#: gitk:2578 gitk:2598 +msgid "Diff selected -> this" +msgstr "So sánh cái đã chọn -> cái này" + +#: gitk:2579 gitk:2599 +msgid "Make patch" +msgstr "Tạo miếng vá" + +#: gitk:2580 gitk:9137 +msgid "Create tag" +msgstr "Tạo thẻ" + +#: gitk:2581 gitk:9254 +msgid "Write commit to file" +msgstr "Ghi lần chuyển giao ra tập tin" + +#: gitk:2582 gitk:9311 +msgid "Create new branch" +msgstr "Tạo nhánh mới" + +#: gitk:2583 +msgid "Cherry-pick this commit" +msgstr "Cherry-pick lần chuyển giao này" + +#: gitk:2584 +msgid "Reset HEAD branch to here" +msgstr "Đặt lại HEAD của nhánh vào đây" + +#: gitk:2585 +msgid "Mark this commit" +msgstr "Đánh dấu lần chuyển giao này" + +#: gitk:2586 +msgid "Return to mark" +msgstr "Quay lại vị trí dấu" + +#: gitk:2587 +msgid "Find descendant of this and mark" +msgstr "Tìm con cháu của cái này và cái đã đánh dấu" + +#: gitk:2588 +msgid "Compare with marked commit" +msgstr "So sánh với lần chuyển giao đã đánh dấu" + +#: gitk:2589 gitk:2600 +msgid "Diff this -> marked commit" +msgstr "So sánh cái này -> lần chuyển giao đã đánh dấu" + +#: gitk:2590 gitk:2601 +msgid "Diff marked commit -> this" +msgstr "So sánh lần chuyển giao đã đánh dấu -> cái này" + +#: gitk:2591 +msgid "Revert this commit" +msgstr "Hoàn lại lần chuyển giao này" + +#: gitk:2607 +msgid "Check out this branch" +msgstr "Checkout nhánh này" + +#: gitk:2608 +msgid "Remove this branch" +msgstr "Gỡ bỏ nhánh này" + +#: gitk:2615 +msgid "Highlight this too" +msgstr "Cũng tô sáng nó" + +#: gitk:2616 +msgid "Highlight this only" +msgstr "Chỉ tô sáng cái này" + +#: gitk:2617 +msgid "External diff" +msgstr "diff từ bên ngoài" + +#: gitk:2618 +msgid "Blame parent commit" +msgstr "Xem công trạng lần chuyển giao cha mẹ" + +#: gitk:2625 +msgid "Show origin of this line" +msgstr "Hiển thị nguyên gốc của dòng này" + +#: gitk:2626 +msgid "Run git gui blame on this line" +msgstr "Chạy lệnh git gui blame cho dòng này" + +#: gitk:2947 +msgid "" +"\n" +"Gitk - a commit viewer for git\n" +"\n" +"Copyright © 2005-2011 Paul Mackerras\n" +"\n" +"Use and redistribute under the terms of the GNU General Public License" +msgstr "" +"\n" +"Gitk - phần mềm xem các lần chuyển giao dành cho git\n" +"\n" +"Bản quyền © 2005-2011 Paul Mackerras\n" +"\n" +"Dùng và phân phối lại phần mềm này theo các điều khoản của Giấy Phép Công GNU" + +#: gitk:2955 gitk:3020 gitk:9738 +msgid "Close" +msgstr "Đóng" + +#: gitk:2976 +msgid "Gitk key bindings" +msgstr "Tổ hợp phím gitk" + +#: gitk:2979 +msgid "Gitk key bindings:" +msgstr "Tổ hợp phím gitk:" + +#: gitk:2981 +#, tcl-format +msgid "<%s-Q>\t\tQuit" +msgstr "<%s-Q>\t\tThoát" + +#: gitk:2982 +#, tcl-format +msgid "<%s-W>\t\tClose window" +msgstr "<%s-W>\t\tĐóng cửa sổ" + +#: gitk:2983 +msgid "\t\tMove to first commit" +msgstr "\t\tChuyển đến lần chuyển giao đầu tiên" + +#: gitk:2984 +msgid "\t\tMove to last commit" +msgstr "\t\tChuyển đến lần chuyển giao cuối" + +#: gitk:2985 +msgid ", p, k\tMove up one commit" +msgstr ", p, k\tDi chuyển lên một lần chuyển giao" + +#: gitk:2986 +msgid ", n, j\tMove down one commit" +msgstr ", n, j\tDi chuyển xuống một lần chuyển giao" + +#: gitk:2987 +msgid ", z, h\tGo back in history list" +msgstr ", z, h\tQuay trở lại danh sách lịch sử" + +#: gitk:2988 +msgid ", x, l\tGo forward in history list" +msgstr ", x, l\tDi chuyển tiếp trong danh sách lịch sử" + +#: gitk:2989 +msgid "\tMove up one page in commit list" +msgstr "\tDi chuyển lên một trang trong danh sách lần chuyển giao" + +#: gitk:2990 +msgid "\tMove down one page in commit list" +msgstr "\tDi chuyển xuống một trang trong danh sách lần chuyển giao" + +#: gitk:2991 +#, tcl-format +msgid "<%s-Home>\tScroll to top of commit list" +msgstr "<%s-Home>\tCuộn lên trên cùng của danh sách lần chuyển giao" + +#: gitk:2992 +#, tcl-format +msgid "<%s-End>\tScroll to bottom of commit list" +msgstr "<%s-End>\tCuộn xuống dưới cùng của danh sách lần chuyển giao" + +#: gitk:2993 +#, tcl-format +msgid "<%s-Up>\tScroll commit list up one line" +msgstr "<%s-Up>\tCuộn danh sách lần chuyển giao lên một dòng" + +#: gitk:2994 +#, tcl-format +msgid "<%s-Down>\tScroll commit list down one line" +msgstr "<%s-Down>\tCuộn danh sách lần chuyển giao xuống một dòng" + +#: gitk:2995 +#, tcl-format +msgid "<%s-PageUp>\tScroll commit list up one page" +msgstr "<%s-PageUp>\tCuộn danh sách lần chuyển giao lên một trang" + +#: gitk:2996 +#, tcl-format +msgid "<%s-PageDown>\tScroll commit list down one page" +msgstr "<%s-PageDown>\tCuộn danh sách lần chuyển giao xuống một trang" + +#: gitk:2997 +msgid "\tFind backwards (upwards, later commits)" +msgstr "\tTìm về phía sau (hướng lên trên, lần chuyển giao sau này)" + +#: gitk:2998 +msgid "\tFind forwards (downwards, earlier commits)" +msgstr "" +"\tTìm về phía trước (hướng xuống dưới, lần chuyển giao trước đây)" + +#: gitk:2999 +msgid ", b\tScroll diff view up one page" +msgstr ", b\tCuộn phần trình bày diff lên một trang" + +#: gitk:3000 +msgid "\tScroll diff view up one page" +msgstr "\tCuộn phần trình bày diff lên một trang" + +#: gitk:3001 +msgid "\t\tScroll diff view down one page" +msgstr "\t\tCuộn phần trình bày diff xuống một trang" + +#: gitk:3002 +msgid "u\t\tScroll diff view up 18 lines" +msgstr "u\t\tCuộn phần trình bày diff lên 18 dòng" + +#: gitk:3003 +msgid "d\t\tScroll diff view down 18 lines" +msgstr "d\t\tCuộn phần trình bày diff xuống 18 dòng" + +#: gitk:3004 +#, tcl-format +msgid "<%s-F>\t\tFind" +msgstr "<%s-F>\t\tTìm kiếm" + +#: gitk:3005 +#, tcl-format +msgid "<%s-G>\t\tMove to next find hit" +msgstr "<%s-G>\t\tDi chuyển đến chỗ gặp kế tiếp" + +#: gitk:3006 +msgid "\tMove to next find hit" +msgstr "\t\tDi chuyển đến chỗ gặp kế tiếp" + +#: gitk:3007 +msgid "/\t\tFocus the search box" +msgstr "/\t\tĐưa con trỏ chuột vào ô tìm kiếm" + +#: gitk:3008 +msgid "?\t\tMove to previous find hit" +msgstr "?\t\tDi chuyển đến chỗ gặp kế trước" + +#: gitk:3009 +msgid "f\t\tScroll diff view to next file" +msgstr "f\t\tCuộn phần trình bày diff sang tập-tin kế" + +#: gitk:3010 +#, tcl-format +msgid "<%s-S>\t\tSearch for next hit in diff view" +msgstr "<%s-S>\t\tTìm đến chỗ khác biệt kế tiếp" + +#: gitk:3011 +#, tcl-format +msgid "<%s-R>\t\tSearch for previous hit in diff view" +msgstr "<%s-R>\t\tTìm đến chỗ khác biệt kế trước" + +#: gitk:3012 +#, tcl-format +msgid "<%s-KP+>\tIncrease font size" +msgstr "<%s-KP+>\tTăng cỡ chữ" + +#: gitk:3013 +#, tcl-format +msgid "<%s-plus>\tIncrease font size" +msgstr "<%s-plus>\tTăng cỡ chữ" + +#: gitk:3014 +#, tcl-format +msgid "<%s-KP->\tDecrease font size" +msgstr "<%s-KP->\tGiảm cỡ chữ" + +#: gitk:3015 +#, tcl-format +msgid "<%s-minus>\tDecrease font size" +msgstr "<%s-minus>\tGiảm cỡ chữ" + +#: gitk:3016 +msgid "\t\tUpdate" +msgstr "\t\tCập nhật" + +#: gitk:3471 gitk:3480 +#, tcl-format +msgid "Error creating temporary directory %s:" +msgstr "Gặp lỗi khi tạo thư mục tạm %s:" + +#: gitk:3493 +#, tcl-format +msgid "Error getting \"%s\" from %s:" +msgstr "Lỗi chào hỏi \"%s\" từ %s:" + +#: gitk:3556 +msgid "command failed:" +msgstr "lệnh gặp lỗi:" + +#: gitk:3705 +msgid "No such commit" +msgstr "Không có lần chuyển giao như vậy" + +#: gitk:3719 +msgid "git gui blame: command failed:" +msgstr "git gui blame: lệnh gặp lỗi:" + +#: gitk:3750 +#, tcl-format +msgid "Couldn't read merge head: %s" +msgstr "Không thể độc đầu của hòa trộn: %s" + +# tcl-format +#: gitk:3758 +#, tcl-format +msgid "Error reading index: %s" +msgstr "Gặp lỗi khi đọc chỉ mục: %s" + +#: gitk:3783 +#, tcl-format +msgid "Couldn't start git blame: %s" +msgstr "Không thể khởi chạy git blame: %s" + +#: gitk:3786 gitk:6652 +msgid "Searching" +msgstr "Đang tìm kiếm" + +#: gitk:3818 +#, tcl-format +msgid "Error running git blame: %s" +msgstr "Gặp lỗi khi chạy git blame: %s" + +#: gitk:3846 +#, tcl-format +msgid "That line comes from commit %s, which is not in this view" +msgstr "Dòng đến từ lần chuyển giao %s, cái mà không trong trình bày này" + +#: gitk:3860 +msgid "External diff viewer failed:" +msgstr "Bộ trình bày diff từ bên ngoài gặp lỗi:" + +#: gitk:3978 +msgid "Gitk view definition" +msgstr "Định nghĩa cách trình bày gitk" + +#: gitk:3982 +msgid "Remember this view" +msgstr "Nhớ cách trình bày này" + +#: gitk:3983 +msgid "References (space separated list):" +msgstr "Tham chiếu (danh sách ngăn cách bằng dấu cách):" + +#: gitk:3984 +msgid "Branches & tags:" +msgstr "Nhánh & thẻ:" + +#: gitk:3985 +msgid "All refs" +msgstr "Mọi tham chiếu" + +#: gitk:3986 +msgid "All (local) branches" +msgstr "Mọi nhánh (nội bộ)" + +#: gitk:3987 +msgid "All tags" +msgstr "Mọi thẻ" + +#: gitk:3988 +msgid "All remote-tracking branches" +msgstr "Mọi nhánh remote-tracking" + +#: gitk:3989 +msgid "Commit Info (regular expressions):" +msgstr "Thông tin chuyển giao (biểu thức chính quy):" + +#: gitk:3990 +msgid "Author:" +msgstr "Tác giả:" + +#: gitk:3991 +msgid "Committer:" +msgstr "Người chuyển giao:" + +#: gitk:3992 +msgid "Commit Message:" +msgstr "Chú thích của lần chuyển giao:" + +#: gitk:3993 +msgid "Matches all Commit Info criteria" +msgstr "Khớp mọi điều kiện Thông tin Chuyển giao" + +#: gitk:3994 +msgid "Changes to Files:" +msgstr "Đổi thành Tập tin:" + +#: gitk:3995 +msgid "Fixed String" +msgstr "Chuỗi cố định" + +#: gitk:3996 +msgid "Regular Expression" +msgstr "Biểu thức chính quy" + +#: gitk:3997 +msgid "Search string:" +msgstr "Chuỗi tìm kiếm:" + +#: gitk:3998 +msgid "" +"Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 " +"15:27:38\"):" +msgstr "" +"Ngày chuyển giao (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 " +"15:27:38\"):" + +#: gitk:3999 +msgid "Since:" +msgstr "Kể từ:" + +#: gitk:4000 +msgid "Until:" +msgstr "Đến:" + +#: gitk:4001 +msgid "Limit and/or skip a number of revisions (positive integer):" +msgstr "Giới hạn và/hoặc bỏ số của điểm xét (số nguyên âm):" + +#: gitk:4002 +msgid "Number to show:" +msgstr "Số lượng hiển thị:" + +#: gitk:4003 +msgid "Number to skip:" +msgstr "Số lượng sẽ bỏ qua:" + +#: gitk:4004 +msgid "Miscellaneous options:" +msgstr "Tuỳ chọn hỗn hợp:" + +#: gitk:4005 +msgid "Strictly sort by date" +msgstr "Sắp xếp chặt chẽ theo ngày" + +#: gitk:4006 +msgid "Mark branch sides" +msgstr "Đánh dấu các cạnh nhánh" + +#: gitk:4007 +msgid "Limit to first parent" +msgstr "Giới hạn thành cha mẹ đầu tiên" + +#: gitk:4008 +msgid "Simple history" +msgstr "Lịch sử dạng đơn giản" + +#: gitk:4009 +msgid "Additional arguments to git log:" +msgstr "Đối số bổ xung cho lệnh git log:" + +#: gitk:4010 +msgid "Enter files and directories to include, one per line:" +msgstr "Nhập vào các tập tin và thư mục bao gồm, mỗi dòng một cái:" + +#: gitk:4011 +msgid "Command to generate more commits to include:" +msgstr "Lệnh tạo ra nhiều lần chuyển giao hơn bao gồm:" + +#: gitk:4135 +msgid "Gitk: edit view" +msgstr "Gitk: sửa cách trình bày" + +#: gitk:4143 +msgid "-- criteria for selecting revisions" +msgstr "-- tiêu chuẩn chọn điểm xét duyệt" + +#: gitk:4148 +msgid "View Name" +msgstr "Tên cách trình bày" + +#: gitk:4223 +msgid "Apply (F5)" +msgstr "Áp dụng (F5)" + +#: gitk:4261 +msgid "Error in commit selection arguments:" +msgstr "Lỗi trong các đối số chọn chuyển giao:" + +#: gitk:4314 gitk:4366 gitk:4827 gitk:4841 gitk:6107 gitk:12184 gitk:12185 +msgid "None" +msgstr "Không" + +#: gitk:4924 gitk:4929 +msgid "Descendant" +msgstr "Con cháu" + +#: gitk:4925 +msgid "Not descendant" +msgstr "Không có con cháu" + +#: gitk:4932 gitk:4937 +msgid "Ancestor" +msgstr "Tổ tiên chung" + +#: gitk:4933 +msgid "Not ancestor" +msgstr "Không có chung tổ tiên" + +#: gitk:5223 +msgid "Local changes checked in to index but not committed" +msgstr "" +"Có thay đổi nội bộ đã được đưa vào bảng mục lục, nhưng chưa được chuyển giao" + +#: gitk:5259 +msgid "Local uncommitted changes, not checked in to index" +msgstr "Có thay đổi nội bộ, nhưng chưa được đưa vào bảng mục lục" + +#: gitk:7032 +msgid "and many more" +msgstr "và nhiều nữa" + +#: gitk:7035 +msgid "many" +msgstr "nhiều" + +#: gitk:7222 +msgid "Tags:" +msgstr "Thẻ:" + +#: gitk:7239 gitk:7245 gitk:8708 +msgid "Parent" +msgstr "Cha" + +#: gitk:7250 +msgid "Child" +msgstr "Con" + +#: gitk:7259 +msgid "Branch" +msgstr "Nhánh" + +#: gitk:7262 +msgid "Follows" +msgstr "Đứng sau" + +#: gitk:7265 +msgid "Precedes" +msgstr "Đứng trước" + +# tcl-format +#: gitk:7849 +#, tcl-format +msgid "Error getting diffs: %s" +msgstr "Lỗi lấy diff: %s" + +#: gitk:8533 +msgid "Goto:" +msgstr "Nhảy tới:" + +#: gitk:8554 +#, tcl-format +msgid "Short SHA1 id %s is ambiguous" +msgstr "Định danh SHA1 dạng ngắn %s là chưa đủ rõ ràng" + +#: gitk:8561 +#, tcl-format +msgid "Revision %s is not known" +msgstr "Không hiểu điểm xét duyệt %s" + +#: gitk:8571 +#, tcl-format +msgid "SHA1 id %s is not known" +msgstr "Không hiểu định danh SHA1 %s" + +#: gitk:8573 +#, tcl-format +msgid "Revision %s is not in the current view" +msgstr "Điểm %s không ở trong phần hiển thị hiện tại" + +#: gitk:8715 gitk:8730 +msgid "Date" +msgstr "Ngày" + +#: gitk:8718 +msgid "Children" +msgstr "Con cháu" + +#: gitk:8781 +#, tcl-format +msgid "Reset %s branch to here" +msgstr "Đặt lại nhánh %s tại đây" + +#: gitk:8783 +msgid "Detached head: can't reset" +msgstr "Head đã bị tách rời: không thể đặt lại" + +#: gitk:8888 gitk:8894 +msgid "Skipping merge commit " +msgstr "Bỏ qua lần chuyển giao hòa trộn " + +#: gitk:8903 gitk:8908 +msgid "Error getting patch ID for " +msgstr "Gặp lỗi khi lấy ID miếng vá cho " + +#: gitk:8904 gitk:8909 +msgid " - stopping\n" +msgstr " - dừng\n" + +#: gitk:8914 gitk:8917 gitk:8925 gitk:8939 gitk:8948 +msgid "Commit " +msgstr "Commit " + +#: gitk:8918 +msgid "" +" is the same patch as\n" +" " +msgstr "" +" là cùng một miếng vá với\n" +" " + +#: gitk:8926 +msgid "" +" differs from\n" +" " +msgstr "" +" khác biệt từ\n" +" " + +#: gitk:8928 +msgid "" +"Diff of commits:\n" +"\n" +msgstr "" +"Khác biệt của lần chuyển giao (commit):\n" +"\n" + +#: gitk:8940 gitk:8949 +#, tcl-format +msgid " has %s children - stopping\n" +msgstr " có %s con - dừng\n" + +#: gitk:8968 +#, tcl-format +msgid "Error writing commit to file: %s" +msgstr "Gặp lỗi trong quá trình ghi lần chuyển giao vào tập tin: %s" + +#: gitk:8974 +#, tcl-format +msgid "Error diffing commits: %s" +msgstr "Gặp lỗi khi so sánh sự khác biệt giữa các lần chuyển giao: %s" + +#: gitk:9020 +msgid "Top" +msgstr "Đỉnh" + +#: gitk:9021 +msgid "From" +msgstr "Từ" + +#: gitk:9026 +msgid "To" +msgstr "Đến" + +#: gitk:9050 +msgid "Generate patch" +msgstr "Tạo miếng vá" + +#: gitk:9052 +msgid "From:" +msgstr "Từ:" + +#: gitk:9061 +msgid "To:" +msgstr "Đến:" + +#: gitk:9070 +msgid "Reverse" +msgstr "Đảo ngược" + +#: gitk:9072 gitk:9268 +msgid "Output file:" +msgstr "Tập tin kết xuất:" + +#: gitk:9078 +msgid "Generate" +msgstr "Tạo" + +#: gitk:9116 +msgid "Error creating patch:" +msgstr "Gặp lỗi khi tạo miếng vá:" + +#: gitk:9139 gitk:9256 gitk:9313 +msgid "ID:" +msgstr "ID:" + +#: gitk:9148 +msgid "Tag name:" +msgstr "Tên thẻ:" + +#: gitk:9151 +msgid "Tag message is optional" +msgstr "Ghi chú thẻ chỉ là tùy chọn" + +#: gitk:9153 +msgid "Tag message:" +msgstr "Ghi chú cho thẻ:" + +#: gitk:9157 gitk:9322 +msgid "Create" +msgstr "Tạo" + +#: gitk:9175 +msgid "No tag name specified" +msgstr "Chưa chỉ ra tên của thẻ" + +#: gitk:9179 +#, tcl-format +msgid "Tag \"%s\" already exists" +msgstr "Thẻ “%s” đã có sẵn rồi" + +#: gitk:9189 +msgid "Error creating tag:" +msgstr "Gặp lỗi khi tạo thẻ:" + +#: gitk:9265 +msgid "Command:" +msgstr "Lệnh:" + +#: gitk:9273 +msgid "Write" +msgstr "Ghi" + +#: gitk:9291 +msgid "Error writing commit:" +msgstr "Gặp lỗi trong quá trình ghi chuyển giao:" + +#: gitk:9318 +msgid "Name:" +msgstr "Tên:" + +#: gitk:9341 +msgid "Please specify a name for the new branch" +msgstr "Vui lòng chỉ định tên cho nhánh mới" + +#: gitk:9346 +#, tcl-format +msgid "Branch '%s' already exists. Overwrite?" +msgstr "Nhánh “%s” đã có từ trước rồi. Ghi đè?" + +#: gitk:9413 +#, tcl-format +msgid "Commit %s is already included in branch %s -- really re-apply it?" +msgstr "" +"Lần chuyển giao %s đã sẵn được bao gồm trong nhánh %s -- bạn có thực sự muốn " +"áp dụng lại nó không?" + +#: gitk:9418 +msgid "Cherry-picking" +msgstr "Đang cherry-pick" + +#: gitk:9427 +#, tcl-format +msgid "" +"Cherry-pick failed because of local changes to file '%s'.\n" +"Please commit, reset or stash your changes and try again." +msgstr "" +"Cherry-pick gặp lỗi bởi vì các thay đổi nội bộ tập tin “%s”.\n" +"Xin hãy chuyển giao, reset hay stash các thay đổi của bạn sau đó thử lại." + +#: gitk:9433 +msgid "" +"Cherry-pick failed because of merge conflict.\n" +"Do you wish to run git citool to resolve it?" +msgstr "" +"Cherry-pick gặp lỗi bởi vì xung đột trong hòa trộn.\n" +"Bạn có muốn chạy lệnh “git citool” để giải quyết vấn đề này không?" + +#: gitk:9449 gitk:9507 +msgid "No changes committed" +msgstr "Không có thay đổi nào cần chuyển giao" + +#: gitk:9476 +#, tcl-format +msgid "Commit %s is not included in branch %s -- really revert it?" +msgstr "" +"Lần chuyển giao %s không được bao gồm trong nhánh %s -- bạn có thực sự muốn " +"“revert” nó không?" + +#: gitk:9481 +msgid "Reverting" +msgstr "Đang hoàn tác" + +#: gitk:9489 +#, tcl-format +msgid "" +"Revert failed because of local changes to the following files:%s Please " +"commit, reset or stash your changes and try again." +msgstr "" +"Revert gặp lỗi bởi vì tập tin sau đã được thay đổi nội bộ:%s\n" +"Xin hãy chạy lệnh “commit”, “reset” hoặc “stash” rồi thử lại." + +#: gitk:9493 +msgid "" +"Revert failed because of merge conflict.\n" +" Do you wish to run git citool to resolve it?" +msgstr "" +"Revert gặp lỗi bởi vì xung đột hòa trộn.\n" +" Bạn có muốn chạy lệnh “git citool” để phân giải nó không?" + +#: gitk:9536 +msgid "Confirm reset" +msgstr "Xác nhật đặt lại" + +#: gitk:9538 +#, tcl-format +msgid "Reset branch %s to %s?" +msgstr "Đặt lại nhánh “%s” thành “%s”?" + +#: gitk:9540 +msgid "Reset type:" +msgstr "Kiểu đặt lại:" + +#: gitk:9543 +msgid "Soft: Leave working tree and index untouched" +msgstr "Mềm: Không động đến thư mục làm việc và bảng mục lục" + +#: gitk:9546 +msgid "Mixed: Leave working tree untouched, reset index" +msgstr "" +"Pha trộn: Không động chạm đến thư mục làm việc nhưng đặt lại bảng mục lục" + +#: gitk:9549 +msgid "" +"Hard: Reset working tree and index\n" +"(discard ALL local changes)" +msgstr "" +"Hard: Đặt lại cây làm việc và mục lục\n" +"(hủy bỏ MỌI thay đổi nội bộ)" + +#: gitk:9566 +msgid "Resetting" +msgstr "Đang đặt lại" + +#: gitk:9626 +msgid "Checking out" +msgstr "Đang checkout" + +#: gitk:9679 +msgid "Cannot delete the currently checked-out branch" +msgstr "Không thể xóa nhánh hiện tại đang được lấy ra" + +#: gitk:9685 +#, tcl-format +msgid "" +"The commits on branch %s aren't on any other branch.\n" +"Really delete branch %s?" +msgstr "" +"Các lần chuyển giao trên nhánh %s không ở trên nhánh khác.\n" +"Thực sự muốn xóa nhánh %s?" + +#: gitk:9716 +#, tcl-format +msgid "Tags and heads: %s" +msgstr "Thẻ và Đầu: %s" + +#: gitk:9731 +msgid "Filter" +msgstr "Bộ lọc" + +#: gitk:10027 +msgid "" +"Error reading commit topology information; branch and preceding/following " +"tag information will be incomplete." +msgstr "" +"Gặp lỗi khi đọc thông tin hình học lần chuyển giao; thông tin nhánh và thẻ " +"trước/sau sẽ không hoàn thiện." + +#: gitk:11004 +msgid "Tag" +msgstr "Thẻ" + +#: gitk:11008 +msgid "Id" +msgstr "Id" + +#: gitk:11091 +msgid "Gitk font chooser" +msgstr "Hộp thoại chọn phông Gitk" + +#: gitk:11108 +msgid "B" +msgstr "B" + +#: gitk:11111 +msgid "I" +msgstr "I" + +#: gitk:11229 +msgid "Commit list display options" +msgstr "Các tùy chọn về hiển thị danh sách lần chuyển giao" + +#: gitk:11232 +msgid "Maximum graph width (lines)" +msgstr "Độ rộng biểu đồ tối đa (dòng)" + +#: gitk:11235 +#, tcl-format +msgid "Maximum graph width (% of pane)" +msgstr "Độ rộng biểu đồ tối đa (% của bảng)" + +#: gitk:11238 +msgid "Show local changes" +msgstr "Hiển thị các thay đổi nội bộ" + +#: gitk:11241 +msgid "Auto-select SHA1 (length)" +msgstr "Tự chọn SHA1 (độ dài)" + +#: gitk:11245 +msgid "Hide remote refs" +msgstr "Ẩn tham chiếu đến máy chủ" + +#: gitk:11249 +msgid "Diff display options" +msgstr "Các tùy chọn trình bày các khác biệt" + +#: gitk:11251 +msgid "Tab spacing" +msgstr "Khoảng cách tab" + +#: gitk:11254 +msgid "Display nearby tags/heads" +msgstr "Hiển thị các thẻ/đầu xung quanh" + +#: gitk:11257 +msgid "Maximum # tags/heads to show" +msgstr "Số lượng thẻ/đầu tối đa sẽ hiển thị" + +#: gitk:11260 +msgid "Limit diffs to listed paths" +msgstr "Giới hạn các khác biệt cho đường dẫn đã liệt kê" + +#: gitk:11263 +msgid "Support per-file encodings" +msgstr "Hỗ trợ mã hóa mỗi-dòng" + +#: gitk:11269 gitk:11416 +msgid "External diff tool" +msgstr "Công cụ so sánh từ bên ngoài" + +#: gitk:11270 +msgid "Choose..." +msgstr "Chọn..." + +#: gitk:11275 +msgid "General options" +msgstr "Các tùy chọn chung" + +#: gitk:11278 +msgid "Use themed widgets" +msgstr "Dùng các widget chủ đề" + +#: gitk:11280 +msgid "(change requires restart)" +msgstr "(để thay đổi cần khởi động lại)" + +#: gitk:11282 +msgid "(currently unavailable)" +msgstr "(hiện tại không sẵn sàng)" + +#: gitk:11293 +msgid "Colors: press to choose" +msgstr "Màu sắc: bấm vào nút phía dưới để chọn màu" + +#: gitk:11296 +msgid "Interface" +msgstr "Giao diện" + +#: gitk:11297 +msgid "interface" +msgstr "giao diện" + +#: gitk:11300 +msgid "Background" +msgstr "Nền" + +#: gitk:11301 gitk:11331 +msgid "background" +msgstr "nền" + +#: gitk:11304 +msgid "Foreground" +msgstr "Tiền cảnh" + +#: gitk:11305 +msgid "foreground" +msgstr "tiền cảnh" + +#: gitk:11308 +msgid "Diff: old lines" +msgstr "So sánh: dòng cũ" + +#: gitk:11309 +msgid "diff old lines" +msgstr "diff dòng cũ" + +#: gitk:11313 +msgid "Diff: new lines" +msgstr "So sánh: dòng mới" + +#: gitk:11314 +msgid "diff new lines" +msgstr "màu dòng mới" + +#: gitk:11318 +msgid "Diff: hunk header" +msgstr "So sánh: phần đầu của đoạn" + +#: gitk:11320 +msgid "diff hunk header" +msgstr "màu của phần đầu của đoạn khi so sánh" + +#: gitk:11324 +msgid "Marked line bg" +msgstr "Nền dòng đánh dấu" + +#: gitk:11326 +msgid "marked line background" +msgstr "nền dòng được đánh dấu" + +#: gitk:11330 +msgid "Select bg" +msgstr "Màu nền" + +#: gitk:11339 +msgid "Fonts: press to choose" +msgstr "Phông chữ: bấm vào các nút ở dưới để chọn" + +#: gitk:11341 +msgid "Main font" +msgstr "Phông chữ chính" + +#: gitk:11342 +msgid "Diff display font" +msgstr "Phông chữ dùng khi so sánh" + +#: gitk:11343 +msgid "User interface font" +msgstr "Phông chữ giao diện" + +#: gitk:11365 +msgid "Gitk preferences" +msgstr "Cá nhân hóa các cài đặt cho Gitk" + +#: gitk:11374 +msgid "General" +msgstr "Chung" + +#: gitk:11375 +msgid "Colors" +msgstr "Màu sắc" + +#: gitk:11376 +msgid "Fonts" +msgstr "Phông chữ" + +#: gitk:11426 +#, tcl-format +msgid "Gitk: choose color for %s" +msgstr "Gitk: chọn màu cho %s" + +#: gitk:12080 +msgid "Cannot find a git repository here." +msgstr "Không thể tìm thấy kho git ở đây." + +#: gitk:12127 +#, tcl-format +msgid "Ambiguous argument '%s': both revision and filename" +msgstr "Đối số “%s” chưa rõ ràng: vừa là điểm xét duyệt vừa là tên tập tin" + +#: gitk:12139 +msgid "Bad arguments to gitk:" +msgstr "Đối số không hợp lệ cho gitk:" + +#: gitk:12242 +msgid "Command line" +msgstr "Dòng lệnh" From 51af1886c73f12b1e020db1aa03525e2d74bed93 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 3 Feb 2014 16:47:19 +0400 Subject: [PATCH 002/760] combine-diff: move show_log_first logic/action out of paths scanning Judging from sample outputs and tests nothing changes in diff -c output, and this change will help later patches, when we'll be refactoring paths scanning into its own function with several variants - the show_log_first logic / code will stay common to all of them. NOTE: only now we have to take care to explicitly not show anything if parents array is empty, as in fact there are some clients in Git code, which calls diff_tree_combined() in such a way. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- combine-diff.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 24ca7e2334b68e..68d2e53be66c50 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1311,6 +1311,20 @@ void diff_tree_combined(const unsigned char *sha1, struct combine_diff_path *p, *paths = NULL; int i, num_paths, needsep, show_log_first, num_parent = parents->nr; + /* nothing to do, if no parents */ + if (!num_parent) + return; + + show_log_first = !!rev->loginfo && !rev->no_commit_id; + needsep = 0; + if (show_log_first) { + show_log(rev); + + if (rev->verbose_header && opt->output_format) + printf("%s%c", diff_line_prefix(opt), + opt->line_termination); + } + diffopts = *opt; copy_pathspec(&diffopts.pathspec, &opt->pathspec); diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; @@ -1319,8 +1333,6 @@ void diff_tree_combined(const unsigned char *sha1, /* tell diff_tree to emit paths in sorted (=tree) order */ diffopts.orderfile = NULL; - show_log_first = !!rev->loginfo && !rev->no_commit_id; - needsep = 0; /* find set of paths that everybody touches */ for (i = 0; i < num_parent; i++) { /* show stat against the first parent even @@ -1336,14 +1348,6 @@ void diff_tree_combined(const unsigned char *sha1, diffcore_std(&diffopts); paths = intersect_paths(paths, i, num_parent); - if (show_log_first && i == 0) { - show_log(rev); - - if (rev->verbose_header && opt->output_format) - printf("%s%c", diff_line_prefix(opt), - opt->line_termination); - } - /* if showing diff, show it in requested order */ if (diffopts.output_format != DIFF_FORMAT_NO_OUTPUT && opt->orderfile) { From eeb3f32868862609b475122f3e0c2ef7c0dd3e79 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 3 Feb 2014 16:47:20 +0400 Subject: [PATCH 003/760] combine-diff: move changed-paths scanning logic into its own function Move code for finding paths for which diff(commit,parent_i) is not-empty for all parents to separate function - at present we have generic (and slow) code for this job, which translates 1 n-parent problem to n 1-parent problems and then intersect results, and will be adding another limited, but faster, paths scanning implementation in the next patch. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- combine-diff.c | 80 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 68d2e53be66c50..1732dfd110664e 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1301,6 +1301,51 @@ static const char *path_path(void *obj) return path->path; } + +/* find set of paths that every parent touches */ +static struct combine_diff_path *find_paths(const unsigned char *sha1, + const struct sha1_array *parents, struct diff_options *opt) +{ + struct combine_diff_path *paths = NULL; + int i, num_parent = parents->nr; + + int output_format = opt->output_format; + const char *orderfile = opt->orderfile; + + opt->output_format = DIFF_FORMAT_NO_OUTPUT; + /* tell diff_tree to emit paths in sorted (=tree) order */ + opt->orderfile = NULL; + + for (i = 0; i < num_parent; i++) { + /* + * show stat against the first parent even when doing + * combined diff. + */ + int stat_opt = (output_format & + (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)); + if (i == 0 && stat_opt) + opt->output_format = stat_opt; + else + opt->output_format = DIFF_FORMAT_NO_OUTPUT; + diff_tree_sha1(parents->sha1[i], sha1, "", opt); + diffcore_std(opt); + paths = intersect_paths(paths, i, num_parent); + + /* if showing diff, show it in requested order */ + if (opt->output_format != DIFF_FORMAT_NO_OUTPUT && + orderfile) { + diffcore_order(orderfile); + } + + diff_flush(opt); + } + + opt->output_format = output_format; + opt->orderfile = orderfile; + return paths; +} + + void diff_tree_combined(const unsigned char *sha1, const struct sha1_array *parents, int dense, @@ -1308,7 +1353,7 @@ void diff_tree_combined(const unsigned char *sha1, { struct diff_options *opt = &rev->diffopt; struct diff_options diffopts; - struct combine_diff_path *p, *paths = NULL; + struct combine_diff_path *p, *paths; int i, num_paths, needsep, show_log_first, num_parent = parents->nr; /* nothing to do, if no parents */ @@ -1327,35 +1372,16 @@ void diff_tree_combined(const unsigned char *sha1, diffopts = *opt; copy_pathspec(&diffopts.pathspec, &opt->pathspec); - diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; DIFF_OPT_SET(&diffopts, RECURSIVE); DIFF_OPT_CLR(&diffopts, ALLOW_EXTERNAL); - /* tell diff_tree to emit paths in sorted (=tree) order */ - diffopts.orderfile = NULL; - /* find set of paths that everybody touches */ - for (i = 0; i < num_parent; i++) { - /* show stat against the first parent even - * when doing combined diff. - */ - int stat_opt = (opt->output_format & - (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)); - if (i == 0 && stat_opt) - diffopts.output_format = stat_opt; - else - diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; - diff_tree_sha1(parents->sha1[i], sha1, "", &diffopts); - diffcore_std(&diffopts); - paths = intersect_paths(paths, i, num_parent); - - /* if showing diff, show it in requested order */ - if (diffopts.output_format != DIFF_FORMAT_NO_OUTPUT && - opt->orderfile) { - diffcore_order(opt->orderfile); - } - - diff_flush(&diffopts); - } + /* find set of paths that everybody touches + * + * NOTE find_paths() also handles --stat, as it computes + * diff(sha1,parent_i) for all i to do the job, specifically + * for parent0. + */ + paths = find_paths(sha1, parents, &diffopts); /* find out number of surviving paths */ for (num_paths = 0, p = paths; p; p = p->next) From e197c2b650316f62e6dfee4fadcb4198a03b8325 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 3 Feb 2014 16:47:17 +0400 Subject: [PATCH 004/760] tree-diff: no need to manually verify that there is no mode change for a path Because if there is, such two tree entries would never be compared as equal - the code in base_name_compare() explicitly compares modes, if there is a change for dir bit, even for equal paths, entries would compare as different. The code I'm removing here is from 2005 April 262e82b4 (Fix diff-tree recursion), which pre-dates base_name_compare() introduction in 958ba6c9 (Introduce "base_name_compare()" helper function) by a month. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 11c3550177dbaa..5810b0042723be 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -23,6 +23,11 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, pathlen1 = tree_entry_len(&t1->entry); pathlen2 = tree_entry_len(&t2->entry); + + /* + * NOTE files and directories *always* compare differently, + * even when having the same name. + */ cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); if (cmp < 0) { show_entry(opt, "-", t1, base); @@ -35,16 +40,6 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER) && !hashcmp(sha1, sha2) && mode1 == mode2) return 0; - /* - * If the filemode has changed to/from a directory from/to a regular - * file, we need to consider it a remove and an add. - */ - if (S_ISDIR(mode1) != S_ISDIR(mode2)) { - show_entry(opt, "-", t1, base); - show_entry(opt, "+", t2, base); - return 0; - } - strbuf_add(base, path1, pathlen1); if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode1)) { if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) { From e906612121bc9d436a3a64cd03be0537654e800c Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 3 Feb 2014 16:47:18 +0400 Subject: [PATCH 005/760] tree-diff: no need to pass match to skip_uninteresting() It is neither used there as input, nor the output written through it, is used outside. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 5810b0042723be..a8c2aecd1d3158 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -109,13 +109,14 @@ static void show_entry(struct diff_options *opt, const char *prefix, } static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, - struct diff_options *opt, - enum interesting *match) + struct diff_options *opt) { + enum interesting match; + while (t->size) { - *match = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec); - if (*match) { - if (*match == all_entries_not_interesting) + match = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec); + if (match) { + if (match == all_entries_not_interesting) t->size = 0; break; } @@ -128,8 +129,6 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, { struct strbuf base; int baselen = strlen(base_str); - enum interesting t1_match = entry_not_interesting; - enum interesting t2_match = entry_not_interesting; /* Enable recursion indefinitely */ opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); @@ -141,8 +140,8 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, if (diff_can_quit_early(opt)) break; if (opt->pathspec.nr) { - skip_uninteresting(t1, &base, opt, &t1_match); - skip_uninteresting(t2, &base, opt, &t2_match); + skip_uninteresting(t1, &base, opt); + skip_uninteresting(t2, &base, opt); } if (!t1->size) { if (!t2->size) From 7e9003c1497d01f2e75a5f3df7303643fb2432c3 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:37 +0400 Subject: [PATCH 006/760] tree-diff: show_tree() is not needed We don't need special code for showing added/removed subtree, because we can do the same via diff_tree_sha1, just passing NULL for absent tree. And compared to show_tree(), which was calling show_entry() for every tree entry, that would lead to the same show_entry() callings: show_tree(t): for e in t.entries: show_entry(e) diff_tree_sha1(NULL, new): /* the same applies to (old, NULL) */ diff_tree(t1=NULL, t2) ... if (!t1->size) show_entry(t2) ... and possible overhead is negligible, since after the patch, timing for `git log --raw --no-abbrev --no-renames` for navy.git and `linux.git v3.10..v3.11` is practically the same. So let's say goodbye to show_tree() - it removes some code, but also, and what is important, consolidates more code for showing/recursing into trees into one place. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index a8c2aecd1d3158..2ad778884a338f 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -55,25 +55,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, return 0; } -/* A whole sub-tree went away or appeared */ -static void show_tree(struct diff_options *opt, const char *prefix, - struct tree_desc *desc, struct strbuf *base) -{ - enum interesting match = entry_not_interesting; - for (; desc->size; update_tree_entry(desc)) { - if (match != all_entries_interesting) { - match = tree_entry_interesting(&desc->entry, base, 0, - &opt->pathspec); - if (match == all_entries_not_interesting) - break; - if (match == entry_not_interesting) - continue; - } - show_entry(opt, prefix, desc, base); - } -} - -/* A file entry went away or appeared */ +/* An entry went away or appeared */ static void show_entry(struct diff_options *opt, const char *prefix, struct tree_desc *desc, struct strbuf *base) { @@ -85,23 +67,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, strbuf_add(base, path, pathlen); if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) { - enum object_type type; - struct tree_desc inner; - void *tree; - unsigned long size; - - tree = read_sha1_file(sha1, &type, &size); - if (!tree || type != OBJ_TREE) - die("corrupt tree sha %s", sha1_to_hex(sha1)); - if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) opt->add_remove(opt, *prefix, mode, sha1, 1, base->buf, 0); strbuf_addch(base, '/'); - - init_tree_desc(&inner, tree, size); - show_tree(opt, prefix, &inner, base); - free(tree); + diff_tree_sha1(*prefix == '-' ? sha1 : NULL, + *prefix == '+' ? sha1 : NULL, base->buf, opt); } else opt->add_remove(opt, prefix[0], mode, sha1, 1, base->buf, 0); From 6453f7b34864c1a639cc367f576476ee3be1456f Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Mon, 17 Mar 2014 20:16:05 +0100 Subject: [PATCH 007/760] grep: add grep.fullName config variable This configuration variable sets the default for the --full-name option. Signed-off-by: Andreas Schwab Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 3 +++ grep.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index f83733490f5a88..31811f16bdaac4 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -53,6 +53,9 @@ grep.extendedRegexp:: option is ignored when the 'grep.patternType' option is set to a value other than 'default'. +grep.fullName:: + If set to true, enable '--full-name' option by default. + OPTIONS ------- diff --git a/grep.c b/grep.c index c668034739258d..ece04bf2756ec6 100644 --- a/grep.c +++ b/grep.c @@ -86,6 +86,11 @@ int grep_config(const char *var, const char *value, void *cb) return 0; } + if (!strcmp(var, "grep.fullname")) { + opt->relative = !git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "color.grep")) opt->color = git_config_colorbool(var, value); else if (!strcmp(var, "color.grep.context")) From d00e980c224d4b65972dda4474fbd9294bdb185f Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:38 +0400 Subject: [PATCH 008/760] tree-diff: consolidate code for emitting diffs and recursion in one place Currently both compare_tree_entry() and show_entry() invoke opt diff callbacks (opt->add_remove() and opt->change()), and also they both have code which decides whether to recurse into sub-tree, and whether to emit a tree as separate entry if DIFF_OPT_TREE_IN_RECURSIVE is set. I.e. we have code duplication and logic scattered on two places. Let's consolidate it - all diff emiting code and recurion logic moves to show_entry, which is now named as show_path, because it shows diff for a path, based on up to two tree entries, with actual diff emitting code being kept in new helper emit_diff() for clarity. What we have as the result, is that compare_tree_entry is now free from code with logic for diff generation, and also performance is not affected as timings for `git log --raw --no-abbrev --no-renames` for navy.git and `linux.git v3.10..v3.11`, just like in previous patch, stay the same. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 112 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 2ad778884a338f..1af82190339b05 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -6,8 +6,8 @@ #include "diffcore.h" #include "tree.h" -static void show_entry(struct diff_options *opt, const char *prefix, - struct tree_desc *desc, struct strbuf *base); +static void show_path(struct strbuf *base, struct diff_options *opt, + struct tree_desc *t1, struct tree_desc *t2); static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, struct strbuf *base, struct diff_options *opt) @@ -16,7 +16,6 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const char *path1, *path2; const unsigned char *sha1, *sha2; int cmp, pathlen1, pathlen2; - int old_baselen = base->len; sha1 = tree_entry_extract(t1, &path1, &mode1); sha2 = tree_entry_extract(t2, &path2, &mode2); @@ -30,51 +29,104 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, */ cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); if (cmp < 0) { - show_entry(opt, "-", t1, base); + show_path(base, opt, t1, /*t2=*/NULL); return -1; } if (cmp > 0) { - show_entry(opt, "+", t2, base); + show_path(base, opt, /*t1=*/NULL, t2); return 1; } if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER) && !hashcmp(sha1, sha2) && mode1 == mode2) return 0; - strbuf_add(base, path1, pathlen1); - if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode1)) { - if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) { - opt->change(opt, mode1, mode2, - sha1, sha2, 1, 1, base->buf, 0, 0); + show_path(base, opt, t1, t2); + return 0; +} + + +/* convert path, t1/t2 -> opt->diff_*() callbacks */ +static void emit_diff(struct diff_options *opt, struct strbuf *path, + struct tree_desc *t1, struct tree_desc *t2) +{ + unsigned int mode1 = t1 ? t1->entry.mode : 0; + unsigned int mode2 = t2 ? t2->entry.mode : 0; + + if (mode1 && mode2) { + opt->change(opt, mode1, mode2, t1->entry.sha1, t2->entry.sha1, + 1, 1, path->buf, 0, 0); + } + else { + const unsigned char *sha1; + unsigned int mode; + int addremove; + + if (mode2) { + addremove = '+'; + sha1 = t2->entry.sha1; + mode = mode2; + } else { + addremove = '-'; + sha1 = t1->entry.sha1; + mode = mode1; } - strbuf_addch(base, '/'); - diff_tree_sha1(sha1, sha2, base->buf, opt); - } else { - opt->change(opt, mode1, mode2, sha1, sha2, 1, 1, base->buf, 0, 0); + + opt->add_remove(opt, addremove, mode, sha1, 1, path->buf, 0); } - strbuf_setlen(base, old_baselen); - return 0; } -/* An entry went away or appeared */ -static void show_entry(struct diff_options *opt, const char *prefix, - struct tree_desc *desc, struct strbuf *base) + +/* new path should be added to diff + * + * 3 cases on how/when it should be called and behaves: + * + * !t1, t2 -> path added, parent lacks it + * t1, !t2 -> path removed from parent + * t1, t2 -> path modified + */ +static void show_path(struct strbuf *base, struct diff_options *opt, + struct tree_desc *t1, struct tree_desc *t2) { unsigned mode; const char *path; - const unsigned char *sha1 = tree_entry_extract(desc, &path, &mode); - int pathlen = tree_entry_len(&desc->entry); + int pathlen; int old_baselen = base->len; + int isdir, recurse = 0, emitthis = 1; + + /* at least something has to be valid */ + assert(t1 || t2); + + if (t2) { + /* path present in resulting tree */ + tree_entry_extract(t2, &path, &mode); + pathlen = tree_entry_len(&t2->entry); + isdir = S_ISDIR(mode); + } else { + /* + * a path was removed - take path from parent. Also take + * mode from parent, to decide on recursion. + */ + tree_entry_extract(t1, &path, &mode); + pathlen = tree_entry_len(&t1->entry); + + isdir = S_ISDIR(mode); + mode = 0; + } + + if (DIFF_OPT_TST(opt, RECURSIVE) && isdir) { + recurse = 1; + emitthis = DIFF_OPT_TST(opt, TREE_IN_RECURSIVE); + } strbuf_add(base, path, pathlen); - if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) { - if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) - opt->add_remove(opt, *prefix, mode, sha1, 1, base->buf, 0); + if (emitthis) + emit_diff(opt, base, t1, t2); + + if (recurse) { strbuf_addch(base, '/'); - diff_tree_sha1(*prefix == '-' ? sha1 : NULL, - *prefix == '+' ? sha1 : NULL, base->buf, opt); - } else - opt->add_remove(opt, prefix[0], mode, sha1, 1, base->buf, 0); + diff_tree_sha1(t1 ? t1->entry.sha1 : NULL, + t2 ? t2->entry.sha1 : NULL, base->buf, opt); + } strbuf_setlen(base, old_baselen); } @@ -117,12 +169,12 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, if (!t1->size) { if (!t2->size) break; - show_entry(opt, "+", t2, &base); + show_path(&base, opt, /*t1=*/NULL, t2); update_tree_entry(t2); continue; } if (!t2->size) { - show_entry(opt, "-", t1, &base); + show_path(&base, opt, t1, /*t2=*/NULL); update_tree_entry(t1); continue; } From 5dfb2bbd8d2e2e48aa3ad6c6a8f437bbe5d2a7fb Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:39 +0400 Subject: [PATCH 009/760] tree-diff: don't assume compare_tree_entry() returns -1,0,1 It does, but we'll be reworking it in the next patch after it won't, and besides it is better to stick to standard strcmp/memcmp/base_name_compare/etc... convention, where comparison function returns <0, =0, >0 Regarding performance, comparing for <0, =0, >0 should be a little bit faster, than switch, because it is just 1 test-without-immediate instruction and then up to 3 conditional branches, and in switch you have up to 3 tests with immediate and up to 3 conditional branches. No worry, that update_tree_entry(t2) is duplicated for =0 and >0 - it will be good after we'll be adding support for multiparent walker and will stay that way. =0 case goes first, because it happens more often in real diffs - i.e. paths are the same. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 1af82190339b05..6a677daa7a8c31 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -178,18 +178,24 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, update_tree_entry(t1); continue; } - switch (compare_tree_entry(t1, t2, &base, opt)) { - case -1: + + cmp = compare_tree_entry(t1, t2, &base, opt); + + /* t1 = t2 */ + if (cmp == 0) { update_tree_entry(t1); - continue; - case 0: + update_tree_entry(t2); + } + + /* t1 < t2 */ + else if (cmp < 0) { update_tree_entry(t1); - /* Fallthrough */ - case 1: + } + + /* t1 > t2 */ + else { update_tree_entry(t2); - continue; } - die("git diff-tree: internal error"); } strbuf_release(&base); From 903bba68abb8153f181d854e9a7075b893f1303f Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:40 +0400 Subject: [PATCH 010/760] tree-diff: move all action-taking code out of compare_tree_entry() - let it do only comparison. This way the code is cleaner and more structured - cmp function only compares, and the driver takes action based on comparison result. There should be no change in performance, as effectively, we just move if series from on place into another, and merge it to was-already-there same switch/if, so the result is maybe a little bit faster. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 6a677daa7a8c31..ce3ca7204b914c 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -9,8 +9,7 @@ static void show_path(struct strbuf *base, struct diff_options *opt, struct tree_desc *t1, struct tree_desc *t2); -static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, - struct strbuf *base, struct diff_options *opt) +static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2) { unsigned mode1, mode2; const char *path1, *path2; @@ -28,19 +27,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, * even when having the same name. */ cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); - if (cmp < 0) { - show_path(base, opt, t1, /*t2=*/NULL); - return -1; - } - if (cmp > 0) { - show_path(base, opt, /*t1=*/NULL, t2); - return 1; - } - if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER) && !hashcmp(sha1, sha2) && mode1 == mode2) - return 0; - - show_path(base, opt, t1, t2); - return 0; + return cmp; } @@ -160,6 +147,8 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, strbuf_add(&base, base_str, baselen); for (;;) { + int cmp; + if (diff_can_quit_early(opt)) break; if (opt->pathspec.nr) { @@ -179,21 +168,28 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, continue; } - cmp = compare_tree_entry(t1, t2, &base, opt); + cmp = compare_tree_entry(t1, t2); /* t1 = t2 */ if (cmp == 0) { + if (DIFF_OPT_TST(opt, FIND_COPIES_HARDER) || + hashcmp(t1->entry.sha1, t2->entry.sha1) || + (t1->entry.mode != t2->entry.mode)) + show_path(&base, opt, t1, t2); + update_tree_entry(t1); update_tree_entry(t2); } /* t1 < t2 */ else if (cmp < 0) { + show_path(&base, opt, t1, /*t2=*/NULL); update_tree_entry(t1); } /* t1 > t2 */ else { + show_path(&base, opt, /*t1=*/NULL, t2); update_tree_entry(t2); } } From 9bc0619655dfd183eb5d0d47b4d63a511acd5c64 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:41 +0400 Subject: [PATCH 011/760] tree-diff: rename compare_tree_entry -> tree_entry_pathcmp Since previous commit, this function does not compare entry hashes, and mode are compared fully outside of it. So what it does is compare entry names and DIR bit in modes. Reflect this in its name. Add documentation stating the semantics, and move the note about files/dirs comparison to it. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index ce3ca7204b914c..58e790a5ee48ff 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -9,7 +9,14 @@ static void show_path(struct strbuf *base, struct diff_options *opt, struct tree_desc *t1, struct tree_desc *t2); -static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2) +/* + * Compare two tree entries, taking into account only path/S_ISDIR(mode), + * but not their sha1's. + * + * NOTE files and directories *always* compare differently, even when having + * the same name - thanks to base_name_compare(). + */ +static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) { unsigned mode1, mode2; const char *path1, *path2; @@ -22,10 +29,6 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2) pathlen1 = tree_entry_len(&t1->entry); pathlen2 = tree_entry_len(&t2->entry); - /* - * NOTE files and directories *always* compare differently, - * even when having the same name. - */ cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); return cmp; } @@ -168,7 +171,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, continue; } - cmp = compare_tree_entry(t1, t2); + cmp = tree_entry_pathcmp(t1, t2); /* t1 = t2 */ if (cmp == 0) { From 5acabd84a6656a4f568f0e934cc9e1b344ed39d4 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:42 +0400 Subject: [PATCH 012/760] tree-diff: show_path prototype is not needed anymore We moved all action-taking code below show_path() in recent HEAD~~ (tree-diff: move all action-taking code out of compare_tree_entry). Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 58e790a5ee48ff..73fa9beab0a506 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -6,9 +6,6 @@ #include "diffcore.h" #include "tree.h" -static void show_path(struct strbuf *base, struct diff_options *opt, - struct tree_desc *t1, struct tree_desc *t2); - /* * Compare two tree entries, taking into account only path/S_ISDIR(mode), * but not their sha1's. From 1a27a1545230a5a19a3c05ed41efb8530d2fd2cd Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:43 +0400 Subject: [PATCH 013/760] tree-diff: simplify tree_entry_pathcmp Since an earlier "Finally switch over tree descriptors to contain a pre-parsed entry", we can safely access all tree_desc->entry fields directly instead of first "extracting" them through tree_entry_extract. Use it. The code generated stays the same - only it now visually looks cleaner. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 73fa9beab0a506..f8b2607c6d93af 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -15,18 +15,13 @@ */ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) { - unsigned mode1, mode2; - const char *path1, *path2; - const unsigned char *sha1, *sha2; - int cmp, pathlen1, pathlen2; + struct name_entry *e1, *e2; + int cmp; - sha1 = tree_entry_extract(t1, &path1, &mode1); - sha2 = tree_entry_extract(t2, &path2, &mode2); - - pathlen1 = tree_entry_len(&t1->entry); - pathlen2 = tree_entry_len(&t2->entry); - - cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); + e1 = &t1->entry; + e2 = &t2->entry; + cmp = base_name_compare(e1->path, tree_entry_len(e1), e1->mode, + e2->path, tree_entry_len(e2), e2->mode); return cmp; } From 14d3bb4955a41e146b6f1cd6571602a6b46b2af9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 26 Mar 2014 13:42:06 -0700 Subject: [PATCH 014/760] apply --ignore-space-change: lines with and without leading whitespaces do not match The fuzzy_matchlines() function is used when attempting to resurrect a patch that is whitespace-damaged, or when applying a patch that was produced against an old codebase to the codebase after indentation change. The patch may want to change a line "a_bc" ("_" is used throught this description for a whitespace to make it stand out) in the original into something else, and we may not find "a_bc" in the current source, but there may be "a__bc" (two spaces instead of one the whitespace-damaged patch claims to expect). By ignoring the amount of whitespaces, it forces "git apply" to consider that "a_bc" in the broken patch meant to refer to "a__bc" in reality. However, the implementation special cases a run of whitespaces at the beginning of a line and makes "abc" match "_abc", even though a whitespace in the middle of string never matches a 0-width gap, e.g. "a_bc" does not match "abc". A run of whitespace at the end of one string does not match a 0-width end of line on the other line, either, e.g. "abc_" does not match "abc". Fix this inconsistency by making the code skip leading whitespaces only when both strings begin with a whitespace. This makes the option mean the same as the option of the same name in "diff" and "git diff". Note that I am not sure if anybody sane should use this option in the first place. The fuzzy match logic may be able to find the original line that the patch author may have meant to touch because it does not fully trust what the original lines say (i.e. context lines prefixed by " " and old lines prefixed by "-" does not have to exactly match the contents the patch is applied to). There is no reason for us to trust what the replacement lines (i.e. new lines prefixed by "+") say, either, but with this option enabled, we end up copying these new lines with suspicious whitespace distributions literally into the patched result. But as long as we keep it, we should make it do its insane thing consistently. Signed-off-by: Junio C Hamano --- builtin/apply.c | 12 +++++++----- t/t4107-apply-ignore-whitespace.sh | 12 ++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index ef32e4f6241595..b2e641934e0c34 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -300,11 +300,13 @@ static int fuzzy_matchlines(const char *s1, size_t n1, while ((*last2 == '\r') || (*last2 == '\n')) last2--; - /* skip leading whitespace */ - while (isspace(*s1) && (s1 <= last1)) - s1++; - while (isspace(*s2) && (s2 <= last2)) - s2++; + /* skip leading whitespaces, if both begin with whitespace */ + if (s1 <= last1 && s2 <= last2 && isspace(*s1) && isspace(*s2)) { + while (isspace(*s1) && (s1 <= last1)) + s1++; + while (isspace(*s2) && (s2 <= last2)) + s2++; + } /* early return if both lines are empty */ if ((s1 > last1) && (s2 > last2)) return 1; diff --git a/t/t4107-apply-ignore-whitespace.sh b/t/t4107-apply-ignore-whitespace.sh index b04fc8fc12238c..9e29b5262d3f2e 100755 --- a/t/t4107-apply-ignore-whitespace.sh +++ b/t/t4107-apply-ignore-whitespace.sh @@ -111,7 +111,6 @@ sed -e 's/T/ /g' > main.c.final <<\EOF #include void print_int(int num); -T/* a comment */ int func(int num); int main() { @@ -154,7 +153,8 @@ test_expect_success 'patch2 reverse applies with --ignore-space-change' ' git config apply.ignorewhitespace change test_expect_success 'patch2 applies (apply.ignorewhitespace = change)' ' - git apply patch2.patch + git apply patch2.patch && + test_cmp main.c.final main.c ' test_expect_success 'patch3 fails (missing string at EOL)' ' @@ -165,12 +165,8 @@ test_expect_success 'patch4 fails (missing EOL at EOF)' ' test_must_fail git apply patch4.patch ' -test_expect_success 'patch5 applies (leading whitespace)' ' - git apply patch5.patch -' - -test_expect_success 'patches do not mangle whitespace' ' - test_cmp main.c main.c.final +test_expect_success 'patch5 fails (leading whitespace differences matter)' ' + test_must_fail git apply patch5.patch ' test_expect_success 're-create file (with --ignore-whitespace)' ' From 6ca844e9f5ca93efd0a1323a9c9aaa882c0043e8 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:44 +0400 Subject: [PATCH 015/760] tree-diff: remove special-case diff-emitting code for empty-tree cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While walking trees, we iterate their entries from lowest to highest in sort order, so empty tree means all entries were already went over. If we artificially assign +infinity value to such tree "entry", it will go after all usual entries, and through the usual driver loop we will be taking the same actions, which were hand-coded for special cases, i.e. t1 empty, t2 non-empty pathcmp(+∞, t2) -> +1 show_path(/*t1=*/NULL, t2); /* = t1 > t2 case in main loop */ t1 non-empty, t2-empty pathcmp(t1, +∞) -> -1 show_path(t1, /*t2=*/NULL); /* = t1 < t2 case in main loop */ In other words when we have t1 and t2, we return a sign that tells the caller to indicate the "earlier" one to be emitted, and by returning the sign that causes the non-empty side to be emitted, we will automatically cause the entries from the remaining side to be emitted, without attempting to touch the empty side at all. We can teach tree_entry_pathcmp() to pretend that an empty tree has an element that sorts after anything else to achieve this. Right now we never go to when compared tree descriptors are both infinity, as this condition is checked in the loop beginning as finishing criteria, but will do so in the future, when there will be several parents iterated simultaneously, and some pair of them would run to the end. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index f8b2607c6d93af..8e04002c0ecd21 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -12,12 +12,24 @@ * * NOTE files and directories *always* compare differently, even when having * the same name - thanks to base_name_compare(). + * + * NOTE empty (=invalid) descriptor(s) take part in comparison as +infty, + * so that they sort *after* valid tree entries. + * + * Due to this convention, if trees are scanned in sorted order, all + * non-empty descriptors will be processed first. */ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) { struct name_entry *e1, *e2; int cmp; + /* empty descriptors sort after valid tree entries */ + if (!t1->size) + return t2->size ? 1 : 0; + else if (!t2->size) + return -1; + e1 = &t1->entry; e2 = &t2->entry; cmp = base_name_compare(e1->path, tree_entry_len(e1), e1->mode, @@ -150,18 +162,8 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2, skip_uninteresting(t1, &base, opt); skip_uninteresting(t2, &base, opt); } - if (!t1->size) { - if (!t2->size) - break; - show_path(&base, opt, /*t1=*/NULL, t2); - update_tree_entry(t2); - continue; - } - if (!t2->size) { - show_path(&base, opt, t1, /*t2=*/NULL); - update_tree_entry(t1); - continue; - } + if (!t1->size && !t2->size) + break; cmp = tree_entry_pathcmp(t1, t2); From ad6f3cc7d2eaec5247b39e9dca8e55a0f98123e7 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:45 +0400 Subject: [PATCH 016/760] tree-diff: diff_tree() should now be static We reworked all its users to use the functionality through diff_tree_sha1 variant in recent patches (see "tree-diff: allow diff_tree_sha1 to accept NULL sha1" and what comes next). diff_tree() is now not used outside tree-diff.c - make it static. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- diff.h | 2 -- tree-diff.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/diff.h b/diff.h index e79f3b3ff09aed..5d7b9f7577a393 100644 --- a/diff.h +++ b/diff.h @@ -189,8 +189,6 @@ const char *diff_line_prefix(struct diff_options *); extern const char mime_boundary_leader[]; -extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2, - const char *base, struct diff_options *opt); extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt); extern int diff_root_tree_sha1(const unsigned char *new, const char *base, diff --git a/tree-diff.c b/tree-diff.c index 8e04002c0ecd21..0e43906b4318c0 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -141,8 +141,8 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, } } -int diff_tree(struct tree_desc *t1, struct tree_desc *t2, - const char *base_str, struct diff_options *opt) +static int diff_tree(struct tree_desc *t1, struct tree_desc *t2, + const char *base_str, struct diff_options *opt) { struct strbuf base; int baselen = strlen(base_str); From 52894e70951518e44c064cef2561aed38202fd36 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Thu, 27 Mar 2014 18:24:38 +0400 Subject: [PATCH 017/760] tree-diff: rework diff_tree interface to be sha1 based In the next commit this will allow to reduce intermediate calls, when recursing into subtrees - at that stage we know only subtree sha1, and it is natural for tree walker to start from that phase. For now we do diff_tree show_path diff_tree_sha1 diff_tree ... and the change will allow to reduce it to diff_tree show_path diff_tree Also, it will allow to omit allocating strbuf for each subtree, and just reuse the common strbuf via playing with its len. The above-mentioned improvements go in the next 2 patches. The downside is that try_to_follow_renames(), if active, we cause re-reading of 2 initial trees, which was negligible based on my timings, and which is outweighed cogently by the upsides. NOTE To keep with the current interface and semantics, I needed to rename the function from diff_tree() to diff_tree_sha1(). As diff_tree_sha1() was already used, and the function we are talking here is its more low-level helper, let's use convention for prefixing such helpers with "ll_". So the final renaming is diff_tree() -> ll_diff_tree_sha1() Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 60 +++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 0e43906b4318c0..55d81469f6c489 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -141,12 +141,17 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, } } -static int diff_tree(struct tree_desc *t1, struct tree_desc *t2, - const char *base_str, struct diff_options *opt) +static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, + const char *base_str, struct diff_options *opt) { + struct tree_desc t1, t2; + void *t1tree, *t2tree; struct strbuf base; int baselen = strlen(base_str); + t1tree = fill_tree_descriptor(&t1, old); + t2tree = fill_tree_descriptor(&t2, new); + /* Enable recursion indefinitely */ opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); @@ -159,39 +164,41 @@ static int diff_tree(struct tree_desc *t1, struct tree_desc *t2, if (diff_can_quit_early(opt)) break; if (opt->pathspec.nr) { - skip_uninteresting(t1, &base, opt); - skip_uninteresting(t2, &base, opt); + skip_uninteresting(&t1, &base, opt); + skip_uninteresting(&t2, &base, opt); } - if (!t1->size && !t2->size) + if (!t1.size && !t2.size) break; - cmp = tree_entry_pathcmp(t1, t2); + cmp = tree_entry_pathcmp(&t1, &t2); /* t1 = t2 */ if (cmp == 0) { if (DIFF_OPT_TST(opt, FIND_COPIES_HARDER) || - hashcmp(t1->entry.sha1, t2->entry.sha1) || - (t1->entry.mode != t2->entry.mode)) - show_path(&base, opt, t1, t2); + hashcmp(t1.entry.sha1, t2.entry.sha1) || + (t1.entry.mode != t2.entry.mode)) + show_path(&base, opt, &t1, &t2); - update_tree_entry(t1); - update_tree_entry(t2); + update_tree_entry(&t1); + update_tree_entry(&t2); } /* t1 < t2 */ else if (cmp < 0) { - show_path(&base, opt, t1, /*t2=*/NULL); - update_tree_entry(t1); + show_path(&base, opt, &t1, /*t2=*/NULL); + update_tree_entry(&t1); } /* t1 > t2 */ else { - show_path(&base, opt, /*t1=*/NULL, t2); - update_tree_entry(t2); + show_path(&base, opt, /*t1=*/NULL, &t2); + update_tree_entry(&t2); } } strbuf_release(&base); + free(t2tree); + free(t1tree); return 0; } @@ -206,7 +213,7 @@ static inline int diff_might_be_rename(void) !DIFF_FILE_VALID(diff_queued_diff.queue[0]->one); } -static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt) +static void try_to_follow_renames(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt) { struct diff_options diff_opts; struct diff_queue_struct *q = &diff_queued_diff; @@ -244,7 +251,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co diff_opts.break_opt = opt->break_opt; diff_opts.rename_score = opt->rename_score; diff_setup_done(&diff_opts); - diff_tree(t1, t2, base, &diff_opts); + ll_diff_tree_sha1(old, new, base, &diff_opts); diffcore_std(&diff_opts); free_pathspec(&diff_opts.pathspec); @@ -305,23 +312,12 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt) { - void *tree1, *tree2; - struct tree_desc t1, t2; - unsigned long size1, size2; int retval; - tree1 = fill_tree_descriptor(&t1, old); - tree2 = fill_tree_descriptor(&t2, new); - size1 = t1.size; - size2 = t2.size; - retval = diff_tree(&t1, &t2, base, opt); - if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) { - init_tree_desc(&t1, tree1, size1); - init_tree_desc(&t2, tree2, size2); - try_to_follow_renames(&t1, &t2, base, opt); - } - free(tree1); - free(tree2); + retval = ll_diff_tree_sha1(old, new, base, opt); + if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) + try_to_follow_renames(old, new, base, opt); + return retval; } From b9081a657446ac2c5e2129de183edb41d4b4f4fb Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Thu, 27 Mar 2014 18:21:29 +0400 Subject: [PATCH 018/760] tree-diff: no need to call "full" diff_tree_sha1 from show_path() As described in previous commit, when recursing into sub-trees, we can use lower-level tree walker, since its interface is now sha1 based. The change is ok, because diff_tree_sha1() only invokes ll_diff_tree_sha1(), and also, if base is empty, try_to_follow_renames(). But base is not empty here, as we have added a path and '/' before recursing. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 55d81469f6c489..80527c046472d4 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -6,6 +6,10 @@ #include "diffcore.h" #include "tree.h" + +static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, + const char *base_str, struct diff_options *opt); + /* * Compare two tree entries, taking into account only path/S_ISDIR(mode), * but not their sha1's. @@ -118,8 +122,8 @@ static void show_path(struct strbuf *base, struct diff_options *opt, if (recurse) { strbuf_addch(base, '/'); - diff_tree_sha1(t1 ? t1->entry.sha1 : NULL, - t2 ? t2->entry.sha1 : NULL, base->buf, opt); + ll_diff_tree_sha1(t1 ? t1->entry.sha1 : NULL, + t2 ? t2->entry.sha1 : NULL, base->buf, opt); } strbuf_setlen(base, old_baselen); From 12cd81743dc4645ef909b0c38582f5714c9a8ff7 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Thu, 27 Mar 2014 18:22:07 +0400 Subject: [PATCH 019/760] tree-diff: reuse base str(buf) memory on sub-tree recursion Instead of allocating it all the time for every subtree in ll_diff_tree_sha1, let's allocate it once in diff_tree_sha1, and then all callee just use it in stacking style, without memory allocations. This should be faster, and for me this change gives the following slight speedups for git log --raw --no-abbrev --no-renames --format='%H' navy.git linux.git v3.10..v3.11 before 0.618s 1.903s after 0.611s 1.889s speedup 1.1% 0.7% Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- tree-diff.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tree-diff.c b/tree-diff.c index 80527c046472d4..278acc807a3564 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -8,7 +8,7 @@ static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, - const char *base_str, struct diff_options *opt); + struct strbuf *base, struct diff_options *opt); /* * Compare two tree entries, taking into account only path/S_ISDIR(mode), @@ -123,7 +123,7 @@ static void show_path(struct strbuf *base, struct diff_options *opt, if (recurse) { strbuf_addch(base, '/'); ll_diff_tree_sha1(t1 ? t1->entry.sha1 : NULL, - t2 ? t2->entry.sha1 : NULL, base->buf, opt); + t2 ? t2->entry.sha1 : NULL, base, opt); } strbuf_setlen(base, old_baselen); @@ -146,12 +146,10 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, } static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, - const char *base_str, struct diff_options *opt) + struct strbuf *base, struct diff_options *opt) { struct tree_desc t1, t2; void *t1tree, *t2tree; - struct strbuf base; - int baselen = strlen(base_str); t1tree = fill_tree_descriptor(&t1, old); t2tree = fill_tree_descriptor(&t2, new); @@ -159,17 +157,14 @@ static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, /* Enable recursion indefinitely */ opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); - strbuf_init(&base, PATH_MAX); - strbuf_add(&base, base_str, baselen); - for (;;) { int cmp; if (diff_can_quit_early(opt)) break; if (opt->pathspec.nr) { - skip_uninteresting(&t1, &base, opt); - skip_uninteresting(&t2, &base, opt); + skip_uninteresting(&t1, base, opt); + skip_uninteresting(&t2, base, opt); } if (!t1.size && !t2.size) break; @@ -181,7 +176,7 @@ static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, if (DIFF_OPT_TST(opt, FIND_COPIES_HARDER) || hashcmp(t1.entry.sha1, t2.entry.sha1) || (t1.entry.mode != t2.entry.mode)) - show_path(&base, opt, &t1, &t2); + show_path(base, opt, &t1, &t2); update_tree_entry(&t1); update_tree_entry(&t2); @@ -189,18 +184,17 @@ static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, /* t1 < t2 */ else if (cmp < 0) { - show_path(&base, opt, &t1, /*t2=*/NULL); + show_path(base, opt, &t1, /*t2=*/NULL); update_tree_entry(&t1); } /* t1 > t2 */ else { - show_path(&base, opt, /*t1=*/NULL, &t2); + show_path(base, opt, /*t1=*/NULL, &t2); update_tree_entry(&t2); } } - strbuf_release(&base); free(t2tree); free(t1tree); return 0; @@ -217,7 +211,7 @@ static inline int diff_might_be_rename(void) !DIFF_FILE_VALID(diff_queued_diff.queue[0]->one); } -static void try_to_follow_renames(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt) +static void try_to_follow_renames(const unsigned char *old, const unsigned char *new, struct strbuf *base, struct diff_options *opt) { struct diff_options diff_opts; struct diff_queue_struct *q = &diff_queued_diff; @@ -314,13 +308,19 @@ static void try_to_follow_renames(const unsigned char *old, const unsigned char q->nr = 1; } -int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt) +int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base_str, struct diff_options *opt) { + struct strbuf base; int retval; - retval = ll_diff_tree_sha1(old, new, base, opt); - if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) - try_to_follow_renames(old, new, base, opt); + strbuf_init(&base, PATH_MAX); + strbuf_addstr(&base, base_str); + + retval = ll_diff_tree_sha1(old, new, &base, opt); + if (!*base_str && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) + try_to_follow_renames(old, new, &base, opt); + + strbuf_release(&base); return retval; } From 61f76a3612db199a9eb9090c2605d8fc35ffc41c Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Thu, 27 Mar 2014 18:22:50 +0400 Subject: [PATCH 020/760] Portable alloca for Git In the next patch we'll have to use alloca() for performance reasons, but since alloca is non-standardized and is not portable, let's have a trick with compatibility wrappers: 1. at configure time, determine, do we have working alloca() through alloca.h, and define #define HAVE_ALLOCA_H if yes. 2. in code #ifdef HAVE_ALLOCA_H # include # define xalloca(size) (alloca(size)) # define xalloca_free(p) do {} while(0) #else # define xalloca(size) (xmalloc(size)) # define xalloca_free(p) (free(p)) #endif and use it like func() { p = xalloca(size); ... xalloca_free(p); } This way, for systems, where alloca is available, we'll have optimal on-stack allocations with fast executions. On the other hand, on systems, where alloca is not available, this gracefully fallbacks to xmalloc/free. Both autoconf and config.mak.uname configurations were updated. For autoconf, we are not bothering considering cases, when no alloca.h is available, but alloca() works some other way - its simply alloca.h is available and works or not, everything else is deep legacy. For config.mak.uname, I've tried to make my almost-sure guess for where alloca() is available, but since I only have access to Linux it is the only change I can be sure about myself, with relevant to other changed systems people Cc'ed. NOTE SunOS and Windows had explicit -DHAVE_ALLOCA_H in their configurations. I've changed that to now-common HAVE_ALLOCA_H=YesPlease which should be correct. Cc: Brandon Casey Cc: Marius Storm-Olsen Cc: Johannes Sixt Cc: Johannes Schindelin Cc: Ramsay Jones Cc: Gerrit Pape Cc: Petr Salinger Cc: Jonathan Nieder Acked-by: Thomas Schwinge (GNU Hurd changes) Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- Makefile | 6 ++++++ config.mak.uname | 10 ++++++++-- configure.ac | 8 ++++++++ git-compat-util.h | 8 ++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dddaf4f287cf5c..03348066bc17a9 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,8 @@ all:: # Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in # /foo/bar/include and /foo/bar/lib directories. # +# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header. +# # Define NO_CURL if you do not have libcurl installed. git-http-fetch and # git-http-push are not built, and you cannot use http:// and https:// # transports (neither smart nor dumb). @@ -1099,6 +1101,10 @@ ifdef USE_LIBPCRE EXTLIBS += -lpcre endif +ifdef HAVE_ALLOCA_H + BASIC_CFLAGS += -DHAVE_ALLOCA_H +endif + ifdef NO_CURL BASIC_CFLAGS += -DNO_CURL REMOTE_CURL_PRIMARY = diff --git a/config.mak.uname b/config.mak.uname index 7d31fad241761e..71602ee9a16951 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -28,6 +28,7 @@ ifeq ($(uname_S),OSF1) NO_NSEC = YesPlease endif ifeq ($(uname_S),Linux) + HAVE_ALLOCA_H = YesPlease NO_STRLCPY = YesPlease NO_MKSTEMPS = YesPlease HAVE_PATHS_H = YesPlease @@ -35,6 +36,7 @@ ifeq ($(uname_S),Linux) HAVE_DEV_TTY = YesPlease endif ifeq ($(uname_S),GNU/kFreeBSD) + HAVE_ALLOCA_H = YesPlease NO_STRLCPY = YesPlease NO_MKSTEMPS = YesPlease HAVE_PATHS_H = YesPlease @@ -103,6 +105,7 @@ ifeq ($(uname_S),SunOS) NEEDS_NSL = YesPlease SHELL_PATH = /bin/bash SANE_TOOL_PATH = /usr/xpg6/bin:/usr/xpg4/bin + HAVE_ALLOCA_H = YesPlease NO_STRCASESTR = YesPlease NO_MEMMEM = YesPlease NO_MKDTEMP = YesPlease @@ -146,7 +149,7 @@ ifeq ($(uname_S),SunOS) endif INSTALL = /usr/ucb/install TAR = gtar - BASIC_CFLAGS += -D__EXTENSIONS__ -D__sun__ -DHAVE_ALLOCA_H + BASIC_CFLAGS += -D__EXTENSIONS__ -D__sun__ endif ifeq ($(uname_O),Cygwin) ifeq ($(shell expr "$(uname_R)" : '1\.[1-6]\.'),4) @@ -166,6 +169,7 @@ ifeq ($(uname_O),Cygwin) else NO_REGEX = UnfortunatelyYes endif + HAVE_ALLOCA_H = YesPlease NEEDS_LIBICONV = YesPlease NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease @@ -239,6 +243,7 @@ ifeq ($(uname_S),AIX) endif ifeq ($(uname_S),GNU) # GNU/Hurd + HAVE_ALLOCA_H = YesPlease NO_STRLCPY = YesPlease NO_MKSTEMPS = YesPlease HAVE_PATHS_H = YesPlease @@ -316,6 +321,7 @@ endif ifeq ($(uname_S),Windows) GIT_VERSION := $(GIT_VERSION).MSVC pathsep = ; + HAVE_ALLOCA_H = YesPlease NO_PREAD = YesPlease NEEDS_CRYPTO_WITH_SSL = YesPlease NO_LIBGEN_H = YesPlease @@ -363,7 +369,7 @@ ifeq ($(uname_S),Windows) COMPAT_OBJS = compat/msvc.o compat/winansi.o \ compat/win32/pthread.o compat/win32/syslog.o \ compat/win32/dirent.o - COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\" + COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\" BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib PTHREAD_LIBS = diff --git a/configure.ac b/configure.ac index 2f433939dc9d90..0eae70430cc837 100644 --- a/configure.ac +++ b/configure.ac @@ -272,6 +272,14 @@ AS_HELP_STRING([], [ARG can be also prefix for libpcre library and hea GIT_CONF_SUBST([LIBPCREDIR]) fi) # +# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header. +AC_FUNC_ALLOCA +case $ac_cv_working_alloca_h in + yes) HAVE_ALLOCA_H=YesPlease;; + *) HAVE_ALLOCA_H='';; +esac +GIT_CONF_SUBST([HAVE_ALLOCA_H]) +# # Define NO_CURL if you do not have curl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https:// # transports. diff --git a/git-compat-util.h b/git-compat-util.h index cbd86c37f51c00..63b2b3bb47c79f 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -526,6 +526,14 @@ extern void release_pack_memory(size_t); typedef void (*try_to_free_t)(size_t); extern try_to_free_t set_try_to_free_routine(try_to_free_t); +#ifdef HAVE_ALLOCA_H +# include +# define xalloca(size) (alloca(size)) +# define xalloca_free(p) do {} while (0) +#else +# define xalloca(size) (xmalloc(size)) +# define xalloca_free(p) (free(p)) +#endif extern char *xstrdup(const char *str); extern void *xmalloc(size_t size); extern void *xmallocz(size_t size); From 1d2f393ac9bfb4c20f14d6ead7bb4c56e766ab77 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Sat, 5 Apr 2014 18:59:03 +0200 Subject: [PATCH 021/760] status/commit: show staged submodules regardless of ignore config Currently setting submodule..ignore and/or diff.ignoreSubmodules to "all" suppresses all output of submodule changes for the diff family, status and commit. For status and commit this is really confusing, as it even when the user chooses to record a new commit for an ignored submodule by adding it manually this change won't show up under the to-be-committed changes. To add insult to injury, a later "git commit" will error out with "nothing to commit" when only ignored submodules are staged. Fix that by making wt_status always print staged submodule changes, no matter what ignore settings are configured. The only exception is when the user explicitly uses the "--ignore-submodules=all" command line option, in that case the submodule output is still suppressed. This also makes "git commit" work again when only modifications of ignored submodules are staged, as that command uses the "commitable" member of the wt_status struct to determine if staged changes are present. But this only happens when the commit command uses the wt_status* functions to produce status output for human consumption (when forking an editor or with --dry-run), in all other cases (e.g. when run in a script with '-m') another code path is taken which uses index_differs_from() to determine if any changes are staged which still ignores submodules according to their configuration. This will be fixed in a follow-up commit. Change t7508 to reflect this new behavior and add three new tests to show that a single staged submodule configured to be ignored will be committed when the status output is generated and won't be if not. Also update the documentation of the ignore config options accordingly. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- Documentation/config.txt | 8 +++- Documentation/gitmodules.txt | 4 +- t/t7508-status.sh | 74 +++++++++++++++++++++++++++++++++++- wt-status.c | 12 +++++- 4 files changed, 92 insertions(+), 6 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 5f4d7939ed1ec2..2ecce0573586f9 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -2227,7 +2227,9 @@ status.submodulesummary:: --summary-limit option of linkgit:git-submodule[1]). Please note that the summary output command will be suppressed for all submodules when `diff.ignoreSubmodules` is set to 'all' or only - for those submodules where `submodule..ignore=all`. To + for those submodules where `submodule..ignore=all`. The only + exception to that rule is that status and commit will show staged + submodule changes. To also view the summary for ignored submodules you can either use the --ignore-submodules=dirty command line option or the 'git submodule summary' command, which shows a similar output but does @@ -2258,7 +2260,9 @@ submodule..fetchRecurseSubmodules:: submodule..ignore:: Defines under what circumstances "git status" and the diff family show a submodule as modified. When set to "all", it will never be considered - modified, "dirty" will ignore all changes to the submodules work tree and + modified (but it will nonetheless show up in the output of status and + commit when it has been staged), "dirty" will ignore all changes + to the submodules work tree and takes only differences between the HEAD of the submodule and the commit recorded in the superproject into account. "untracked" will additionally let submodules with modified tracked files in their work tree show up. diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt index 347a9f76ee809c..f6c0dfd0290a9b 100644 --- a/Documentation/gitmodules.txt +++ b/Documentation/gitmodules.txt @@ -67,7 +67,9 @@ submodule..fetchRecurseSubmodules:: submodule..ignore:: Defines under what circumstances "git status" and the diff family show a submodule as modified. When set to "all", it will never be considered - modified, "dirty" will ignore all changes to the submodules work tree and + modified (but will nonetheless show up in the output of status and + commit when it has been staged), "dirty" will ignore all changes + to the submodules work tree and takes only differences between the HEAD of the submodule and the commit recorded in the superproject into account. "untracked" will additionally let submodules with modified tracked files in their work tree show up. diff --git a/t/t7508-status.sh b/t/t7508-status.sh index c987b5ed652b97..e6483fcd423133 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1380,7 +1380,32 @@ EOF test_i18ncmp expect output ' -test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' +test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD ..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git checkout -- ..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add ..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1388,7 +1413,7 @@ test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success '.git/config ignore=all suppresses submodule summary' ' +test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore all && @@ -1461,4 +1486,49 @@ test_expect_success 'Restore default test environment' ' git config --unset status.showUntrackedFiles ' +test_expect_success 'git commit will commit a staged but ignored submodule' ' + git config --add -f .gitmodules submodule.subname.ignore all && + git config --add -f .gitmodules submodule.subname.path sm && + git config --add submodule.subname.ignore all && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output && + GIT_EDITOR="echo hello >>\"\$1\"" && + export GIT_EDITOR && + git commit -uno && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output +' + +test_expect_success 'git commit --dry-run will show a staged but ignored submodule' ' + git reset HEAD^ && + git add sm && + cat >expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD ..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git checkout -- ..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files not listed (use -u option to show untracked files) +EOF + git commit -uno --dry-run >output && + test_i18ncmp expect output && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output +' + +test_expect_failure 'git commit -m will commit a staged but ignored submodule' ' + git commit -uno -m message && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output && + git config --remove-section submodule.subname && + git config -f .gitmodules --remove-section submodule.subname +' + test_done diff --git a/wt-status.c b/wt-status.c index 4e5581005936a1..ccdf02fc8a8f92 100644 --- a/wt-status.c +++ b/wt-status.c @@ -486,9 +486,19 @@ static void wt_status_collect_changes_index(struct wt_status *s) opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; setup_revisions(0, NULL, &rev, &opt); + DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG); if (s->ignore_submodule_arg) { - DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG); handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg); + } else { + /* + * Unless the user did explicitly request a submodule ignore + * mode by passing a command line option we do not ignore any + * changed submodule SHA-1s when comparing index and HEAD, no + * matter what is configured. Otherwise the user won't be + * shown any submodules she manually added (and which are + * staged to be committed), which would be really confusing. + */ + handle_ignore_submodules_arg(&rev.diffopt, "dirty"); } rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; From c215d3d2826c882feb819e5743287ec74d9ff693 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Sat, 5 Apr 2014 18:59:36 +0200 Subject: [PATCH 022/760] commit -m: commit staged submodules regardless of ignore config The previous commit fixed the problem that the staged but that ignored submodules did not show up in the status output of the commit command and weren't committed afterwards either. But when commit doesn't generate the status output (e.g. when used in a script with '-m') the ignored submodule will still not be committed. This is because in that case a different code path is taken which calls index_differs_from() instead of calling the wt_status functions. Fix that by calling index_differs_from() from builtin/commit.c with a diff_options argument value that tells it not ignore any submodule changes unless the '--ignore-submodules' option is used. Even though this option isn't yet implemented for cmd_commit() but only for cmd_status() this prepares cmd_commit() to correctly handle the '--ignore-submodules' option later. As status and commit share the same ignore_submodule_arg variable this makes the code more robust against accidental breakage and documents how to correctly call index_differs_from(). Change the expected result of the test documenting this problem from failure to success. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- builtin/commit.c | 18 ++++++++++++++++-- t/t7508-status.sh | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 3767478c6ddb02..2341a4b7f785e7 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -826,8 +826,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (get_sha1(parent, sha1)) commitable = !!active_nr; - else - commitable = index_differs_from(parent, 0); + else { + /* + * Unless the user did explicitly request a submodule + * ignore mode by passing a command line option we do + * not ignore any changed submodule SHA-1s when + * comparing index and parent, no matter what is + * configured. Otherwise we won't commit any + * submodules which were manually staged, which would + * be really confusing. + */ + int diff_flags = DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG; + if (ignore_submodule_arg && + !strcmp(ignore_submodule_arg, "all")) + diff_flags |= DIFF_OPT_IGNORE_SUBMODULES; + commitable = index_differs_from(parent, diff_flags); + } } strbuf_release(&committer_ident); diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e6483fcd423133..d48006960e8b4e 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1523,7 +1523,7 @@ EOF test_i18ngrep "^M. sm" output ' -test_expect_failure 'git commit -m will commit a staged but ignored submodule' ' +test_expect_success 'git commit -m will commit a staged but ignored submodule' ' git commit -uno -m message && git status -s --ignore-submodules=dirty >output && test_i18ngrep ! "^M. sm" output && From b984d333a1367078c3631b8dfdd0d0ec7b332715 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:52 +0200 Subject: [PATCH 023/760] t1400: fix name and expected result of one test The test stdin -z create ref fails with zero new value actually passes an empty new value, not a zero new value. So rename the test s/zero/empty/, and change the expected error from fatal: create $c given zero new value to fatal: create $c missing Of course, this makes the test fail now, because although "git update-ref" tries to distinguish between these two errors, it does not succeed in this situation. Fixing it is more than a one-liner, so mark the test test_expect_failure for now. The failure will be fixed later in this patch series. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 6ffd82fe321cd3..fa927d21846d64 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -827,10 +827,10 @@ test_expect_success 'stdin -z create ref fails with bad new value' ' test_must_fail git rev-parse --verify -q $c ' -test_expect_success 'stdin -z create ref fails with zero new value' ' +test_expect_failure 'stdin -z create ref fails with empty new value' ' printf $F "create $c" "" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: create $c given zero new value" err && + grep "fatal: create $c missing " err && test_must_fail git rev-parse --verify -q $c ' From c13291108880f9adc26a2ab5c09535869afecb22 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:53 +0200 Subject: [PATCH 024/760] t1400: provide more usual input to the command The old version was passing (among other things) update SP refs/heads/c NUL NUL 0{40} NUL to "git update-ref -z --stdin" to test whether the old-value check for c is working. But the is empty, which is a bit off the beaten track. So, to be sure that we are testing what we want to test, provide an actual on the "update" line. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index fa927d21846d64..29391c67fc9aac 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -912,7 +912,7 @@ test_expect_success 'stdin -z update refs works with identity updates' ' test_expect_success 'stdin -z update refs fails with wrong old value' ' git update-ref $c $m && - printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "" "$Z" >stdin && + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin && test_must_fail git update-ref -z --stdin err && grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && git rev-parse $m >expect && From 697a41519b0d41c1b2c5714b5558f68814d78885 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:54 +0200 Subject: [PATCH 025/760] parse_arg(): really test that argument is properly terminated The old parse_arg(), when fed an argument "refs/heads/a"master parsed 'refs/heads/a' off of the front of the argument and considered itself successful. It was only when parse_next_arg() tried to parse the *next* argument that a problem was noticed. But in fact, the definition of the input format requires arguments to be terminated by SP or NUL, so *this* argument is already erroneous and parse_arg() should diagnose the problem. So teach parse_arg() to verify that C-quoted arguments are terminated correctly. If not, emit a more specific error message. There is no corresponding error case of a non-C-quoted argument that is not terminated correctly, because the end of a non-quoted argument is *by definition* a space or NUL, so there is no way to insert other junk between the "end" of the argument and the argument terminator. Adjust the tests to expect the new error message. Add a docstring to the function, incorporating the comments that were formerly within the function plus some added information. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 20 +++++++++++++++----- t/t1400-update-ref.sh | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 1292cfea11d87e..02b5f950e34a31 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -62,16 +62,26 @@ static void update_store_old_sha1(struct ref_update *update, update->have_old = *oldvalue || line_termination; } +/* + * Parse one whitespace- or NUL-terminated, possibly C-quoted argument + * and append the result to arg. Return a pointer to the terminator. + * Die if there is an error in how the argument is C-quoted. This + * function is only used if not -z. + */ static const char *parse_arg(const char *next, struct strbuf *arg) { - /* Parse SP-terminated, possibly C-quoted argument */ - if (*next != '"') + if (*next == '"') { + const char *orig = next; + + if (unquote_c_style(arg, next, &next)) + die("badly quoted argument: %s", orig); + if (*next && !isspace(*next)) + die("unexpected character after quoted argument: %s", orig); + } else { while (*next && !isspace(*next)) strbuf_addch(arg, *next++); - else if (unquote_c_style(arg, next, &next)) - die("badly quoted argument: %s", next); + } - /* Return position after the argument */ return next; } diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 29391c67fc9aac..774f8c5bf16b21 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -356,10 +356,10 @@ test_expect_success 'stdin fails on badly quoted input' ' grep "fatal: badly quoted argument: \\\"master" err ' -test_expect_success 'stdin fails on arguments not separated by space' ' +test_expect_success 'stdin fails on junk after quoted argument' ' echo "create \"$a\"master" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: expected SP but got: master" err + grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err ' test_expect_success 'stdin fails create with no ref' ' From 20fcffcc8de9fcfba15fce916ff38c98ca20323d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:55 +0200 Subject: [PATCH 026/760] t1400: add some more tests involving quoted arguments Previously there were no good tests of C-quoted arguments. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 774f8c5bf16b21..00862bc28ee7d9 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -350,12 +350,18 @@ test_expect_success 'stdin fails on unknown command' ' grep "fatal: unknown command: unknown $a" err ' -test_expect_success 'stdin fails on badly quoted input' ' +test_expect_success 'stdin fails on unbalanced quotes' ' echo "create $a \"master" >stdin && test_must_fail git update-ref --stdin err && grep "fatal: badly quoted argument: \\\"master" err ' +test_expect_success 'stdin fails on invalid escape' ' + echo "create $a \"ma\zter\"" >stdin && + test_must_fail git update-ref --stdin err && + grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err +' + test_expect_success 'stdin fails on junk after quoted argument' ' echo "create \"$a\"master" >stdin && test_must_fail git update-ref --stdin err && @@ -458,6 +464,24 @@ test_expect_success 'stdin create ref works' ' test_cmp expect actual ' +test_expect_success 'stdin succeeds with quoted argument' ' + git update-ref -d $a && + echo "create $a \"$m\"" >stdin && + git update-ref --stdin expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin succeeds with escaped character' ' + git update-ref -d $a && + echo "create $a \"ma\\163ter\"" >stdin && + git update-ref --stdin expect && + git rev-parse $a >actual && + test_cmp expect actual +' + test_expect_success 'stdin update ref creates with zero old value' ' echo "update $b $m $Z" >stdin && git update-ref --stdin Date: Mon, 7 Apr 2014 15:47:56 +0200 Subject: [PATCH 027/760] refs.h: rename the action_on_err constants Given that these constants are only being used when updating references, it is inappropriate to give them such generic names as "DIE_ON_ERR". So prefix their names with "UPDATE_REFS_". Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/checkout.c | 2 +- builtin/clone.c | 9 +++++---- builtin/merge.c | 6 +++--- builtin/notes.c | 6 +++--- builtin/reset.c | 6 ++++-- builtin/update-ref.c | 5 +++-- contrib/examples/builtin-fetch--tool.c | 3 ++- notes-cache.c | 2 +- notes-utils.c | 3 ++- refs.c | 18 +++++++++--------- refs.h | 9 +++++++-- 11 files changed, 40 insertions(+), 29 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 1b86d9c868c35c..6bf23188c9e68d 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -624,7 +624,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, /* Nothing to do. */ } else if (opts->force_detach || !new->path) { /* No longer on any branch. */ update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL, - REF_NODEREF, DIE_ON_ERR); + REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); if (!opts->quiet) { if (old->path && advice_detached_head) detach_advice(new->name); diff --git a/builtin/clone.c b/builtin/clone.c index 9b3c04d914b3d3..b12989d1caecb4 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -521,7 +521,7 @@ static void write_followtags(const struct ref *refs, const char *msg) if (!has_sha1_file(ref->old_sha1)) continue; update_ref(msg, ref->name, ref->old_sha1, - NULL, 0, DIE_ON_ERR); + NULL, 0, UPDATE_REFS_DIE_ON_ERR); } } @@ -589,14 +589,15 @@ static void update_head(const struct ref *our, const struct ref *remote, create_symref("HEAD", our->name, NULL); if (!option_bare) { const char *head = skip_prefix(our->name, "refs/heads/"); - update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR); + update_ref(msg, "HEAD", our->old_sha1, NULL, 0, + UPDATE_REFS_DIE_ON_ERR); install_branch_config(0, head, option_origin, our->name); } } else if (our) { struct commit *c = lookup_commit_reference(our->old_sha1); /* --branch specifies a non-branch (i.e. tags), detach HEAD */ update_ref(msg, "HEAD", c->object.sha1, - NULL, REF_NODEREF, DIE_ON_ERR); + NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); } else if (remote) { /* * We know remote HEAD points to a non-branch, or @@ -604,7 +605,7 @@ static void update_head(const struct ref *our, const struct ref *remote, * Detach HEAD in all these cases. */ update_ref(msg, "HEAD", remote->old_sha1, - NULL, REF_NODEREF, DIE_ON_ERR); + NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); } } diff --git a/builtin/merge.c b/builtin/merge.c index e15d0e145a51d5..7d1d83e8a509bc 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -398,7 +398,7 @@ static void finish(struct commit *head_commit, const char *argv_gc_auto[] = { "gc", "--auto", NULL }; update_ref(reflog_message.buf, "HEAD", new_head, head, 0, - DIE_ON_ERR); + UPDATE_REFS_DIE_ON_ERR); /* * We ignore errors in 'gc --auto', since the * user should see them. @@ -1222,7 +1222,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) die(_("%s - not something we can merge"), argv[0]); read_empty(remote_head->object.sha1, 0); update_ref("initial pull", "HEAD", remote_head->object.sha1, - NULL, 0, DIE_ON_ERR); + NULL, 0, UPDATE_REFS_DIE_ON_ERR); goto done; } else { struct strbuf merge_names = STRBUF_INIT; @@ -1339,7 +1339,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1, - NULL, 0, DIE_ON_ERR); + NULL, 0, UPDATE_REFS_DIE_ON_ERR); if (remoteheads && !common) ; /* No common ancestors found. We need a real merge. */ diff --git a/builtin/notes.c b/builtin/notes.c index bb89930373451e..66147b673946dc 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -717,7 +717,7 @@ static int merge_commit(struct notes_merge_options *o) strbuf_insert(&msg, 0, "notes: ", 7); update_ref(msg.buf, o->local_ref, sha1, is_null_sha1(parent_sha1) ? NULL : parent_sha1, - 0, DIE_ON_ERR); + 0, UPDATE_REFS_DIE_ON_ERR); free_notes(t); strbuf_release(&msg); @@ -812,11 +812,11 @@ static int merge(int argc, const char **argv, const char *prefix) if (result >= 0) /* Merge resulted (trivially) in result_sha1 */ /* Update default notes ref with new commit */ update_ref(msg.buf, default_notes_ref(), result_sha1, NULL, - 0, DIE_ON_ERR); + 0, UPDATE_REFS_DIE_ON_ERR); else { /* Merge has unresolved conflicts */ /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */ update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL, - 0, DIE_ON_ERR); + 0, UPDATE_REFS_DIE_ON_ERR); /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL)) die("Failed to store link to current notes ref (%s)", diff --git a/builtin/reset.c b/builtin/reset.c index f4e087596b6337..f368266762fae1 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -252,11 +252,13 @@ static int reset_refs(const char *rev, const unsigned char *sha1) if (!get_sha1("HEAD", sha1_orig)) { orig = sha1_orig; set_reflog_message(&msg, "updating ORIG_HEAD", NULL); - update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0, MSG_ON_ERR); + update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0, + UPDATE_REFS_MSG_ON_ERR); } else if (old_orig) delete_ref("ORIG_HEAD", old_orig, 0); set_reflog_message(&msg, "updating HEAD", rev); - update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0, MSG_ON_ERR); + update_ref_status = update_ref(msg.buf, "HEAD", sha1, orig, 0, + UPDATE_REFS_MSG_ON_ERR); strbuf_release(&msg); return update_ref_status; } diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 02b5f950e34a31..f6345e5251c07c 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -282,7 +282,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) if (end_null) line_termination = '\0'; update_refs_stdin(); - return update_refs(msg, updates, updates_count, DIE_ON_ERR); + return update_refs(msg, updates, updates_count, + UPDATE_REFS_DIE_ON_ERR); } if (end_null) @@ -314,5 +315,5 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) return delete_ref(refname, oldval ? oldsha1 : NULL, flags); else return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL, - flags, DIE_ON_ERR); + flags, UPDATE_REFS_DIE_ON_ERR); } diff --git a/contrib/examples/builtin-fetch--tool.c b/contrib/examples/builtin-fetch--tool.c index 8bc8c7533a8678..ee1916641e46c1 100644 --- a/contrib/examples/builtin-fetch--tool.c +++ b/contrib/examples/builtin-fetch--tool.c @@ -31,7 +31,8 @@ static int update_ref_env(const char *action, rla = "(reflog update)"; if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg)) warning("reflog message too long: %.*s...", 50, msg); - return update_ref(msg, refname, sha1, oldval, 0, QUIET_ON_ERR); + return update_ref(msg, refname, sha1, oldval, 0, + UPDATE_REFS_QUIET_ON_ERR); } static int update_local_ref(const char *name, diff --git a/notes-cache.c b/notes-cache.c index eabe4a0d9bf440..97dfd63c9bf564 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -62,7 +62,7 @@ int notes_cache_write(struct notes_cache *c) if (commit_tree(&msg, tree_sha1, NULL, commit_sha1, NULL, NULL) < 0) return -1; if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL, - 0, QUIET_ON_ERR) < 0) + 0, UPDATE_REFS_QUIET_ON_ERR) < 0) return -1; return 0; diff --git a/notes-utils.c b/notes-utils.c index 4aa7023903374a..a0b1d7be982533 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -48,7 +48,8 @@ void commit_notes(struct notes_tree *t, const char *msg) create_notes_commit(t, NULL, &buf, commit_sha1); strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */ - update_ref(buf.buf, t->ref, commit_sha1, NULL, 0, DIE_ON_ERR); + update_ref(buf.buf, t->ref, commit_sha1, NULL, 0, + UPDATE_REFS_DIE_ON_ERR); strbuf_release(&buf); } diff --git a/refs.c b/refs.c index 28d5eca8eaff7b..196984e12ebb2c 100644 --- a/refs.c +++ b/refs.c @@ -3243,9 +3243,9 @@ static struct ref_lock *update_ref_lock(const char *refname, if (!lock) { const char *str = "Cannot lock the ref '%s'."; switch (onerr) { - case MSG_ON_ERR: error(str, refname); break; - case DIE_ON_ERR: die(str, refname); break; - case QUIET_ON_ERR: break; + case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break; + case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break; + case UPDATE_REFS_QUIET_ON_ERR: break; } } return lock; @@ -3258,9 +3258,9 @@ static int update_ref_write(const char *action, const char *refname, if (write_ref_sha1(lock, sha1, action) < 0) { const char *str = "Cannot update the ref '%s'."; switch (onerr) { - case MSG_ON_ERR: error(str, refname); break; - case DIE_ON_ERR: die(str, refname); break; - case QUIET_ON_ERR: break; + case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break; + case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break; + case UPDATE_REFS_QUIET_ON_ERR: break; } return 1; } @@ -3294,11 +3294,11 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, const char *str = "Multiple updates for ref '%s' not allowed."; switch (onerr) { - case MSG_ON_ERR: + case UPDATE_REFS_MSG_ON_ERR: error(str, updates[i]->ref_name); break; - case DIE_ON_ERR: + case UPDATE_REFS_DIE_ON_ERR: die(str, updates[i]->ref_name); break; - case QUIET_ON_ERR: + case UPDATE_REFS_QUIET_ON_ERR: break; } return 1; diff --git a/refs.h b/refs.h index 87a1a79ad659f3..a713b34ad8a48c 100644 --- a/refs.h +++ b/refs.h @@ -214,8 +214,13 @@ extern int rename_ref(const char *oldref, const char *newref, const char *logmsg */ extern int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1); -/** lock a ref and then write its file */ -enum action_on_err { MSG_ON_ERR, DIE_ON_ERR, QUIET_ON_ERR }; +enum action_on_err { + UPDATE_REFS_MSG_ON_ERR, + UPDATE_REFS_DIE_ON_ERR, + UPDATE_REFS_QUIET_ON_ERR +}; + +/** Lock a ref and then write its file */ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr); From 595deb8da69b4f816ff0c8e669b49f7527ff609b Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:57 +0200 Subject: [PATCH 028/760] update_refs(): fix constness The old signature of update_refs() required a (const struct ref_update **) for its updates_orig argument. The "const" is presumably there to promise that the function will not modify the contents of the structures. But this declaration does not permit the function to be called with a (struct ref_update **), which is perfectly legitimate. C's type system is not powerful enough to express what we'd like. So remove the first "const" from the declaration. On the other hand, the function *can* promise not to modify the pointers within the array that is passed to it without inconveniencing its callers. So add a "const" that has that effect, making the final declaration (struct ref_update * const *). Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 2 +- refs.c | 2 +- refs.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index f6345e5251c07c..a8a68e8a50a293 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -14,7 +14,7 @@ static const char * const git_update_ref_usage[] = { static int updates_alloc; static int updates_count; -static const struct ref_update **updates; +static struct ref_update **updates; static char line_termination = '\n'; static int update_flags; diff --git a/refs.c b/refs.c index 196984e12ebb2c..1305eb1fcff6d9 100644 --- a/refs.c +++ b/refs.c @@ -3306,7 +3306,7 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, return 0; } -int update_refs(const char *action, const struct ref_update **updates_orig, +int update_refs(const char *action, struct ref_update * const *updates_orig, int n, enum action_on_err onerr) { int ret = 0, delnum = 0, i; diff --git a/refs.h b/refs.h index a713b34ad8a48c..08e60ac07f2611 100644 --- a/refs.h +++ b/refs.h @@ -228,7 +228,7 @@ int update_ref(const char *action, const char *refname, /** * Lock all refs and then perform all modifications. */ -int update_refs(const char *action, const struct ref_update **updates, +int update_refs(const char *action, struct ref_update * const *updates, int n, enum action_on_err onerr); extern int parse_hide_refs_config(const char *var, const char *value, const char *); From e23d84350a3f4a3bfb86037eb1e6c4b28240324e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:58 +0200 Subject: [PATCH 029/760] update-ref --stdin: read the whole input at once Read the whole input into a strbuf at once, and then parse it from there. This might also be a tad faster, but that is not the point. The point is to decouple the parsing code from the input source (the old parsing code had to read new data even in the middle of commands). Add docstrings for the parsing functions. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 170 +++++++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 62 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index a8a68e8a50a293..5f197fe2122e79 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -85,44 +85,70 @@ static const char *parse_arg(const char *next, struct strbuf *arg) return next; } -static const char *parse_first_arg(const char *next, struct strbuf *arg) +/* + * Parse the argument immediately after "command SP". If not -z, then + * handle C-quoting. Write the argument to arg. Set *next to point + * at the character that terminates the argument. Die if C-quoting is + * malformed. + */ +static void parse_first_arg(struct strbuf *input, const char **next, + struct strbuf *arg) { - /* Parse argument immediately after "command SP" */ strbuf_reset(arg); if (line_termination) { /* Without -z, use the next argument */ - next = parse_arg(next, arg); + *next = parse_arg(*next, arg); } else { - /* With -z, use rest of first NUL-terminated line */ - strbuf_addstr(arg, next); - next = next + arg->len; + /* With -z, use everything up to the next NUL */ + strbuf_addstr(arg, *next); + *next += arg->len; } - return next; } -static const char *parse_next_arg(const char *next, struct strbuf *arg) +/* + * Parse a SP/NUL separator followed by the next SP- or NUL-terminated + * argument, if any. If there is an argument, write it to arg, set + * *next to point at the character terminating the argument, and + * return 0. If there is no argument at all (not even the empty + * string), return a non-zero result and leave *next unchanged. + */ +static int parse_next_arg(struct strbuf *input, const char **next, + struct strbuf *arg) { - /* Parse next SP-terminated or NUL-terminated argument, if any */ strbuf_reset(arg); if (line_termination) { /* Without -z, consume SP and use next argument */ - if (!*next) - return NULL; - if (*next != ' ') - die("expected SP but got: %s", next); - next = parse_arg(next + 1, arg); + if (!**next || **next == line_termination) + return -1; + if (**next != ' ') + die("expected SP but got: %s", *next); + (*next)++; + *next = parse_arg(*next, arg); } else { /* With -z, read the next NUL-terminated line */ - if (*next) - die("expected NUL but got: %s", next); - if (strbuf_getline(arg, stdin, '\0') == EOF) - return NULL; - next = arg->buf + arg->len; + if (**next) + die("expected NUL but got: %s", *next); + (*next)++; + if (*next == input->buf + input->len) + return -1; + strbuf_addstr(arg, *next); + *next += arg->len; } - return next; + return 0; } -static void parse_cmd_update(const char *next) + +/* + * The following five parse_cmd_*() functions parse the corresponding + * command. In each case, next points at the character following the + * command name and the following space. They each return a pointer + * to the character terminating the command, and die with an + * explanatory message if there are any parsing problems. All of + * these functions handle either text or binary format input, + * depending on how line_termination is set. + */ + +static const char *parse_cmd_update(struct strbuf *input, const char *next) { struct strbuf ref = STRBUF_INIT; struct strbuf newvalue = STRBUF_INIT; @@ -131,26 +157,28 @@ static void parse_cmd_update(const char *next) update = update_alloc(); - if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0]) + parse_first_arg(input, &next, &ref); + if (ref.buf[0]) update_store_ref_name(update, ref.buf); else die("update line missing "); - if ((next = parse_next_arg(next, &newvalue)) != NULL) + if (!parse_next_arg(input, &next, &newvalue)) update_store_new_sha1(update, newvalue.buf); else die("update %s missing ", ref.buf); - if ((next = parse_next_arg(next, &oldvalue)) != NULL) + if (!parse_next_arg(input, &next, &oldvalue)) { update_store_old_sha1(update, oldvalue.buf); - else if(!line_termination) + if (*next != line_termination) + die("update %s has extra input: %s", ref.buf, next); + } else if (!line_termination) die("update %s missing [] NUL", ref.buf); - if (next && *next) - die("update %s has extra input: %s", ref.buf, next); + return next; } -static void parse_cmd_create(const char *next) +static const char *parse_cmd_create(struct strbuf *input, const char *next) { struct strbuf ref = STRBUF_INIT; struct strbuf newvalue = STRBUF_INIT; @@ -158,23 +186,27 @@ static void parse_cmd_create(const char *next) update = update_alloc(); - if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0]) + parse_first_arg(input, &next, &ref); + if (ref.buf[0]) update_store_ref_name(update, ref.buf); else die("create line missing "); - if ((next = parse_next_arg(next, &newvalue)) != NULL) + if (!parse_next_arg(input, &next, &newvalue)) update_store_new_sha1(update, newvalue.buf); else die("create %s missing ", ref.buf); + if (is_null_sha1(update->new_sha1)) die("create %s given zero new value", ref.buf); - if (next && *next) + if (*next != line_termination) die("create %s has extra input: %s", ref.buf, next); + + return next; } -static void parse_cmd_delete(const char *next) +static const char *parse_cmd_delete(struct strbuf *input, const char *next) { struct strbuf ref = STRBUF_INIT; struct strbuf oldvalue = STRBUF_INIT; @@ -182,23 +214,26 @@ static void parse_cmd_delete(const char *next) update = update_alloc(); - if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0]) + parse_first_arg(input, &next, &ref); + if (ref.buf[0]) update_store_ref_name(update, ref.buf); else die("delete line missing "); - if ((next = parse_next_arg(next, &oldvalue)) != NULL) + if (!parse_next_arg(input, &next, &oldvalue)) { update_store_old_sha1(update, oldvalue.buf); - else if(!line_termination) + if (update->have_old && is_null_sha1(update->old_sha1)) + die("delete %s given zero old value", ref.buf); + } else if (!line_termination) die("delete %s missing [] NUL", ref.buf); - if (update->have_old && is_null_sha1(update->old_sha1)) - die("delete %s given zero old value", ref.buf); - if (next && *next) + if (*next != line_termination) die("delete %s has extra input: %s", ref.buf, next); + + return next; } -static void parse_cmd_verify(const char *next) +static const char *parse_cmd_verify(struct strbuf *input, const char *next) { struct strbuf ref = STRBUF_INIT; struct strbuf value = STRBUF_INIT; @@ -206,53 +241,64 @@ static void parse_cmd_verify(const char *next) update = update_alloc(); - if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0]) + parse_first_arg(input, &next, &ref); + if (ref.buf[0]) update_store_ref_name(update, ref.buf); else die("verify line missing "); - if ((next = parse_next_arg(next, &value)) != NULL) { + if (!parse_next_arg(input, &next, &value)) { update_store_old_sha1(update, value.buf); update_store_new_sha1(update, value.buf); - } else if(!line_termination) + } else if (!line_termination) die("verify %s missing [] NUL", ref.buf); - if (next && *next) + if (*next != line_termination) die("verify %s has extra input: %s", ref.buf, next); + + return next; } -static void parse_cmd_option(const char *next) +static const char *parse_cmd_option(struct strbuf *input, const char *next) { - if (!strcmp(next, "no-deref")) + if (!strncmp(next, "no-deref", 8) && next[8] == line_termination) update_flags |= REF_NODEREF; else die("option unknown: %s", next); + return next + 8; } static void update_refs_stdin(void) { - struct strbuf cmd = STRBUF_INIT; + struct strbuf input = STRBUF_INIT; + const char *next; + if (strbuf_read(&input, 0, 1000) < 0) + die_errno("could not read from stdin"); + next = input.buf; /* Read each line dispatch its command */ - while (strbuf_getline(&cmd, stdin, line_termination) != EOF) - if (!cmd.buf[0]) + while (next < input.buf + input.len) { + if (*next == line_termination) die("empty command in input"); - else if (isspace(*cmd.buf)) - die("whitespace before command: %s", cmd.buf); - else if (starts_with(cmd.buf, "update ")) - parse_cmd_update(cmd.buf + 7); - else if (starts_with(cmd.buf, "create ")) - parse_cmd_create(cmd.buf + 7); - else if (starts_with(cmd.buf, "delete ")) - parse_cmd_delete(cmd.buf + 7); - else if (starts_with(cmd.buf, "verify ")) - parse_cmd_verify(cmd.buf + 7); - else if (starts_with(cmd.buf, "option ")) - parse_cmd_option(cmd.buf + 7); + else if (isspace(*next)) + die("whitespace before command: %s", next); + else if (starts_with(next, "update ")) + next = parse_cmd_update(&input, next + 7); + else if (starts_with(next, "create ")) + next = parse_cmd_create(&input, next + 7); + else if (starts_with(next, "delete ")) + next = parse_cmd_delete(&input, next + 7); + else if (starts_with(next, "verify ")) + next = parse_cmd_verify(&input, next + 7); + else if (starts_with(next, "option ")) + next = parse_cmd_option(&input, next + 7); else - die("unknown command: %s", cmd.buf); + die("unknown command: %s", next); + + next++; + } - strbuf_release(&cmd); + strbuf_release(&input); } int cmd_update_ref(int argc, const char **argv, const char *prefix) From 2f57736002e6a774ce5ab53a15a631da8299f8b4 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:47:59 +0200 Subject: [PATCH 030/760] parse_cmd_verify(): copy old_sha1 instead of evaluating twice Aside from avoiding a tiny bit of work, this makes it transparently obvious that old_sha1 and new_sha1 are identical. It is arguably a bit silly to have to set new_sha1 in order to verify old_sha1, but that is a problem for another day. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 5f197fe2122e79..51adf2dafae1d6 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -249,7 +249,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next) if (!parse_next_arg(input, &next, &value)) { update_store_old_sha1(update, value.buf); - update_store_new_sha1(update, value.buf); + hashcpy(update->new_sha1, update->old_sha1); } else if (!line_termination) die("verify %s missing [] NUL", ref.buf); From ed410e611dc39dc7e845f27a660b76b7d0ecbab6 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:00 +0200 Subject: [PATCH 031/760] update-ref.c: extract a new function, parse_refname() There is no reason to obscure the fact that parse_first_arg() always parses refnames. Form the new function by combining parse_first_arg() and update_store_ref_name(). Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 90 ++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 51adf2dafae1d6..0dc2061c7ea8aa 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -35,14 +35,6 @@ static struct ref_update *update_alloc(void) return update; } -static void update_store_ref_name(struct ref_update *update, - const char *ref_name) -{ - if (check_refname_format(ref_name, REFNAME_ALLOW_ONELEVEL)) - die("invalid ref format: %s", ref_name); - update->ref_name = xstrdup(ref_name); -} - static void update_store_new_sha1(struct ref_update *update, const char *newvalue) { @@ -86,23 +78,35 @@ static const char *parse_arg(const char *next, struct strbuf *arg) } /* - * Parse the argument immediately after "command SP". If not -z, then - * handle C-quoting. Write the argument to arg. Set *next to point - * at the character that terminates the argument. Die if C-quoting is - * malformed. + * Parse the reference name immediately after "command SP". If not + * -z, then handle C-quoting. Return a pointer to a newly allocated + * string containing the name of the reference, or NULL if there was + * an error. Update *next to point at the character that terminates + * the argument. Die if C-quoting is malformed or the reference name + * is invalid. */ -static void parse_first_arg(struct strbuf *input, const char **next, - struct strbuf *arg) +static char *parse_refname(struct strbuf *input, const char **next) { - strbuf_reset(arg); + struct strbuf ref = STRBUF_INIT; + if (line_termination) { /* Without -z, use the next argument */ - *next = parse_arg(*next, arg); + *next = parse_arg(*next, &ref); } else { /* With -z, use everything up to the next NUL */ - strbuf_addstr(arg, *next); - *next += arg->len; + strbuf_addstr(&ref, *next); + *next += ref.len; + } + + if (!ref.len) { + strbuf_release(&ref); + return NULL; } + + if (check_refname_format(ref.buf, REFNAME_ALLOW_ONELEVEL)) + die("invalid ref format: %s", ref.buf); + + return strbuf_detach(&ref, NULL); } /* @@ -150,111 +154,99 @@ static int parse_next_arg(struct strbuf *input, const char **next, static const char *parse_cmd_update(struct strbuf *input, const char *next) { - struct strbuf ref = STRBUF_INIT; struct strbuf newvalue = STRBUF_INIT; struct strbuf oldvalue = STRBUF_INIT; struct ref_update *update; update = update_alloc(); - parse_first_arg(input, &next, &ref); - if (ref.buf[0]) - update_store_ref_name(update, ref.buf); - else + update->ref_name = parse_refname(input, &next); + if (!update->ref_name) die("update line missing "); if (!parse_next_arg(input, &next, &newvalue)) update_store_new_sha1(update, newvalue.buf); else - die("update %s missing ", ref.buf); + die("update %s missing ", update->ref_name); if (!parse_next_arg(input, &next, &oldvalue)) { update_store_old_sha1(update, oldvalue.buf); if (*next != line_termination) - die("update %s has extra input: %s", ref.buf, next); + die("update %s has extra input: %s", update->ref_name, next); } else if (!line_termination) - die("update %s missing [] NUL", ref.buf); + die("update %s missing [] NUL", update->ref_name); return next; } static const char *parse_cmd_create(struct strbuf *input, const char *next) { - struct strbuf ref = STRBUF_INIT; struct strbuf newvalue = STRBUF_INIT; struct ref_update *update; update = update_alloc(); - parse_first_arg(input, &next, &ref); - if (ref.buf[0]) - update_store_ref_name(update, ref.buf); - else + update->ref_name = parse_refname(input, &next); + if (!update->ref_name) die("create line missing "); if (!parse_next_arg(input, &next, &newvalue)) update_store_new_sha1(update, newvalue.buf); else - die("create %s missing ", ref.buf); + die("create %s missing ", update->ref_name); if (is_null_sha1(update->new_sha1)) - die("create %s given zero new value", ref.buf); + die("create %s given zero new value", update->ref_name); if (*next != line_termination) - die("create %s has extra input: %s", ref.buf, next); + die("create %s has extra input: %s", update->ref_name, next); return next; } static const char *parse_cmd_delete(struct strbuf *input, const char *next) { - struct strbuf ref = STRBUF_INIT; struct strbuf oldvalue = STRBUF_INIT; struct ref_update *update; update = update_alloc(); - parse_first_arg(input, &next, &ref); - if (ref.buf[0]) - update_store_ref_name(update, ref.buf); - else + update->ref_name = parse_refname(input, &next); + if (!update->ref_name) die("delete line missing "); if (!parse_next_arg(input, &next, &oldvalue)) { update_store_old_sha1(update, oldvalue.buf); if (update->have_old && is_null_sha1(update->old_sha1)) - die("delete %s given zero old value", ref.buf); + die("delete %s given zero old value", update->ref_name); } else if (!line_termination) - die("delete %s missing [] NUL", ref.buf); + die("delete %s missing [] NUL", update->ref_name); if (*next != line_termination) - die("delete %s has extra input: %s", ref.buf, next); + die("delete %s has extra input: %s", update->ref_name, next); return next; } static const char *parse_cmd_verify(struct strbuf *input, const char *next) { - struct strbuf ref = STRBUF_INIT; struct strbuf value = STRBUF_INIT; struct ref_update *update; update = update_alloc(); - parse_first_arg(input, &next, &ref); - if (ref.buf[0]) - update_store_ref_name(update, ref.buf); - else + update->ref_name = parse_refname(input, &next); + if (!update->ref_name) die("verify line missing "); if (!parse_next_arg(input, &next, &value)) { update_store_old_sha1(update, value.buf); hashcpy(update->new_sha1, update->old_sha1); } else if (!line_termination) - die("verify %s missing [] NUL", ref.buf); + die("verify %s missing [] NUL", update->ref_name); if (*next != line_termination) - die("verify %s has extra input: %s", ref.buf, next); + die("verify %s has extra input: %s", update->ref_name, next); return next; } From 1746ef4e9d869fb0f54194bb225604eb61a77501 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:01 +0200 Subject: [PATCH 032/760] update-ref --stdin: improve error messages for invalid values If an invalid value is passed to "update-ref --stdin" as or , include the command and the name of the reference at the beginning of the error message. Update the tests accordingly. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 24 +++++++++++++----------- t/t1400-update-ref.sh | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 0dc2061c7ea8aa..13a884a45ea944 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -35,20 +35,22 @@ static struct ref_update *update_alloc(void) return update; } -static void update_store_new_sha1(struct ref_update *update, +static void update_store_new_sha1(const char *command, + struct ref_update *update, const char *newvalue) { if (*newvalue && get_sha1(newvalue, update->new_sha1)) - die("invalid new value for ref %s: %s", - update->ref_name, newvalue); + die("%s %s: invalid new value: %s", + command, update->ref_name, newvalue); } -static void update_store_old_sha1(struct ref_update *update, +static void update_store_old_sha1(const char *command, + struct ref_update *update, const char *oldvalue) { if (*oldvalue && get_sha1(oldvalue, update->old_sha1)) - die("invalid old value for ref %s: %s", - update->ref_name, oldvalue); + die("%s %s: invalid old value: %s", + command, update->ref_name, oldvalue); /* We have an old value if non-empty, or if empty without -z */ update->have_old = *oldvalue || line_termination; @@ -165,12 +167,12 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next) die("update line missing "); if (!parse_next_arg(input, &next, &newvalue)) - update_store_new_sha1(update, newvalue.buf); + update_store_new_sha1("update", update, newvalue.buf); else die("update %s missing ", update->ref_name); if (!parse_next_arg(input, &next, &oldvalue)) { - update_store_old_sha1(update, oldvalue.buf); + update_store_old_sha1("update", update, oldvalue.buf); if (*next != line_termination) die("update %s has extra input: %s", update->ref_name, next); } else if (!line_termination) @@ -191,7 +193,7 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next) die("create line missing "); if (!parse_next_arg(input, &next, &newvalue)) - update_store_new_sha1(update, newvalue.buf); + update_store_new_sha1("create", update, newvalue.buf); else die("create %s missing ", update->ref_name); @@ -216,7 +218,7 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) die("delete line missing "); if (!parse_next_arg(input, &next, &oldvalue)) { - update_store_old_sha1(update, oldvalue.buf); + update_store_old_sha1("delete", update, oldvalue.buf); if (update->have_old && is_null_sha1(update->old_sha1)) die("delete %s given zero old value", update->ref_name); } else if (!line_termination) @@ -240,7 +242,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next) die("verify line missing "); if (!parse_next_arg(input, &next, &value)) { - update_store_old_sha1(update, value.buf); + update_store_old_sha1("verify", update, value.buf); hashcpy(update->new_sha1, update->old_sha1); } else if (!line_termination) die("verify %s missing [] NUL", update->ref_name); diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 00862bc28ee7d9..f6c6e960da1066 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -518,14 +518,14 @@ test_expect_success 'stdin update ref fails with wrong old value' ' test_expect_success 'stdin update ref fails with bad old value' ' echo "update $c $m does-not-exist" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: invalid old value for ref $c: does-not-exist" err && + grep "fatal: update $c: invalid old value: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin create ref fails with bad new value' ' echo "create $c does-not-exist" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: invalid new value for ref $c: does-not-exist" err && + grep "fatal: create $c: invalid new value: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' @@ -840,14 +840,14 @@ test_expect_success 'stdin -z update ref fails with wrong old value' ' test_expect_success 'stdin -z update ref fails with bad old value' ' printf $F "update $c" "$m" "does-not-exist" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: invalid old value for ref $c: does-not-exist" err && + grep "fatal: update $c: invalid old value: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin -z create ref fails with bad new value' ' printf $F "create $c" "does-not-exist" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: invalid new value for ref $c: does-not-exist" err && + grep "fatal: create $c: invalid new value: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' From 9255f059ff0bfce7605748f62f58d6ba9055a1f3 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:02 +0200 Subject: [PATCH 033/760] update-ref --stdin: make error messages more consistent The old error messages emitted for invalid input sometimes said ""/"" and sometimes said "old value"/"new value". Convert them all to the former. Update the tests accordingly. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 8 ++++---- t/t1400-update-ref.sh | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 13a884a45ea944..e4c0854e9fc58b 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -40,7 +40,7 @@ static void update_store_new_sha1(const char *command, const char *newvalue) { if (*newvalue && get_sha1(newvalue, update->new_sha1)) - die("%s %s: invalid new value: %s", + die("%s %s: invalid : %s", command, update->ref_name, newvalue); } @@ -49,7 +49,7 @@ static void update_store_old_sha1(const char *command, const char *oldvalue) { if (*oldvalue && get_sha1(oldvalue, update->old_sha1)) - die("%s %s: invalid old value: %s", + die("%s %s: invalid : %s", command, update->ref_name, oldvalue); /* We have an old value if non-empty, or if empty without -z */ @@ -198,7 +198,7 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next) die("create %s missing ", update->ref_name); if (is_null_sha1(update->new_sha1)) - die("create %s given zero new value", update->ref_name); + die("create %s given zero ", update->ref_name); if (*next != line_termination) die("create %s has extra input: %s", update->ref_name, next); @@ -220,7 +220,7 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) if (!parse_next_arg(input, &next, &oldvalue)) { update_store_old_sha1("delete", update, oldvalue.buf); if (update->have_old && is_null_sha1(update->old_sha1)) - die("delete %s given zero old value", update->ref_name); + die("delete %s given zero ", update->ref_name); } else if (!line_termination) die("delete %s missing [] NUL", update->ref_name); diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index f6c6e960da1066..ef61fe324bdd14 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -518,21 +518,21 @@ test_expect_success 'stdin update ref fails with wrong old value' ' test_expect_success 'stdin update ref fails with bad old value' ' echo "update $c $m does-not-exist" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: update $c: invalid old value: does-not-exist" err && + grep "fatal: update $c: invalid : does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin create ref fails with bad new value' ' echo "create $c does-not-exist" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: create $c: invalid new value: does-not-exist" err && + grep "fatal: create $c: invalid : does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin create ref fails with zero new value' ' echo "create $c " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: create $c given zero new value" err && + grep "fatal: create $c given zero " err && test_must_fail git rev-parse --verify -q $c ' @@ -556,7 +556,7 @@ test_expect_success 'stdin delete ref fails with wrong old value' ' test_expect_success 'stdin delete ref fails with zero old value' ' echo "delete $a " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: delete $a given zero old value" err && + grep "fatal: delete $a given zero " err && git rev-parse $m >expect && git rev-parse $a >actual && test_cmp expect actual @@ -840,14 +840,14 @@ test_expect_success 'stdin -z update ref fails with wrong old value' ' test_expect_success 'stdin -z update ref fails with bad old value' ' printf $F "update $c" "$m" "does-not-exist" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: update $c: invalid old value: does-not-exist" err && + grep "fatal: update $c: invalid : does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin -z create ref fails with bad new value' ' printf $F "create $c" "does-not-exist" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: create $c: invalid new value: does-not-exist" err && + grep "fatal: create $c: invalid : does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' @@ -878,7 +878,7 @@ test_expect_success 'stdin -z delete ref fails with wrong old value' ' test_expect_success 'stdin -z delete ref fails with zero old value' ' printf $F "delete $a" "$Z" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: delete $a given zero old value" err && + grep "fatal: delete $a given zero " err && git rev-parse $m >expect && git rev-parse $a >actual && test_cmp expect actual From ac1177553d8c632e93c507f8efc80b80e6c7d3d8 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:03 +0200 Subject: [PATCH 034/760] update-ref --stdin: simplify error messages for missing oldvalues Instead of, for example, fatal: update refs/heads/master missing [] NUL emit fatal: update refs/heads/master missing Update the tests accordingly. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 6 +++--- t/t1400-update-ref.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index e4c0854e9fc58b..a9eb5fe24d3efd 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -176,7 +176,7 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next) if (*next != line_termination) die("update %s has extra input: %s", update->ref_name, next); } else if (!line_termination) - die("update %s missing [] NUL", update->ref_name); + die("update %s missing ", update->ref_name); return next; } @@ -222,7 +222,7 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) if (update->have_old && is_null_sha1(update->old_sha1)) die("delete %s given zero ", update->ref_name); } else if (!line_termination) - die("delete %s missing [] NUL", update->ref_name); + die("delete %s missing ", update->ref_name); if (*next != line_termination) die("delete %s has extra input: %s", update->ref_name, next); @@ -245,7 +245,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next) update_store_old_sha1("verify", update, value.buf); hashcpy(update->new_sha1, update->old_sha1); } else if (!line_termination) - die("verify %s missing [] NUL", update->ref_name); + die("verify %s missing ", update->ref_name); if (*next != line_termination) die("verify %s has extra input: %s", update->ref_name, next); diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index ef61fe324bdd14..a2015d09773e8d 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -739,7 +739,7 @@ test_expect_success 'stdin -z fails update with no new value' ' test_expect_success 'stdin -z fails update with no old value' ' printf $F "update $a" "$m" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: update $a missing \\[\\] NUL" err + grep "fatal: update $a missing " err ' test_expect_success 'stdin -z fails update with too many arguments' ' @@ -763,7 +763,7 @@ test_expect_success 'stdin -z fails delete with bad ref name' ' test_expect_success 'stdin -z fails delete with no old value' ' printf $F "delete $a" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: delete $a missing \\[\\] NUL" err + grep "fatal: delete $a missing " err ' test_expect_success 'stdin -z fails delete with too many arguments' ' @@ -781,7 +781,7 @@ test_expect_success 'stdin -z fails verify with too many arguments' ' test_expect_success 'stdin -z fails verify with no old value' ' printf $F "verify $a" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: verify $a missing \\[\\] NUL" err + grep "fatal: verify $a missing " err ' test_expect_success 'stdin -z fails option with unknown name' ' From 191f241b528c10e242d045bde2cef70fb013a6e5 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:04 +0200 Subject: [PATCH 035/760] t1400: test that stdin -z update treats empty as zeros This is the (slightly inconsistent) status quo; make sure it doesn't change by accident. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index a2015d09773e8d..208f56e5181fa5 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -730,6 +730,13 @@ test_expect_success 'stdin -z fails update with bad ref name' ' grep "fatal: invalid ref format: ~a" err ' +test_expect_success 'stdin -z treats empty new value as zeros' ' + git update-ref $a $m && + printf $F "update $a" "" "" >stdin && + git update-ref -z --stdin stdin && test_must_fail git update-ref -z --stdin err && From 3afcc4637452100c68b469de7757dd2b45b4d29c Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:05 +0200 Subject: [PATCH 036/760] update-ref.c: extract a new function, parse_next_sha1() Replace three functions, update_store_new_sha1(), update_store_old_sha1(), and parse_next_arg(), with a single function, parse_next_sha1(). The new function takes care of a whole argument, including checking whether it is there, converting it to an SHA-1, and emitting errors on EOF or for invalid values. The return value indicates whether the argument was present or absent, which requires a bit of intelligence because absent values are represented differently depending on whether "-z" was used. The new interface means that the calling functions, parse_cmd_*(), don't have to interpret the result differently based on the line_termination mode that is in effect. It also means that parse_cmd_create() can distinguish unambiguously between an empty new value and a zeros new value, which fixes a failure in t1400. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 160 ++++++++++++++++++++++++++---------------- t/t1400-update-ref.sh | 2 +- 2 files changed, 99 insertions(+), 63 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index a9eb5fe24d3efd..c61120faf7680d 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -35,27 +35,6 @@ static struct ref_update *update_alloc(void) return update; } -static void update_store_new_sha1(const char *command, - struct ref_update *update, - const char *newvalue) -{ - if (*newvalue && get_sha1(newvalue, update->new_sha1)) - die("%s %s: invalid : %s", - command, update->ref_name, newvalue); -} - -static void update_store_old_sha1(const char *command, - struct ref_update *update, - const char *oldvalue) -{ - if (*oldvalue && get_sha1(oldvalue, update->old_sha1)) - die("%s %s: invalid : %s", - command, update->ref_name, oldvalue); - - /* We have an old value if non-empty, or if empty without -z */ - update->have_old = *oldvalue || line_termination; -} - /* * Parse one whitespace- or NUL-terminated, possibly C-quoted argument * and append the result to arg. Return a pointer to the terminator. @@ -112,35 +91,94 @@ static char *parse_refname(struct strbuf *input, const char **next) } /* - * Parse a SP/NUL separator followed by the next SP- or NUL-terminated - * argument, if any. If there is an argument, write it to arg, set - * *next to point at the character terminating the argument, and + * The value being parsed is (as opposed to ; the + * difference affects which error messages are generated): + */ +#define PARSE_SHA1_OLD 0x01 + +/* + * For backwards compatibility, accept an empty string for update's + * in binary mode to be equivalent to specifying zeros. + */ +#define PARSE_SHA1_ALLOW_EMPTY 0x02 + +/* + * Parse an argument separator followed by the next argument, if any. + * If there is an argument, convert it to a SHA-1, write it to sha1, + * set *next to point at the character terminating the argument, and * return 0. If there is no argument at all (not even the empty - * string), return a non-zero result and leave *next unchanged. + * string), return 1 and leave *next unchanged. If the value is + * provided but cannot be converted to a SHA-1, die. flags can + * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY. */ -static int parse_next_arg(struct strbuf *input, const char **next, - struct strbuf *arg) +static int parse_next_sha1(struct strbuf *input, const char **next, + unsigned char *sha1, + const char *command, const char *refname, + int flags) { - strbuf_reset(arg); + struct strbuf arg = STRBUF_INIT; + int ret = 0; + + if (*next == input->buf + input->len) + goto eof; + if (line_termination) { /* Without -z, consume SP and use next argument */ if (!**next || **next == line_termination) - return -1; + return 1; if (**next != ' ') - die("expected SP but got: %s", *next); + die("%s %s: expected SP but got: %s", + command, refname, *next); (*next)++; - *next = parse_arg(*next, arg); + *next = parse_arg(*next, &arg); + if (arg.len) { + if (get_sha1(arg.buf, sha1)) + goto invalid; + } else { + /* Without -z, an empty value means all zeros: */ + hashclr(sha1); + } } else { /* With -z, read the next NUL-terminated line */ if (**next) - die("expected NUL but got: %s", *next); + die("%s %s: expected NUL but got: %s", + command, refname, *next); (*next)++; if (*next == input->buf + input->len) - return -1; - strbuf_addstr(arg, *next); - *next += arg->len; + goto eof; + strbuf_addstr(&arg, *next); + *next += arg.len; + + if (arg.len) { + if (get_sha1(arg.buf, sha1)) + goto invalid; + } else if (flags & PARSE_SHA1_ALLOW_EMPTY) { + /* With -z, treat an empty value as all zeros: */ + hashclr(sha1); + } else { + /* + * With -z, an empty non-required value means + * unspecified: + */ + ret = 1; + } } - return 0; + + strbuf_release(&arg); + + return ret; + + invalid: + die(flags & PARSE_SHA1_OLD ? + "%s %s: invalid : %s" : + "%s %s: invalid : %s", + command, refname, arg.buf); + + eof: + die(flags & PARSE_SHA1_OLD ? + "%s %s missing " : + "%s %s missing ", + command, refname); } @@ -156,8 +194,6 @@ static int parse_next_arg(struct strbuf *input, const char **next, static const char *parse_cmd_update(struct strbuf *input, const char *next) { - struct strbuf newvalue = STRBUF_INIT; - struct strbuf oldvalue = STRBUF_INIT; struct ref_update *update; update = update_alloc(); @@ -166,24 +202,23 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next) if (!update->ref_name) die("update line missing "); - if (!parse_next_arg(input, &next, &newvalue)) - update_store_new_sha1("update", update, newvalue.buf); - else + if (parse_next_sha1(input, &next, update->new_sha1, + "update", update->ref_name, + PARSE_SHA1_ALLOW_EMPTY)) die("update %s missing ", update->ref_name); - if (!parse_next_arg(input, &next, &oldvalue)) { - update_store_old_sha1("update", update, oldvalue.buf); - if (*next != line_termination) - die("update %s has extra input: %s", update->ref_name, next); - } else if (!line_termination) - die("update %s missing ", update->ref_name); + update->have_old = !parse_next_sha1(input, &next, update->old_sha1, + "update", update->ref_name, + PARSE_SHA1_OLD); + + if (*next != line_termination) + die("update %s has extra input: %s", update->ref_name, next); return next; } static const char *parse_cmd_create(struct strbuf *input, const char *next) { - struct strbuf newvalue = STRBUF_INIT; struct ref_update *update; update = update_alloc(); @@ -192,9 +227,8 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next) if (!update->ref_name) die("create line missing "); - if (!parse_next_arg(input, &next, &newvalue)) - update_store_new_sha1("create", update, newvalue.buf); - else + if (parse_next_sha1(input, &next, update->new_sha1, + "create", update->ref_name, 0)) die("create %s missing ", update->ref_name); if (is_null_sha1(update->new_sha1)) @@ -208,7 +242,6 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next) static const char *parse_cmd_delete(struct strbuf *input, const char *next) { - struct strbuf oldvalue = STRBUF_INIT; struct ref_update *update; update = update_alloc(); @@ -217,12 +250,14 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) if (!update->ref_name) die("delete line missing "); - if (!parse_next_arg(input, &next, &oldvalue)) { - update_store_old_sha1("delete", update, oldvalue.buf); - if (update->have_old && is_null_sha1(update->old_sha1)) + if (parse_next_sha1(input, &next, update->old_sha1, + "delete", update->ref_name, PARSE_SHA1_OLD)) { + update->have_old = 0; + } else { + if (is_null_sha1(update->old_sha1)) die("delete %s given zero ", update->ref_name); - } else if (!line_termination) - die("delete %s missing ", update->ref_name); + update->have_old = 1; + } if (*next != line_termination) die("delete %s has extra input: %s", update->ref_name, next); @@ -232,7 +267,6 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) static const char *parse_cmd_verify(struct strbuf *input, const char *next) { - struct strbuf value = STRBUF_INIT; struct ref_update *update; update = update_alloc(); @@ -241,11 +275,13 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next) if (!update->ref_name) die("verify line missing "); - if (!parse_next_arg(input, &next, &value)) { - update_store_old_sha1("verify", update, value.buf); + if (parse_next_sha1(input, &next, update->old_sha1, + "verify", update->ref_name, PARSE_SHA1_OLD)) { + update->have_old = 0; + } else { hashcpy(update->new_sha1, update->old_sha1); - } else if (!line_termination) - die("verify %s missing ", update->ref_name); + update->have_old = 1; + } if (*next != line_termination) die("verify %s has extra input: %s", update->ref_name, next); diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 208f56e5181fa5..15f5bfd1682b16 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -858,7 +858,7 @@ test_expect_success 'stdin -z create ref fails with bad new value' ' test_must_fail git rev-parse --verify -q $c ' -test_expect_failure 'stdin -z create ref fails with empty new value' ' +test_expect_success 'stdin -z create ref fails with empty new value' ' printf $F "create $c" "" >stdin && test_must_fail git update-ref -z --stdin err && grep "fatal: create $c missing " err && From 1fbd504942b20a541ba4fcbe90d3ea21b03717e4 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:06 +0200 Subject: [PATCH 037/760] update-ref --stdin -z: deprecate interpreting the empty string as zeros In the original version of this command, for the single case of the "update" command's , the empty string was interpreted as being equivalent to 40 "0"s. This shorthand is unnecessary (binary input will usually be generated programmatically anyway), and it complicates the parser and the documentation. So gently deprecate this usage: remove its description from the documentation and emit a warning if it is found. But for reasons of backwards compatibility, continue to accept it. Helped-by: Brad King Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- Documentation/git-update-ref.txt | 18 ++++++++++++------ builtin/update-ref.c | 2 ++ t/t1400-update-ref.sh | 5 +++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Documentation/git-update-ref.txt b/Documentation/git-update-ref.txt index 0a0a5512b3c62e..c8f5ae5cb36227 100644 --- a/Documentation/git-update-ref.txt +++ b/Documentation/git-update-ref.txt @@ -68,7 +68,12 @@ performs all modifications together. Specify commands of the form: option SP LF Quote fields containing whitespace as if they were strings in C source -code. Alternatively, use `-z` to specify commands without quoting: +code; i.e., surrounded by double-quotes and with backslash escapes. +Use 40 "0" characters or the empty string to specify a zero value. To +specify a missing value, omit the value and its preceding SP entirely. + +Alternatively, use `-z` to specify in NUL-terminated format, without +quoting: update SP NUL NUL [] NUL create SP NUL NUL @@ -76,8 +81,12 @@ code. Alternatively, use `-z` to specify commands without quoting: verify SP NUL [] NUL option SP NUL -Lines of any other format or a repeated produce an error. -Command meanings are: +In this format, use 40 "0" to specify a zero value, and use the empty +string to specify a missing value. + +In either format, values can be specified in any form that Git +recognizes as an object name. Commands in any other format or a +repeated produce an error. Command meanings are: update:: Set to after verifying , if given. @@ -102,9 +111,6 @@ option:: The only valid option is `no-deref` to avoid dereferencing a symbolic ref. -Use 40 "0" or the empty string to specify a zero value, except that -with `-z` an empty is considered missing. - If all s can be locked with matching s simultaneously, all modifications are performed. Otherwise, no modifications are performed. Note that while each individual diff --git a/builtin/update-ref.c b/builtin/update-ref.c index c61120faf7680d..6f3b9095cfff48 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -154,6 +154,8 @@ static int parse_next_sha1(struct strbuf *input, const char **next, goto invalid; } else if (flags & PARSE_SHA1_ALLOW_EMPTY) { /* With -z, treat an empty value as all zeros: */ + warning("%s %s: missing , treating as zero", + command, refname); hashclr(sha1); } else { /* diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 15f5bfd1682b16..2d61cceb4c4b53 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -730,10 +730,11 @@ test_expect_success 'stdin -z fails update with bad ref name' ' grep "fatal: invalid ref format: ~a" err ' -test_expect_success 'stdin -z treats empty new value as zeros' ' +test_expect_success 'stdin -z emits warning with empty new value' ' git update-ref $a $m && printf $F "update $a" "" "" >stdin && - git update-ref -z --stdin err && + grep "warning: update $a: missing , treating as zero" err && test_must_fail git rev-parse --verify -q $a ' From ff6ee39525244b7c1bca1953743fdcc14605a031 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:07 +0200 Subject: [PATCH 038/760] t1400: test one mistake at a time This case wants to test passing a bad refname to the "update" command. But it also passes too few arguments to "update", which muddles the situation: which error should be diagnosed? So split this test into two: * One that passes too few arguments to update * One that passes all three arguments to "update", but with a bad refname. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 2d61cceb4c4b53..6b21e459e6f4a9 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -724,8 +724,14 @@ test_expect_success 'stdin -z fails update with no ref' ' grep "fatal: update line missing " err ' +test_expect_success 'stdin -z fails update with too few args' ' + printf $F "update $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin err && + grep "fatal: update $a missing " err +' + test_expect_success 'stdin -z fails update with bad ref name' ' - printf $F "update ~a" "$m" >stdin && + printf $F "update ~a" "$m" "" >stdin && test_must_fail git update-ref -z --stdin err && grep "fatal: invalid ref format: ~a" err ' From 726f69166ff0ac3fef0a9a0241f09a7d9f0fa48f Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:08 +0200 Subject: [PATCH 039/760] update-ref --stdin: improve the error message for unexpected EOF Distinguish this error from the error that an argument is missing for another reason. Update the tests accordingly. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 4 ++-- t/t1400-update-ref.sh | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 6f3b9095cfff48..0d5f1d076ab0d5 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -178,8 +178,8 @@ static int parse_next_sha1(struct strbuf *input, const char **next, eof: die(flags & PARSE_SHA1_OLD ? - "%s %s missing " : - "%s %s missing ", + "%s %s: unexpected end of input when reading " : + "%s %s: unexpected end of input when reading ", command, refname); } diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 6b21e459e6f4a9..1db0689548773f 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -709,7 +709,7 @@ test_expect_success 'stdin -z fails create with bad ref name' ' test_expect_success 'stdin -z fails create with no new value' ' printf $F "create $a" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: create $a missing " err + grep "fatal: create $a: unexpected end of input when reading " err ' test_expect_success 'stdin -z fails create with too many arguments' ' @@ -727,7 +727,7 @@ test_expect_success 'stdin -z fails update with no ref' ' test_expect_success 'stdin -z fails update with too few args' ' printf $F "update $a" "$m" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: update $a missing " err + grep "fatal: update $a: unexpected end of input when reading " err ' test_expect_success 'stdin -z fails update with bad ref name' ' @@ -747,13 +747,13 @@ test_expect_success 'stdin -z emits warning with empty new value' ' test_expect_success 'stdin -z fails update with no new value' ' printf $F "update $a" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: update $a missing " err + grep "fatal: update $a: unexpected end of input when reading " err ' test_expect_success 'stdin -z fails update with no old value' ' printf $F "update $a" "$m" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: update $a missing " err + grep "fatal: update $a: unexpected end of input when reading " err ' test_expect_success 'stdin -z fails update with too many arguments' ' @@ -777,7 +777,7 @@ test_expect_success 'stdin -z fails delete with bad ref name' ' test_expect_success 'stdin -z fails delete with no old value' ' printf $F "delete $a" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: delete $a missing " err + grep "fatal: delete $a: unexpected end of input when reading " err ' test_expect_success 'stdin -z fails delete with too many arguments' ' @@ -795,7 +795,7 @@ test_expect_success 'stdin -z fails verify with too many arguments' ' test_expect_success 'stdin -z fails verify with no old value' ' printf $F "verify $a" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: verify $a missing " err + grep "fatal: verify $a: unexpected end of input when reading " err ' test_expect_success 'stdin -z fails option with unknown name' ' From f11b09fb60556954c6a222f4809631470c81cae6 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:09 +0200 Subject: [PATCH 040/760] update-ref --stdin: harmonize error messages Make (most of) the error messages for invalid input have the same format [1]: $COMMAND [SP $REFNAME]: $MESSAGE Update the tests accordingly. [1] A few error messages are left with their old form, because $COMMAND and $REFNAME aren't passed all the way down the call stack. Maybe those sites should be changed some day, too. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 24 ++++++++++++------------ t/t1400-update-ref.sh | 32 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 0d5f1d076ab0d5..423c5c30c71928 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -202,19 +202,19 @@ static const char *parse_cmd_update(struct strbuf *input, const char *next) update->ref_name = parse_refname(input, &next); if (!update->ref_name) - die("update line missing "); + die("update: missing "); if (parse_next_sha1(input, &next, update->new_sha1, "update", update->ref_name, PARSE_SHA1_ALLOW_EMPTY)) - die("update %s missing ", update->ref_name); + die("update %s: missing ", update->ref_name); update->have_old = !parse_next_sha1(input, &next, update->old_sha1, "update", update->ref_name, PARSE_SHA1_OLD); if (*next != line_termination) - die("update %s has extra input: %s", update->ref_name, next); + die("update %s: extra input: %s", update->ref_name, next); return next; } @@ -227,17 +227,17 @@ static const char *parse_cmd_create(struct strbuf *input, const char *next) update->ref_name = parse_refname(input, &next); if (!update->ref_name) - die("create line missing "); + die("create: missing "); if (parse_next_sha1(input, &next, update->new_sha1, "create", update->ref_name, 0)) - die("create %s missing ", update->ref_name); + die("create %s: missing ", update->ref_name); if (is_null_sha1(update->new_sha1)) - die("create %s given zero ", update->ref_name); + die("create %s: zero ", update->ref_name); if (*next != line_termination) - die("create %s has extra input: %s", update->ref_name, next); + die("create %s: extra input: %s", update->ref_name, next); return next; } @@ -250,19 +250,19 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) update->ref_name = parse_refname(input, &next); if (!update->ref_name) - die("delete line missing "); + die("delete: missing "); if (parse_next_sha1(input, &next, update->old_sha1, "delete", update->ref_name, PARSE_SHA1_OLD)) { update->have_old = 0; } else { if (is_null_sha1(update->old_sha1)) - die("delete %s given zero ", update->ref_name); + die("delete %s: zero ", update->ref_name); update->have_old = 1; } if (*next != line_termination) - die("delete %s has extra input: %s", update->ref_name, next); + die("delete %s: extra input: %s", update->ref_name, next); return next; } @@ -275,7 +275,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next) update->ref_name = parse_refname(input, &next); if (!update->ref_name) - die("verify line missing "); + die("verify: missing "); if (parse_next_sha1(input, &next, update->old_sha1, "verify", update->ref_name, PARSE_SHA1_OLD)) { @@ -286,7 +286,7 @@ static const char *parse_cmd_verify(struct strbuf *input, const char *next) } if (*next != line_termination) - die("verify %s has extra input: %s", update->ref_name, next); + die("verify %s: extra input: %s", update->ref_name, next); return next; } diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 1db0689548773f..48ccc4d6355c1f 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -371,7 +371,7 @@ test_expect_success 'stdin fails on junk after quoted argument' ' test_expect_success 'stdin fails create with no ref' ' echo "create " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: create line missing " err + grep "fatal: create: missing " err ' test_expect_success 'stdin fails create with bad ref name' ' @@ -383,19 +383,19 @@ test_expect_success 'stdin fails create with bad ref name' ' test_expect_success 'stdin fails create with no new value' ' echo "create $a" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: create $a missing " err + grep "fatal: create $a: missing " err ' test_expect_success 'stdin fails create with too many arguments' ' echo "create $a $m $m" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: create $a has extra input: $m" err + grep "fatal: create $a: extra input: $m" err ' test_expect_success 'stdin fails update with no ref' ' echo "update " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: update line missing " err + grep "fatal: update: missing " err ' test_expect_success 'stdin fails update with bad ref name' ' @@ -407,19 +407,19 @@ test_expect_success 'stdin fails update with bad ref name' ' test_expect_success 'stdin fails update with no new value' ' echo "update $a" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: update $a missing " err + grep "fatal: update $a: missing " err ' test_expect_success 'stdin fails update with too many arguments' ' echo "update $a $m $m $m" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: update $a has extra input: $m" err + grep "fatal: update $a: extra input: $m" err ' test_expect_success 'stdin fails delete with no ref' ' echo "delete " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: delete line missing " err + grep "fatal: delete: missing " err ' test_expect_success 'stdin fails delete with bad ref name' ' @@ -431,13 +431,13 @@ test_expect_success 'stdin fails delete with bad ref name' ' test_expect_success 'stdin fails delete with too many arguments' ' echo "delete $a $m $m" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: delete $a has extra input: $m" err + grep "fatal: delete $a: extra input: $m" err ' test_expect_success 'stdin fails verify with too many arguments' ' echo "verify $a $m $m" >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: verify $a has extra input: $m" err + grep "fatal: verify $a: extra input: $m" err ' test_expect_success 'stdin fails option with unknown name' ' @@ -532,7 +532,7 @@ test_expect_success 'stdin create ref fails with bad new value' ' test_expect_success 'stdin create ref fails with zero new value' ' echo "create $c " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: create $c given zero " err && + grep "fatal: create $c: zero " err && test_must_fail git rev-parse --verify -q $c ' @@ -556,7 +556,7 @@ test_expect_success 'stdin delete ref fails with wrong old value' ' test_expect_success 'stdin delete ref fails with zero old value' ' echo "delete $a " >stdin && test_must_fail git update-ref --stdin err && - grep "fatal: delete $a given zero " err && + grep "fatal: delete $a: zero " err && git rev-parse $m >expect && git rev-parse $a >actual && test_cmp expect actual @@ -697,7 +697,7 @@ test_expect_success 'stdin -z fails on unknown command' ' test_expect_success 'stdin -z fails create with no ref' ' printf $F "create " >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: create line missing " err + grep "fatal: create: missing " err ' test_expect_success 'stdin -z fails create with bad ref name' ' @@ -721,7 +721,7 @@ test_expect_success 'stdin -z fails create with too many arguments' ' test_expect_success 'stdin -z fails update with no ref' ' printf $F "update " >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: update line missing " err + grep "fatal: update: missing " err ' test_expect_success 'stdin -z fails update with too few args' ' @@ -765,7 +765,7 @@ test_expect_success 'stdin -z fails update with too many arguments' ' test_expect_success 'stdin -z fails delete with no ref' ' printf $F "delete " >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: delete line missing " err + grep "fatal: delete: missing " err ' test_expect_success 'stdin -z fails delete with bad ref name' ' @@ -868,7 +868,7 @@ test_expect_success 'stdin -z create ref fails with bad new value' ' test_expect_success 'stdin -z create ref fails with empty new value' ' printf $F "create $c" "" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: create $c missing " err && + grep "fatal: create $c: missing " err && test_must_fail git rev-parse --verify -q $c ' @@ -892,7 +892,7 @@ test_expect_success 'stdin -z delete ref fails with wrong old value' ' test_expect_success 'stdin -z delete ref fails with zero old value' ' printf $F "delete $a" "$Z" >stdin && test_must_fail git update-ref -z --stdin err && - grep "fatal: delete $a given zero " err && + grep "fatal: delete $a: zero " err && git rev-parse $m >expect && git rev-parse $a >actual && test_cmp expect actual From caa4046c4f480ceae5afb20e3172a437865cc51f Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:10 +0200 Subject: [PATCH 041/760] refs: add a concept of a reference transaction Build out the API for dealing with a bunch of reference checks and changes within a transaction. Define an opaque ref_transaction type that is managed entirely within refs.c. Introduce functions for beginning a transaction, adding updates to a transaction, and committing/rolling back a transaction. This API will soon replace update_refs(). Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ refs.h | 65 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) diff --git a/refs.c b/refs.c index 1305eb1fcff6d9..f0b5764b34d7eb 100644 --- a/refs.c +++ b/refs.c @@ -3267,6 +3267,96 @@ static int update_ref_write(const char *action, const char *refname, return 0; } +/* + * Data structure for holding a reference transaction, which can + * consist of checks and updates to multiple references, carried out + * as atomically as possible. This structure is opaque to callers. + */ +struct ref_transaction { + struct ref_update **updates; + size_t alloc; + size_t nr; +}; + +struct ref_transaction *ref_transaction_begin(void) +{ + return xcalloc(1, sizeof(struct ref_transaction)); +} + +static void ref_transaction_free(struct ref_transaction *transaction) +{ + int i; + + for (i = 0; i < transaction->nr; i++) { + struct ref_update *update = transaction->updates[i]; + + free((char *)update->ref_name); + free(update); + } + + free(transaction->updates); + free(transaction); +} + +void ref_transaction_rollback(struct ref_transaction *transaction) +{ + ref_transaction_free(transaction); +} + +static struct ref_update *add_update(struct ref_transaction *transaction, + const char *refname) +{ + struct ref_update *update = xcalloc(1, sizeof(*update)); + + update->ref_name = xstrdup(refname); + ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc); + transaction->updates[transaction->nr++] = update; + return update; +} + +void ref_transaction_update(struct ref_transaction *transaction, + const char *refname, + unsigned char *new_sha1, unsigned char *old_sha1, + int flags, int have_old) +{ + struct ref_update *update = add_update(transaction, refname); + + hashcpy(update->new_sha1, new_sha1); + update->flags = flags; + update->have_old = have_old; + if (have_old) + hashcpy(update->old_sha1, old_sha1); +} + +void ref_transaction_create(struct ref_transaction *transaction, + const char *refname, + unsigned char *new_sha1, + int flags) +{ + struct ref_update *update = add_update(transaction, refname); + + assert(!is_null_sha1(new_sha1)); + hashcpy(update->new_sha1, new_sha1); + hashclr(update->old_sha1); + update->flags = flags; + update->have_old = 1; +} + +void ref_transaction_delete(struct ref_transaction *transaction, + const char *refname, + unsigned char *old_sha1, + int flags, int have_old) +{ + struct ref_update *update = add_update(transaction, refname); + + update->flags = flags; + update->have_old = have_old; + if (have_old) { + assert(!is_null_sha1(old_sha1)); + hashcpy(update->old_sha1, old_sha1); + } +} + int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr) @@ -3378,6 +3468,15 @@ int update_refs(const char *action, struct ref_update * const *updates_orig, return ret; } +int ref_transaction_commit(struct ref_transaction *transaction, + const char *msg, enum action_on_err onerr) +{ + int ret = update_refs(msg, transaction->updates, transaction->nr, + onerr); + ref_transaction_free(transaction); + return ret; +} + char *shorten_unambiguous_ref(const char *refname, int strict) { int i; diff --git a/refs.h b/refs.h index 08e60ac07f2611..0518dd5203e09f 100644 --- a/refs.h +++ b/refs.h @@ -24,6 +24,8 @@ struct ref_update { int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ }; +struct ref_transaction; + /* * Bit values set in the flags argument passed to each_ref_fn(): */ @@ -220,6 +222,69 @@ enum action_on_err { UPDATE_REFS_QUIET_ON_ERR }; +/* + * Begin a reference transaction. The reference transaction must + * eventually be commited using ref_transaction_commit() or rolled + * back using ref_transaction_rollback(). + */ +struct ref_transaction *ref_transaction_begin(void); + +/* + * Roll back a ref_transaction and free all associated data. + */ +void ref_transaction_rollback(struct ref_transaction *transaction); + + +/* + * The following functions add a reference check or update to a + * ref_transaction. In all of them, refname is the name of the + * reference to be affected. The functions make internal copies of + * refname, so the caller retains ownership of the parameter. flags + * can be REF_NODEREF; it is passed to update_ref_lock(). + */ + + +/* + * Add a reference update to transaction. new_sha1 is the value that + * the reference should have after the update, or zeros if it should + * be deleted. If have_old is true, then old_sha1 holds the value + * that the reference should have had before the update, or zeros if + * it must not have existed beforehand. + */ +void ref_transaction_update(struct ref_transaction *transaction, + const char *refname, + unsigned char *new_sha1, unsigned char *old_sha1, + int flags, int have_old); + +/* + * Add a reference creation to transaction. new_sha1 is the value + * that the reference should have after the update; it must not be the + * null SHA-1. It is verified that the reference does not exist + * already. + */ +void ref_transaction_create(struct ref_transaction *transaction, + const char *refname, + unsigned char *new_sha1, + int flags); + +/* + * Add a reference deletion to transaction. If have_old is true, then + * old_sha1 holds the value that the reference should have had before + * the update (which must not be the null SHA-1). + */ +void ref_transaction_delete(struct ref_transaction *transaction, + const char *refname, + unsigned char *old_sha1, + int flags, int have_old); + +/* + * Commit all of the changes that have been queued in transaction, as + * atomically as possible. Return a nonzero value if there is a + * problem. The ref_transaction is freed by this function. + */ +int ref_transaction_commit(struct ref_transaction *transaction, + const char *msg, enum action_on_err onerr); + /** Lock a ref and then write its file */ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, From aebfc13337e503b5a7d064cb1e9c9916f24c2baf Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:11 +0200 Subject: [PATCH 042/760] update-ref --stdin: reimplement using reference transactions This change is mostly clerical: the parse_cmd_*() functions need to use local variables rather than a struct ref_update to collect the arguments needed for each update, and then call ref_transaction_*() to queue the change rather than building up the list of changes at the caller side. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/update-ref.c | 142 +++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 67 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 423c5c30c71928..405267f6e2776b 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -12,29 +12,11 @@ static const char * const git_update_ref_usage[] = { NULL }; -static int updates_alloc; -static int updates_count; -static struct ref_update **updates; +static struct ref_transaction *transaction; static char line_termination = '\n'; static int update_flags; -static struct ref_update *update_alloc(void) -{ - struct ref_update *update; - - /* Allocate and zero-init a struct ref_update */ - update = xcalloc(1, sizeof(*update)); - ALLOC_GROW(updates, updates_count + 1, updates_alloc); - updates[updates_count++] = update; - - /* Store and reset accumulated options */ - update->flags = update_flags; - update_flags = 0; - - return update; -} - /* * Parse one whitespace- or NUL-terminated, possibly C-quoted argument * and append the result to arg. Return a pointer to the terminator. @@ -196,97 +178,119 @@ static int parse_next_sha1(struct strbuf *input, const char **next, static const char *parse_cmd_update(struct strbuf *input, const char *next) { - struct ref_update *update; - - update = update_alloc(); + char *refname; + unsigned char new_sha1[20]; + unsigned char old_sha1[20]; + int have_old; - update->ref_name = parse_refname(input, &next); - if (!update->ref_name) + refname = parse_refname(input, &next); + if (!refname) die("update: missing "); - if (parse_next_sha1(input, &next, update->new_sha1, - "update", update->ref_name, + if (parse_next_sha1(input, &next, new_sha1, "update", refname, PARSE_SHA1_ALLOW_EMPTY)) - die("update %s: missing ", update->ref_name); + die("update %s: missing ", refname); - update->have_old = !parse_next_sha1(input, &next, update->old_sha1, - "update", update->ref_name, - PARSE_SHA1_OLD); + have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname, + PARSE_SHA1_OLD); if (*next != line_termination) - die("update %s: extra input: %s", update->ref_name, next); + die("update %s: extra input: %s", refname, next); + + ref_transaction_update(transaction, refname, new_sha1, old_sha1, + update_flags, have_old); + + update_flags = 0; + free(refname); return next; } static const char *parse_cmd_create(struct strbuf *input, const char *next) { - struct ref_update *update; - - update = update_alloc(); + char *refname; + unsigned char new_sha1[20]; - update->ref_name = parse_refname(input, &next); - if (!update->ref_name) + refname = parse_refname(input, &next); + if (!refname) die("create: missing "); - if (parse_next_sha1(input, &next, update->new_sha1, - "create", update->ref_name, 0)) - die("create %s: missing ", update->ref_name); + if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0)) + die("create %s: missing ", refname); - if (is_null_sha1(update->new_sha1)) - die("create %s: zero ", update->ref_name); + if (is_null_sha1(new_sha1)) + die("create %s: zero ", refname); if (*next != line_termination) - die("create %s: extra input: %s", update->ref_name, next); + die("create %s: extra input: %s", refname, next); + + ref_transaction_create(transaction, refname, new_sha1, update_flags); + + update_flags = 0; + free(refname); return next; } static const char *parse_cmd_delete(struct strbuf *input, const char *next) { - struct ref_update *update; + char *refname; + unsigned char old_sha1[20]; + int have_old; - update = update_alloc(); - - update->ref_name = parse_refname(input, &next); - if (!update->ref_name) + refname = parse_refname(input, &next); + if (!refname) die("delete: missing "); - if (parse_next_sha1(input, &next, update->old_sha1, - "delete", update->ref_name, PARSE_SHA1_OLD)) { - update->have_old = 0; + if (parse_next_sha1(input, &next, old_sha1, "delete", refname, + PARSE_SHA1_OLD)) { + have_old = 0; } else { - if (is_null_sha1(update->old_sha1)) - die("delete %s: zero ", update->ref_name); - update->have_old = 1; + if (is_null_sha1(old_sha1)) + die("delete %s: zero ", refname); + have_old = 1; } if (*next != line_termination) - die("delete %s: extra input: %s", update->ref_name, next); + die("delete %s: extra input: %s", refname, next); + + ref_transaction_delete(transaction, refname, old_sha1, + update_flags, have_old); + + update_flags = 0; + free(refname); return next; } static const char *parse_cmd_verify(struct strbuf *input, const char *next) { - struct ref_update *update; - - update = update_alloc(); + char *refname; + unsigned char new_sha1[20]; + unsigned char old_sha1[20]; + int have_old; - update->ref_name = parse_refname(input, &next); - if (!update->ref_name) + refname = parse_refname(input, &next); + if (!refname) die("verify: missing "); - if (parse_next_sha1(input, &next, update->old_sha1, - "verify", update->ref_name, PARSE_SHA1_OLD)) { - update->have_old = 0; + if (parse_next_sha1(input, &next, old_sha1, "verify", refname, + PARSE_SHA1_OLD)) { + hashclr(new_sha1); + have_old = 0; } else { - hashcpy(update->new_sha1, update->old_sha1); - update->have_old = 1; + hashcpy(new_sha1, old_sha1); + have_old = 1; } if (*next != line_termination) - die("verify %s: extra input: %s", update->ref_name, next); + die("verify %s: extra input: %s", refname, next); + + ref_transaction_update(transaction, refname, new_sha1, old_sha1, + update_flags, have_old); + + update_flags = 0; + free(refname); return next; } @@ -355,13 +359,17 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) die("Refusing to perform update with empty message."); if (read_stdin) { + int ret; + transaction = ref_transaction_begin(); + if (delete || no_deref || argc > 0) usage_with_options(git_update_ref_usage, options); if (end_null) line_termination = '\0'; update_refs_stdin(); - return update_refs(msg, updates, updates_count, - UPDATE_REFS_DIE_ON_ERR); + ret = ref_transaction_commit(transaction, msg, + UPDATE_REFS_DIE_ON_ERR); + return ret; } if (end_null) From b5c8ea2afb9bea910f0db5f9a4dfe58471184b3d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:12 +0200 Subject: [PATCH 043/760] refs: remove API function update_refs() It has been superseded by reference transactions. This also means that struct ref_update can become private. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 33 ++++++++++++++++++++------------- refs.h | 20 -------------------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/refs.c b/refs.c index f0b5764b34d7eb..6984ff0aff994a 100644 --- a/refs.c +++ b/refs.c @@ -3267,6 +3267,20 @@ static int update_ref_write(const char *action, const char *refname, return 0; } +/** + * Information needed for a single ref update. Set new_sha1 to the + * new value or to zero to delete the ref. To check the old value + * while locking the ref, set have_old to 1 and set old_sha1 to the + * value or to zero to ensure the ref does not exist before update. + */ +struct ref_update { + const char *ref_name; + unsigned char new_sha1[20]; + unsigned char old_sha1[20]; + int flags; /* REF_NODEREF? */ + int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ +}; + /* * Data structure for holding a reference transaction, which can * consist of checks and updates to multiple references, carried out @@ -3396,16 +3410,17 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, return 0; } -int update_refs(const char *action, struct ref_update * const *updates_orig, - int n, enum action_on_err onerr) +int ref_transaction_commit(struct ref_transaction *transaction, + const char *msg, enum action_on_err onerr) { int ret = 0, delnum = 0, i; struct ref_update **updates; int *types; struct ref_lock **locks; const char **delnames; + int n = transaction->nr; - if (!updates_orig || !n) + if (!n) return 0; /* Allocate work space */ @@ -3415,7 +3430,7 @@ int update_refs(const char *action, struct ref_update * const *updates_orig, delnames = xmalloc(sizeof(*delnames) * n); /* Copy, sort, and reject duplicate refs */ - memcpy(updates, updates_orig, sizeof(*updates) * n); + memcpy(updates, transaction->updates, sizeof(*updates) * n); qsort(updates, n, sizeof(*updates), ref_update_compare); ret = ref_update_reject_duplicates(updates, n, onerr); if (ret) @@ -3437,7 +3452,7 @@ int update_refs(const char *action, struct ref_update * const *updates_orig, /* Perform updates first so live commits remain referenced */ for (i = 0; i < n; i++) if (!is_null_sha1(updates[i]->new_sha1)) { - ret = update_ref_write(action, + ret = update_ref_write(msg, updates[i]->ref_name, updates[i]->new_sha1, locks[i], onerr); @@ -3465,14 +3480,6 @@ int update_refs(const char *action, struct ref_update * const *updates_orig, free(types); free(locks); free(delnames); - return ret; -} - -int ref_transaction_commit(struct ref_transaction *transaction, - const char *msg, enum action_on_err onerr) -{ - int ret = update_refs(msg, transaction->updates, transaction->nr, - onerr); ref_transaction_free(transaction); return ret; } diff --git a/refs.h b/refs.h index 0518dd5203e09f..cb799a39f7a490 100644 --- a/refs.h +++ b/refs.h @@ -10,20 +10,6 @@ struct ref_lock { int force_write; }; -/** - * Information needed for a single ref update. Set new_sha1 to the - * new value or to zero to delete the ref. To check the old value - * while locking the ref, set have_old to 1 and set old_sha1 to the - * value or to zero to ensure the ref does not exist before update. - */ -struct ref_update { - const char *ref_name; - unsigned char new_sha1[20]; - unsigned char old_sha1[20]; - int flags; /* REF_NODEREF? */ - int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ -}; - struct ref_transaction; /* @@ -290,12 +276,6 @@ int update_ref(const char *action, const char *refname, const unsigned char *sha1, const unsigned char *oldval, int flags, enum action_on_err onerr); -/** - * Lock all refs and then perform all modifications. - */ -int update_refs(const char *action, struct ref_update * const *updates, - int n, enum action_on_err onerr); - extern int parse_hide_refs_config(const char *var, const char *value, const char *); extern int ref_is_hidden(const char *); From 5524e2416ec97f8c6d1a2fc12ee857efa9641175 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:13 +0200 Subject: [PATCH 044/760] struct ref_update: rename field "ref_name" to "refname" This is consistent with the usual nomenclature. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 18 +++++++++--------- refs.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/refs.c b/refs.c index 6984ff0aff994a..b6778aaa12c4d7 100644 --- a/refs.c +++ b/refs.c @@ -3274,7 +3274,7 @@ static int update_ref_write(const char *action, const char *refname, * value or to zero to ensure the ref does not exist before update. */ struct ref_update { - const char *ref_name; + const char *refname; unsigned char new_sha1[20]; unsigned char old_sha1[20]; int flags; /* REF_NODEREF? */ @@ -3304,7 +3304,7 @@ static void ref_transaction_free(struct ref_transaction *transaction) for (i = 0; i < transaction->nr; i++) { struct ref_update *update = transaction->updates[i]; - free((char *)update->ref_name); + free((char *)update->refname); free(update); } @@ -3322,7 +3322,7 @@ static struct ref_update *add_update(struct ref_transaction *transaction, { struct ref_update *update = xcalloc(1, sizeof(*update)); - update->ref_name = xstrdup(refname); + update->refname = xstrdup(refname); ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc); transaction->updates[transaction->nr++] = update; return update; @@ -3386,7 +3386,7 @@ static int ref_update_compare(const void *r1, const void *r2) { const struct ref_update * const *u1 = r1; const struct ref_update * const *u2 = r2; - return strcmp((*u1)->ref_name, (*u2)->ref_name); + return strcmp((*u1)->refname, (*u2)->refname); } static int ref_update_reject_duplicates(struct ref_update **updates, int n, @@ -3394,14 +3394,14 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, { int i; for (i = 1; i < n; i++) - if (!strcmp(updates[i - 1]->ref_name, updates[i]->ref_name)) { + if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) { const char *str = "Multiple updates for ref '%s' not allowed."; switch (onerr) { case UPDATE_REFS_MSG_ON_ERR: - error(str, updates[i]->ref_name); break; + error(str, updates[i]->refname); break; case UPDATE_REFS_DIE_ON_ERR: - die(str, updates[i]->ref_name); break; + die(str, updates[i]->refname); break; case UPDATE_REFS_QUIET_ON_ERR: break; } @@ -3438,7 +3438,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, /* Acquire all locks while verifying old values */ for (i = 0; i < n; i++) { - locks[i] = update_ref_lock(updates[i]->ref_name, + locks[i] = update_ref_lock(updates[i]->refname, (updates[i]->have_old ? updates[i]->old_sha1 : NULL), updates[i]->flags, @@ -3453,7 +3453,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, for (i = 0; i < n; i++) if (!is_null_sha1(updates[i]->new_sha1)) { ret = update_ref_write(msg, - updates[i]->ref_name, + updates[i]->refname, updates[i]->new_sha1, locks[i], onerr); locks[i] = NULL; /* freed by update_ref_write */ diff --git a/refs.h b/refs.h index cb799a39f7a490..0f08def21020a1 100644 --- a/refs.h +++ b/refs.h @@ -154,7 +154,7 @@ extern void unlock_ref(struct ref_lock *lock); extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg); /** Setup reflog before using. **/ -int log_ref_setup(const char *ref_name, char *logfile, int bufsize); +int log_ref_setup(const char *refname, char *logfile, int bufsize); /** Reads log for the value of ref during at_time. **/ extern int read_ref_at(const char *refname, unsigned long at_time, int cnt, From 88615910db7f700ae437318308a8631888bd28cd Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:14 +0200 Subject: [PATCH 045/760] struct ref_update: store refname as a FLEX_ARRAY Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/refs.c b/refs.c index b6778aaa12c4d7..2ff195f4711aaf 100644 --- a/refs.c +++ b/refs.c @@ -3274,11 +3274,11 @@ static int update_ref_write(const char *action, const char *refname, * value or to zero to ensure the ref does not exist before update. */ struct ref_update { - const char *refname; unsigned char new_sha1[20]; unsigned char old_sha1[20]; int flags; /* REF_NODEREF? */ int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ + const char refname[FLEX_ARRAY]; }; /* @@ -3301,12 +3301,8 @@ static void ref_transaction_free(struct ref_transaction *transaction) { int i; - for (i = 0; i < transaction->nr; i++) { - struct ref_update *update = transaction->updates[i]; - - free((char *)update->refname); - free(update); - } + for (i = 0; i < transaction->nr; i++) + free(transaction->updates[i]); free(transaction->updates); free(transaction); @@ -3320,9 +3316,10 @@ void ref_transaction_rollback(struct ref_transaction *transaction) static struct ref_update *add_update(struct ref_transaction *transaction, const char *refname) { - struct ref_update *update = xcalloc(1, sizeof(*update)); + size_t len = strlen(refname); + struct ref_update *update = xcalloc(1, sizeof(*update) + len + 1); - update->refname = xstrdup(refname); + strcpy((char *)update->refname, refname); ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc); transaction->updates[transaction->nr++] = update; return update; From cb198d21d3848f0c5f3d85a471a6a6793e540ca4 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:15 +0200 Subject: [PATCH 046/760] ref_transaction_commit(): simplify code using temporary variables Use temporary variables in the for-loop blocks to simplify expressions in the rest of the loop. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/refs.c b/refs.c index 2ff195f4711aaf..33c34dfeff9a92 100644 --- a/refs.c +++ b/refs.c @@ -3435,10 +3435,12 @@ int ref_transaction_commit(struct ref_transaction *transaction, /* Acquire all locks while verifying old values */ for (i = 0; i < n; i++) { - locks[i] = update_ref_lock(updates[i]->refname, - (updates[i]->have_old ? - updates[i]->old_sha1 : NULL), - updates[i]->flags, + struct ref_update *update = updates[i]; + + locks[i] = update_ref_lock(update->refname, + (update->have_old ? + update->old_sha1 : NULL), + update->flags, &types[i], onerr); if (!locks[i]) { ret = 1; @@ -3447,16 +3449,19 @@ int ref_transaction_commit(struct ref_transaction *transaction, } /* Perform updates first so live commits remain referenced */ - for (i = 0; i < n; i++) - if (!is_null_sha1(updates[i]->new_sha1)) { + for (i = 0; i < n; i++) { + struct ref_update *update = updates[i]; + + if (!is_null_sha1(update->new_sha1)) { ret = update_ref_write(msg, - updates[i]->refname, - updates[i]->new_sha1, + update->refname, + update->new_sha1, locks[i], onerr); locks[i] = NULL; /* freed by update_ref_write */ if (ret) goto cleanup; } + } /* Perform deletes now that updates are safely completed */ for (i = 0; i < n; i++) From 81c960e4dcbd69e28b031cbe370100cb28acb911 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:16 +0200 Subject: [PATCH 047/760] struct ref_update: add a lock field Now that we manage ref_update objects internally, we can use them to hold some of the scratch space we need when actually carrying out the updates. Store the (struct ref_lock *) there. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/refs.c b/refs.c index 33c34dfeff9a92..6fe4bfe8d90c2d 100644 --- a/refs.c +++ b/refs.c @@ -3278,6 +3278,7 @@ struct ref_update { unsigned char old_sha1[20]; int flags; /* REF_NODEREF? */ int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ + struct ref_lock *lock; const char refname[FLEX_ARRAY]; }; @@ -3413,7 +3414,6 @@ int ref_transaction_commit(struct ref_transaction *transaction, int ret = 0, delnum = 0, i; struct ref_update **updates; int *types; - struct ref_lock **locks; const char **delnames; int n = transaction->nr; @@ -3423,7 +3423,6 @@ int ref_transaction_commit(struct ref_transaction *transaction, /* Allocate work space */ updates = xmalloc(sizeof(*updates) * n); types = xmalloc(sizeof(*types) * n); - locks = xcalloc(n, sizeof(*locks)); delnames = xmalloc(sizeof(*delnames) * n); /* Copy, sort, and reject duplicate refs */ @@ -3437,12 +3436,12 @@ int ref_transaction_commit(struct ref_transaction *transaction, for (i = 0; i < n; i++) { struct ref_update *update = updates[i]; - locks[i] = update_ref_lock(update->refname, - (update->have_old ? - update->old_sha1 : NULL), - update->flags, - &types[i], onerr); - if (!locks[i]) { + update->lock = update_ref_lock(update->refname, + (update->have_old ? + update->old_sha1 : NULL), + update->flags, + &types[i], onerr); + if (!update->lock) { ret = 1; goto cleanup; } @@ -3456,19 +3455,23 @@ int ref_transaction_commit(struct ref_transaction *transaction, ret = update_ref_write(msg, update->refname, update->new_sha1, - locks[i], onerr); - locks[i] = NULL; /* freed by update_ref_write */ + update->lock, onerr); + update->lock = NULL; /* freed by update_ref_write */ if (ret) goto cleanup; } } /* Perform deletes now that updates are safely completed */ - for (i = 0; i < n; i++) - if (locks[i]) { - delnames[delnum++] = locks[i]->ref_name; - ret |= delete_ref_loose(locks[i], types[i]); + for (i = 0; i < n; i++) { + struct ref_update *update = updates[i]; + + if (update->lock) { + delnames[delnum++] = update->lock->ref_name; + ret |= delete_ref_loose(update->lock, types[i]); } + } + ret |= repack_without_refs(delnames, delnum); for (i = 0; i < delnum; i++) unlink_or_warn(git_path("logs/%s", delnames[i])); @@ -3476,11 +3479,10 @@ int ref_transaction_commit(struct ref_transaction *transaction, cleanup: for (i = 0; i < n; i++) - if (locks[i]) - unlock_ref(locks[i]); + if (updates[i]->lock) + unlock_ref(updates[i]->lock); free(updates); free(types); - free(locks); free(delnames); ref_transaction_free(transaction); return ret; From 84178db76f34d0b8d363545f6e18c99f6e37df4e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:17 +0200 Subject: [PATCH 048/760] struct ref_update: add a type field It used to be that ref_transaction_commit() allocated a temporary array to hold the types of references while it is working. Instead, add a type field to ref_update that ref_transaction_commit() can use as its scratch space. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/refs.c b/refs.c index 6fe4bfe8d90c2d..c058f304deaa46 100644 --- a/refs.c +++ b/refs.c @@ -3279,6 +3279,7 @@ struct ref_update { int flags; /* REF_NODEREF? */ int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ struct ref_lock *lock; + int type; const char refname[FLEX_ARRAY]; }; @@ -3413,7 +3414,6 @@ int ref_transaction_commit(struct ref_transaction *transaction, { int ret = 0, delnum = 0, i; struct ref_update **updates; - int *types; const char **delnames; int n = transaction->nr; @@ -3422,7 +3422,6 @@ int ref_transaction_commit(struct ref_transaction *transaction, /* Allocate work space */ updates = xmalloc(sizeof(*updates) * n); - types = xmalloc(sizeof(*types) * n); delnames = xmalloc(sizeof(*delnames) * n); /* Copy, sort, and reject duplicate refs */ @@ -3440,7 +3439,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, (update->have_old ? update->old_sha1 : NULL), update->flags, - &types[i], onerr); + &update->type, onerr); if (!update->lock) { ret = 1; goto cleanup; @@ -3468,7 +3467,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, if (update->lock) { delnames[delnum++] = update->lock->ref_name; - ret |= delete_ref_loose(update->lock, types[i]); + ret |= delete_ref_loose(update->lock, update->type); } } @@ -3482,7 +3481,6 @@ int ref_transaction_commit(struct ref_transaction *transaction, if (updates[i]->lock) unlock_ref(updates[i]->lock); free(updates); - free(types); free(delnames); ref_transaction_free(transaction); return ret; From 6a402338ec9ca0369e1801533dda2108689ceaaf Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 7 Apr 2014 15:48:18 +0200 Subject: [PATCH 049/760] ref_transaction_commit(): work with transaction->updates in place Now that we free the transaction when we are done, there is no need to make a copy of transaction->updates before working with it. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/refs.c b/refs.c index c058f304deaa46..728a7616483036 100644 --- a/refs.c +++ b/refs.c @@ -3413,19 +3413,17 @@ int ref_transaction_commit(struct ref_transaction *transaction, const char *msg, enum action_on_err onerr) { int ret = 0, delnum = 0, i; - struct ref_update **updates; const char **delnames; int n = transaction->nr; + struct ref_update **updates = transaction->updates; if (!n) return 0; /* Allocate work space */ - updates = xmalloc(sizeof(*updates) * n); delnames = xmalloc(sizeof(*delnames) * n); /* Copy, sort, and reject duplicate refs */ - memcpy(updates, transaction->updates, sizeof(*updates) * n); qsort(updates, n, sizeof(*updates), ref_update_compare); ret = ref_update_reject_duplicates(updates, n, onerr); if (ret) @@ -3480,7 +3478,6 @@ int ref_transaction_commit(struct ref_transaction *transaction, for (i = 0; i < n; i++) if (updates[i]->lock) unlock_ref(updates[i]->lock); - free(updates); free(delnames); ref_transaction_free(transaction); return ret; From 72441af7c4e3bde33cdf7edafcf09c227d5d5296 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 7 Apr 2014 01:46:26 +0400 Subject: [PATCH 050/760] tree-diff: rework diff_tree() to generate diffs for multiparent cases as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously diff_tree(), which is now named ll_diff_tree_sha1(), was generating diff_filepair(s) for two trees t1 and t2, and that was usually used for a commit as t1=HEAD~, and t2=HEAD - i.e. to see changes a commit introduces. In Git, however, we have fundamentally built flexibility in that a commit can have many parents - 1 for a plain commit, 2 for a simple merge, but also more than 2 for merging several heads at once. For merges there is a so called combine-diff, which shows diff, a merge introduces by itself, omitting changes done by any parent. That works through first finding paths, that are different to all parents, and then showing generalized diff, with separate columns for +/- for each parent. The code lives in combine-diff.c . There is an impedance mismatch, however, in that a commit could generally have any number of parents, and that while diffing trees, we divide cases for 2-tree diffs and more-than-2-tree diffs. I mean there is no special casing for multiple parents commits in e.g. revision-walker . That impedance mismatch *hurts* *performance* *badly* for generating combined diffs - in "combine-diff: optimize combine_diff_path sets intersection" I've already removed some slowness from it, but from the timings provided there, it could be seen, that combined diffs still cost more than an order of magnitude more cpu time, compared to diff for usual commits, and that would only be an optimistic estimate, if we take into account that for e.g. linux.git there is only one merge for several dozens of plain commits. That slowness comes from the fact that currently, while generating combined diff, a lot of time is spent computing diff(commit,commit^2) just to only then intersect that huge diff to almost small set of files from diff(commit,commit^1). That's because at present, to compute combine-diff, for first finding paths, that "every parent touches", we use the following combine-diff property/definition: D(A,P1...Pn) = D(A,P1) ^ ... ^ D(A,Pn) (w.r.t. paths) where D(A,P1...Pn) is combined diff between commit A, and parents Pi and D(A,Pi) is usual two-tree diff Pi..A So if any of that D(A,Pi) is huge, tracting 1 n-parent combine-diff as n 1-parent diffs and intersecting results will be slow. And usually, for linux.git and other topic-based workflows, that D(A,P2) is huge, because, if merge-base of A and P2, is several dozens of merges (from A, via first parent) below, that D(A,P2) will be diffing sum of merges from several subsystems to 1 subsystem. The solution is to avoid computing n 1-parent diffs, and to find changed-to-all-parents paths via scanning A's and all Pi's trees simultaneously, at each step comparing their entries, and based on that comparison, populate paths result, and deduce we could *skip* *recursing* into subdirectories, if at least for 1 parent, sha1 of that dir tree is the same as in A. That would save us from doing significant amount of needless work. Such approach is very similar to what diff_tree() does, only there we deal with scanning only 2 trees simultaneously, and for n+1 tree, the logic is a bit more complex: D(T,P1...Pn) calculation scheme ------------------------------- D(T,P1...Pn) = D(T,P1) ^ ... ^ D(T,Pn) (regarding resulting paths set) D(T,Pj) - diff between T..Pj D(T,P1...Pn) - combined diff from T to parents P1,...,Pn We start from all trees, which are sorted, and compare their entries in lock-step: T P1 Pn - - - |t| |p1| |pn| |-| |--| ... |--| imin = argmin(p1...pn) | | | | | | |-| |--| |--| |.| |. | |. | . . . . . . at any time there could be 3 cases: 1) t < p[imin]; 2) t > p[imin]; 3) t = p[imin]. Schematic deduction of what every case means, and what to do, follows: 1) t < p[imin] -> ∀j t ∉ Pj -> "+t" ∈ D(T,Pj) -> D += "+t"; t↓ 2) t > p[imin] 2.1) ∃j: pj > p[imin] -> "-p[imin]" ∉ D(T,Pj) -> D += ø; ∀ pi=p[imin] pi↓ 2.2) ∀i pi = p[imin] -> pi ∉ T -> "-pi" ∈ D(T,Pi) -> D += "-p[imin]"; ∀i pi↓ 3) t = p[imin] 3.1) ∃j: pj > p[imin] -> "+t" ∈ D(T,Pj) -> only pi=p[imin] remains to investigate 3.2) pi = p[imin] -> investigate δ(t,pi) | | v 3.1+3.2) looking at δ(t,pi) ∀i: pi=p[imin] - if all != ø -> ⎧δ(t,pi) - if pi=p[imin] -> D += ⎨ ⎩"+t" - if pi>p[imin] in any case t↓ ∀ pi=p[imin] pi↓ ~ For comparison, here is how diff_tree() works: D(A,B) calculation scheme ------------------------- A B - - |a| |b| a < b -> a ∉ B -> D(A,B) += +a a↓ |-| |-| a > b -> b ∉ A -> D(A,B) += -b b↓ | | | | a = b -> investigate δ(a,b) a↓ b↓ |-| |-| |.| |.| . . . . ~~~~~~~~ This patch generalizes diff tree-walker to work with arbitrary number of parents as described above - i.e. now there is a resulting tree t, and some parents trees tp[i] i=[0..nparent). The generalization builds on the fact that usual diff D(A,B) is by definition the same as combined diff D(A,[B]), so if we could rework the code for common case and make it be not slower for nparent=1 case, usual diff(t1,t2) generation will not be slower, and multiparent diff tree-walker would greatly benefit generating combine-diff. What we do is as follows: 1) diff tree-walker ll_diff_tree_sha1() is internally reworked to be a paths generator (new name diff_tree_paths()), with each generated path being `struct combine_diff_path` with info for path, new sha1,mode and for every parent which sha1,mode it was in it. 2) From that info, we can still generate usual diff queue with struct diff_filepairs, via "exporting" generated combine_diff_path, if we know we run for nparent=1 case. (see emit_diff() which is now named emit_diff_first_parent_only()) 3) In order for diff_can_quit_early(), which checks DIFF_OPT_TST(opt, HAS_CHANGES)) to work, that exporting have to be happening not in bulk, but incrementally, one diff path at a time. For such consumers, there is a new callback in diff_options introduced: ->pathchange(opt, struct combine_diff_path *) which, if set to !NULL, is called for every generated path. (see new compat ll_diff_tree_sha1() wrapper around new paths generator for setup) 4) The paths generation itself, is reworked from previous ll_diff_tree_sha1() code according to "D(A,P1...Pn) calculation scheme" provided above: On the start we allocate [nparent] arrays in place what was earlier just for one parent tree. then we just generalize loops, and comparison according to the algorithm. Some notes(*): 1) alloca(), for small arrays, is used for "runs not slower for nparent=1 case than before" goal - if we change it to xmalloc()/free() the timings get ~1% worse. For alloca() we use just-introduced xalloca/xalloca_free compatibility wrappers, so it should not be a portability problem. 2) For every parent tree, we need to keep a tag, whether entry from that parent equals to entry from minimal parent. For performance reasons I'm keeping that tag in entry's mode field in unused bit - see S_IFXMIN_NEQ. Not doing so, we'd need to alloca another [nparent] array, which hurts performance. 3) For emitted paths, memory could be reused, if we know the path was processed via callback and will not be needed later. We use efficient hand-made realloc-style path_appendnew(), that saves us from ~1-1.5% of potential additional slowdown. 4) goto(s) are used in several places, as the code executes a little bit faster with lowered register pressure. Also - we should now check for FIND_COPIES_HARDER not only when two entries names are the same, and their hashes are equal, but also for a case, when a path was removed from some of all parents having it. The reason is, if we don't, that path won't be emitted at all (see "a > xi" case), and we'll just skip it, and FIND_COPIES_HARDER wants all paths - with diff or without - to be emitted, to be later analyzed for being copies sources. The new check is only necessary for nparent >1, as for nparent=1 case xmin_eqtotal always =1 =nparent, and a path is always added to diff as removal. ~~~~~~~~ Timings for # without -c, i.e. testing only nparent=1 case `git log --raw --no-abbrev --no-renames` before and after the patch are as follows: navy.git linux.git v3.10..v3.11 before 0.611s 1.889s after 0.619s 1.907s slowdown 1.3% 0.9% This timings show we did no harm to usual diff(tree1,tree2) generation. From the table we can see that we actually did ~1% slowdown, but I think I've "earned" that 1% in the previous patch ("tree-diff: reuse base str(buf) memory on sub-tree recursion", HEAD~~) so for nparent=1 case, net timings stays approximately the same. The output also stayed the same. (*) If we revert 1)-4) to more usual techniques, for nparent=1 case, we'll get ~2-2.5% of additional slowdown, which I've tried to avoid, as "do no harm for nparent=1 case" rule. For linux.git, combined diff will run an order of magnitude faster and appropriate timings will be provided in the next commit, as we'll be taking advantage of the new diff tree-walker for combined-diff generation there. P.S. and combined diff is not some exotic/for-play-only stuff - for example for a program I write to represent Git archives as readonly filesystem, there is initial scan with `git log --reverse --raw --no-abbrev --no-renames -c` to extract log of what was created/changed when, as a result building a map {} sha1 -> in which commit (and date) a content was added that `-c` means also show combined diff for merges, and without them, if a merge is non-trivial (merges changes from two parents with both having separate changes to a file), or an evil one, the map will not be full, i.e. some valid sha1 would be absent from it. That case was my initial motivation for combined diffs speedup. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- cache.h | 15 ++ diff.c | 1 + diff.h | 9 + tree-diff.c | 504 +++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 465 insertions(+), 64 deletions(-) diff --git a/cache.h b/cache.h index dc040fb1aa99b7..e7f5a0c7c80383 100644 --- a/cache.h +++ b/cache.h @@ -74,6 +74,21 @@ unsigned long git_deflate_bound(git_zstream *, unsigned long); #define S_IFGITLINK 0160000 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) +/* + * Some mode bits are also used internally for computations. + * + * They *must* not overlap with any valid modes, and they *must* not be emitted + * to outside world - i.e. appear on disk or network. In other words, it's just + * temporary fields, which we internally use, but they have to stay in-house. + * + * ( such approach is valid, as standard S_IF* fits into 16 bits, and in Git + * codebase mode is `unsigned int` which is assumed to be at least 32 bits ) + */ + +/* used internally in tree-diff */ +#define S_DIFFTREE_IFXMIN_NEQ 0x80000000 + + /* * Intensive research over the course of many years has shown that * port 9418 is totally unused by anything else. Or diff --git a/diff.c b/diff.c index 8e4a6a910519b2..cda4aa8f859b5d 100644 --- a/diff.c +++ b/diff.c @@ -3216,6 +3216,7 @@ void diff_setup(struct diff_options *options) options->context = diff_context_default; DIFF_OPT_SET(options, RENAME_EMPTY); + /* pathchange left =NULL by default */ options->change = diff_change; options->add_remove = diff_addremove; options->use_color = diff_use_color_default; diff --git a/diff.h b/diff.h index 5d7b9f7577a393..0abd7350544b38 100644 --- a/diff.h +++ b/diff.h @@ -15,6 +15,10 @@ struct diff_filespec; struct userdiff_driver; struct sha1_array; struct commit; +struct combine_diff_path; + +typedef int (*pathchange_fn_t)(struct diff_options *options, + struct combine_diff_path *path); typedef void (*change_fn_t)(struct diff_options *options, unsigned old_mode, unsigned new_mode, @@ -157,6 +161,7 @@ struct diff_options { int close_file; struct pathspec pathspec; + pathchange_fn_t pathchange; change_fn_t change; add_remove_fn_t add_remove; diff_format_fn_t format_callback; @@ -189,6 +194,10 @@ const char *diff_line_prefix(struct diff_options *); extern const char mime_boundary_leader[]; +extern struct combine_diff_path *diff_tree_paths( + struct combine_diff_path *p, const unsigned char *sha1, + const unsigned char **parent_sha1, int nparent, + struct strbuf *base, struct diff_options *opt); extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base, struct diff_options *opt); extern int diff_root_tree_sha1(const unsigned char *new, const char *base, diff --git a/tree-diff.c b/tree-diff.c index 278acc807a3564..e7b378c8b2c8f1 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -6,7 +6,19 @@ #include "diffcore.h" #include "tree.h" +/* + * internal mode marker, saying a tree entry != entry of tp[imin] + * (see ll_diff_tree_paths for what it means there) + * + * we will update/use/emit entry for diff only with it unset. + */ +#define S_IFXMIN_NEQ S_DIFFTREE_IFXMIN_NEQ + +static struct combine_diff_path *ll_diff_tree_paths( + struct combine_diff_path *p, const unsigned char *sha1, + const unsigned char **parents_sha1, int nparent, + struct strbuf *base, struct diff_options *opt); static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, struct strbuf *base, struct diff_options *opt); @@ -42,71 +54,151 @@ static int tree_entry_pathcmp(struct tree_desc *t1, struct tree_desc *t2) } -/* convert path, t1/t2 -> opt->diff_*() callbacks */ -static void emit_diff(struct diff_options *opt, struct strbuf *path, - struct tree_desc *t1, struct tree_desc *t2) +/* + * convert path -> opt->diff_*() callbacks + * + * emits diff to first parent only, and tells diff tree-walker that we are done + * with p and it can be freed. + */ +static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_diff_path *p) { - unsigned int mode1 = t1 ? t1->entry.mode : 0; - unsigned int mode2 = t2 ? t2->entry.mode : 0; - - if (mode1 && mode2) { - opt->change(opt, mode1, mode2, t1->entry.sha1, t2->entry.sha1, - 1, 1, path->buf, 0, 0); + struct combine_diff_parent *p0 = &p->parent[0]; + if (p->mode && p0->mode) { + opt->change(opt, p0->mode, p->mode, p0->sha1, p->sha1, + 1, 1, p->path, 0, 0); } else { const unsigned char *sha1; unsigned int mode; int addremove; - if (mode2) { + if (p->mode) { addremove = '+'; - sha1 = t2->entry.sha1; - mode = mode2; + sha1 = p->sha1; + mode = p->mode; } else { addremove = '-'; - sha1 = t1->entry.sha1; - mode = mode1; + sha1 = p0->sha1; + mode = p0->mode; } - opt->add_remove(opt, addremove, mode, sha1, 1, path->buf, 0); + opt->add_remove(opt, addremove, mode, sha1, 1, p->path, 0); } + + return 0; /* we are done with p */ } -/* new path should be added to diff +/* + * Make a new combine_diff_path from path/mode/sha1 + * and append it to paths list tail. + * + * Memory for created elements could be reused: + * + * - if last->next == NULL, the memory is allocated; + * + * - if last->next != NULL, it is assumed that p=last->next was returned + * earlier by this function, and p->next was *not* modified. + * The memory is then reused from p. + * + * so for clients, + * + * - if you do need to keep the element + * + * p = path_appendnew(p, ...); + * process(p); + * p->next = NULL; + * + * - if you don't need to keep the element after processing + * + * pprev = p; + * p = path_appendnew(p, ...); + * process(p); + * p = pprev; + * ; don't forget to free tail->next in the end + * + * p->parent[] remains uninitialized. + */ +static struct combine_diff_path *path_appendnew(struct combine_diff_path *last, + int nparent, const struct strbuf *base, const char *path, int pathlen, + unsigned mode, const unsigned char *sha1) +{ + struct combine_diff_path *p; + int len = base->len + pathlen; + int alloclen = combine_diff_path_size(nparent, len); + + /* if last->next is !NULL - it is a pre-allocated memory, we can reuse */ + p = last->next; + if (p && (alloclen > (intptr_t)p->next)) { + free(p); + p = NULL; + } + + if (!p) { + p = xmalloc(alloclen); + + /* + * until we go to it next round, .next holds how many bytes we + * allocated (for faster realloc - we don't need copying old data). + */ + p->next = (struct combine_diff_path *)(intptr_t)alloclen; + } + + last->next = p; + + p->path = (char *)&(p->parent[nparent]); + memcpy(p->path, base->buf, base->len); + memcpy(p->path + base->len, path, pathlen); + p->path[len] = 0; + p->mode = mode; + hashcpy(p->sha1, sha1 ? sha1 : null_sha1); + + return p; +} + +/* + * new path should be added to combine diff * * 3 cases on how/when it should be called and behaves: * - * !t1, t2 -> path added, parent lacks it - * t1, !t2 -> path removed from parent - * t1, t2 -> path modified + * t, !tp -> path added, all parents lack it + * !t, tp -> path removed from all parents + * t, tp -> path modified/added + * (M for tp[i]=tp[imin], A otherwise) */ -static void show_path(struct strbuf *base, struct diff_options *opt, - struct tree_desc *t1, struct tree_desc *t2) +static struct combine_diff_path *emit_path(struct combine_diff_path *p, + struct strbuf *base, struct diff_options *opt, int nparent, + struct tree_desc *t, struct tree_desc *tp, + int imin) { unsigned mode; const char *path; + const unsigned char *sha1; int pathlen; int old_baselen = base->len; - int isdir, recurse = 0, emitthis = 1; + int i, isdir, recurse = 0, emitthis = 1; /* at least something has to be valid */ - assert(t1 || t2); + assert(t || tp); - if (t2) { + if (t) { /* path present in resulting tree */ - tree_entry_extract(t2, &path, &mode); - pathlen = tree_entry_len(&t2->entry); + sha1 = tree_entry_extract(t, &path, &mode); + pathlen = tree_entry_len(&t->entry); isdir = S_ISDIR(mode); } else { /* - * a path was removed - take path from parent. Also take - * mode from parent, to decide on recursion. + * a path was removed - take path from imin parent. Also take + * mode from that parent, to decide on recursion(1). + * + * 1) all modes for tp[i]=tp[imin] should be the same wrt + * S_ISDIR, thanks to base_name_compare(). */ - tree_entry_extract(t1, &path, &mode); - pathlen = tree_entry_len(&t1->entry); + tree_entry_extract(&tp[imin], &path, &mode); + pathlen = tree_entry_len(&tp[imin].entry); isdir = S_ISDIR(mode); + sha1 = NULL; mode = 0; } @@ -115,18 +207,81 @@ static void show_path(struct strbuf *base, struct diff_options *opt, emitthis = DIFF_OPT_TST(opt, TREE_IN_RECURSIVE); } - strbuf_add(base, path, pathlen); + if (emitthis) { + int keep; + struct combine_diff_path *pprev = p; + p = path_appendnew(p, nparent, base, path, pathlen, mode, sha1); + + for (i = 0; i < nparent; ++i) { + /* + * tp[i] is valid, if present and if tp[i]==tp[imin] - + * otherwise, we should ignore it. + */ + int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); + + const unsigned char *sha1_i; + unsigned mode_i; + + p->parent[i].status = + !t ? DIFF_STATUS_DELETED : + tpi_valid ? + DIFF_STATUS_MODIFIED : + DIFF_STATUS_ADDED; + + if (tpi_valid) { + sha1_i = tp[i].entry.sha1; + mode_i = tp[i].entry.mode; + } + else { + sha1_i = NULL; + mode_i = 0; + } + + p->parent[i].mode = mode_i; + hashcpy(p->parent[i].sha1, sha1_i ? sha1_i : null_sha1); + } - if (emitthis) - emit_diff(opt, base, t1, t2); + keep = 1; + if (opt->pathchange) + keep = opt->pathchange(opt, p); + + /* + * If a path was filtered or consumed - we don't need to add it + * to the list and can reuse its memory, leaving it as + * pre-allocated element on the tail. + * + * On the other hand, if path needs to be kept, we need to + * correct its .next to NULL, as it was pre-initialized to how + * much memory was allocated. + * + * see path_appendnew() for details. + */ + if (!keep) + p = pprev; + else + p->next = NULL; + } if (recurse) { + const unsigned char **parents_sha1; + + parents_sha1 = xalloca(nparent * sizeof(parents_sha1[0])); + for (i = 0; i < nparent; ++i) { + /* same rule as in emitthis */ + int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); + + parents_sha1[i] = tpi_valid ? tp[i].entry.sha1 + : NULL; + } + + strbuf_add(base, path, pathlen); strbuf_addch(base, '/'); - ll_diff_tree_sha1(t1 ? t1->entry.sha1 : NULL, - t2 ? t2->entry.sha1 : NULL, base, opt); + p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt); + xalloca_free(parents_sha1); } strbuf_setlen(base, old_baselen); + return p; } static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, @@ -145,59 +300,260 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, } } -static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, - struct strbuf *base, struct diff_options *opt) + +/* + * generate paths for combined diff D(sha1,parents_sha1[]) + * + * Resulting paths are appended to combine_diff_path linked list, and also, are + * emitted on the go via opt->pathchange() callback, so it is possible to + * process the result as batch or incrementally. + * + * The paths are generated scanning new tree and all parents trees + * simultaneously, similarly to what diff_tree() was doing for 2 trees. + * The theory behind such scan is as follows: + * + * + * D(T,P1...Pn) calculation scheme + * ------------------------------- + * + * D(T,P1...Pn) = D(T,P1) ^ ... ^ D(T,Pn) (regarding resulting paths set) + * + * D(T,Pj) - diff between T..Pj + * D(T,P1...Pn) - combined diff from T to parents P1,...,Pn + * + * + * We start from all trees, which are sorted, and compare their entries in + * lock-step: + * + * T P1 Pn + * - - - + * |t| |p1| |pn| + * |-| |--| ... |--| imin = argmin(p1...pn) + * | | | | | | + * |-| |--| |--| + * |.| |. | |. | + * . . . + * . . . + * + * at any time there could be 3 cases: + * + * 1) t < p[imin]; + * 2) t > p[imin]; + * 3) t = p[imin]. + * + * Schematic deduction of what every case means, and what to do, follows: + * + * 1) t < p[imin] -> ∀j t ∉ Pj -> "+t" ∈ D(T,Pj) -> D += "+t"; t↓ + * + * 2) t > p[imin] + * + * 2.1) ∃j: pj > p[imin] -> "-p[imin]" ∉ D(T,Pj) -> D += ø; ∀ pi=p[imin] pi↓ + * 2.2) ∀i pi = p[imin] -> pi ∉ T -> "-pi" ∈ D(T,Pi) -> D += "-p[imin]"; ∀i pi↓ + * + * 3) t = p[imin] + * + * 3.1) ∃j: pj > p[imin] -> "+t" ∈ D(T,Pj) -> only pi=p[imin] remains to investigate + * 3.2) pi = p[imin] -> investigate δ(t,pi) + * | + * | + * v + * + * 3.1+3.2) looking at δ(t,pi) ∀i: pi=p[imin] - if all != ø -> + * + * ⎧δ(t,pi) - if pi=p[imin] + * -> D += ⎨ + * ⎩"+t" - if pi>p[imin] + * + * + * in any case t↓ ∀ pi=p[imin] pi↓ + * + * + * ~~~~~~~~ + * + * NOTE + * + * Usual diff D(A,B) is by definition the same as combined diff D(A,[B]), + * so this diff paths generator can, and is used, for plain diffs + * generation too. + * + * Please keep attention to the common D(A,[B]) case when working on the + * code, in order not to slow it down. + * + * NOTE + * nparent must be > 0. + */ + + +/* ∀ pi=p[imin] pi↓ */ +static inline void update_tp_entries(struct tree_desc *tp, int nparent) { - struct tree_desc t1, t2; - void *t1tree, *t2tree; + int i; + for (i = 0; i < nparent; ++i) + if (!(tp[i].entry.mode & S_IFXMIN_NEQ)) + update_tree_entry(&tp[i]); +} - t1tree = fill_tree_descriptor(&t1, old); - t2tree = fill_tree_descriptor(&t2, new); +static struct combine_diff_path *ll_diff_tree_paths( + struct combine_diff_path *p, const unsigned char *sha1, + const unsigned char **parents_sha1, int nparent, + struct strbuf *base, struct diff_options *opt) +{ + struct tree_desc t, *tp; + void *ttree, **tptree; + int i; + + tp = xalloca(nparent * sizeof(tp[0])); + tptree = xalloca(nparent * sizeof(tptree[0])); + + /* + * load parents first, as they are probably already cached. + * + * ( log_tree_diff() parses commit->parent before calling here via + * diff_tree_sha1(parent, commit) ) + */ + for (i = 0; i < nparent; ++i) + tptree[i] = fill_tree_descriptor(&tp[i], parents_sha1[i]); + ttree = fill_tree_descriptor(&t, sha1); /* Enable recursion indefinitely */ opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); for (;;) { - int cmp; + int imin, cmp; if (diff_can_quit_early(opt)) break; + if (opt->pathspec.nr) { - skip_uninteresting(&t1, base, opt); - skip_uninteresting(&t2, base, opt); + skip_uninteresting(&t, base, opt); + for (i = 0; i < nparent; i++) + skip_uninteresting(&tp[i], base, opt); + } + + /* comparing is finished when all trees are done */ + if (!t.size) { + int done = 1; + for (i = 0; i < nparent; ++i) + if (tp[i].size) { + done = 0; + break; + } + if (done) + break; + } + + /* + * lookup imin = argmin(p1...pn), + * mark entries whether they =p[imin] along the way + */ + imin = 0; + tp[0].entry.mode &= ~S_IFXMIN_NEQ; + + for (i = 1; i < nparent; ++i) { + cmp = tree_entry_pathcmp(&tp[i], &tp[imin]); + if (cmp < 0) { + imin = i; + tp[i].entry.mode &= ~S_IFXMIN_NEQ; + } + else if (cmp == 0) { + tp[i].entry.mode &= ~S_IFXMIN_NEQ; + } + else { + tp[i].entry.mode |= S_IFXMIN_NEQ; + } } - if (!t1.size && !t2.size) - break; - cmp = tree_entry_pathcmp(&t1, &t2); + /* fixup markings for entries before imin */ + for (i = 0; i < imin; ++i) + tp[i].entry.mode |= S_IFXMIN_NEQ; /* pi > p[imin] */ - /* t1 = t2 */ - if (cmp == 0) { - if (DIFF_OPT_TST(opt, FIND_COPIES_HARDER) || - hashcmp(t1.entry.sha1, t2.entry.sha1) || - (t1.entry.mode != t2.entry.mode)) - show_path(base, opt, &t1, &t2); - update_tree_entry(&t1); - update_tree_entry(&t2); + + /* compare t vs p[imin] */ + cmp = tree_entry_pathcmp(&t, &tp[imin]); + + /* t = p[imin] */ + if (cmp == 0) { + /* are either pi > p[imin] or diff(t,pi) != ø ? */ + if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER)) { + for (i = 0; i < nparent; ++i) { + /* p[i] > p[imin] */ + if (tp[i].entry.mode & S_IFXMIN_NEQ) + continue; + + /* diff(t,pi) != ø */ + if (hashcmp(t.entry.sha1, tp[i].entry.sha1) || + (t.entry.mode != tp[i].entry.mode)) + continue; + + goto skip_emit_t_tp; + } + } + + /* D += {δ(t,pi) if pi=p[imin]; "+a" if pi > p[imin]} */ + p = emit_path(p, base, opt, nparent, + &t, tp, imin); + + skip_emit_t_tp: + /* t↓, ∀ pi=p[imin] pi↓ */ + update_tree_entry(&t); + update_tp_entries(tp, nparent); } - /* t1 < t2 */ + /* t < p[imin] */ else if (cmp < 0) { - show_path(base, opt, &t1, /*t2=*/NULL); - update_tree_entry(&t1); + /* D += "+t" */ + p = emit_path(p, base, opt, nparent, + &t, /*tp=*/NULL, -1); + + /* t↓ */ + update_tree_entry(&t); } - /* t1 > t2 */ + /* t > p[imin] */ else { - show_path(base, opt, /*t1=*/NULL, &t2); - update_tree_entry(&t2); + /* ∀i pi=p[imin] -> D += "-p[imin]" */ + if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER)) { + for (i = 0; i < nparent; ++i) + if (tp[i].entry.mode & S_IFXMIN_NEQ) + goto skip_emit_tp; + } + + p = emit_path(p, base, opt, nparent, + /*t=*/NULL, tp, imin); + + skip_emit_tp: + /* ∀ pi=p[imin] pi↓ */ + update_tp_entries(tp, nparent); } } - free(t2tree); - free(t1tree); - return 0; + free(ttree); + for (i = nparent-1; i >= 0; i--) + free(tptree[i]); + xalloca_free(tptree); + xalloca_free(tp); + + return p; +} + +struct combine_diff_path *diff_tree_paths( + struct combine_diff_path *p, const unsigned char *sha1, + const unsigned char **parents_sha1, int nparent, + struct strbuf *base, struct diff_options *opt) +{ + p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt); + + /* + * free pre-allocated last element, if any + * (see path_appendnew() for details about why) + */ + if (p->next) { + free(p->next); + p->next = NULL; + } + + return p; } /* @@ -308,6 +664,26 @@ static void try_to_follow_renames(const unsigned char *old, const unsigned char q->nr = 1; } +static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, + struct strbuf *base, struct diff_options *opt) +{ + struct combine_diff_path phead, *p; + pathchange_fn_t pathchange_old = opt->pathchange; + + phead.next = NULL; + opt->pathchange = emit_diff_first_parent_only; + diff_tree_paths(&phead, new, &old, 1, base, opt); + + for (p = phead.next; p;) { + struct combine_diff_path *pprev = p; + p = p->next; + free(pprev); + } + + opt->pathchange = pathchange_old; + return 0; +} + int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base_str, struct diff_options *opt) { struct strbuf base; From 7195fbfaf5a539b8e8358097e02b63991e78a565 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Mon, 24 Feb 2014 20:21:51 +0400 Subject: [PATCH 051/760] combine-diff: speed it up, by using multiparent diff tree-walker directly As was recently shown in "combine-diff: optimize combine_diff_path sets intersection", combine-diff runs very slowly. In that commit we optimized paths sets intersection, but that accounted only for ~ 25% of the slowness, and as my tracing showed, for linux.git v3.10..v3.11, for merges a lot of time is spent computing diff(commit,commit^2) just to only then intersect that huge diff to almost small set of files from diff(commit,commit^1). In previous commit, we described the problem in more details, and reworked the diff tree-walker to be general one - i.e. to work in multiple parent case too. Now is the time to take advantage of it for finding paths for combine diff. The implementation is straightforward - if we know, we can get generated diff paths directly, and at present that means no diff filtering or rename/copy detection was requested(*), we can call multiparent tree-walker directly and get ready paths. (*) because e.g. at present, all diffcore transformations work on diff_filepair queues, but in the future, that limitation can be lifted, if filters would operate directly on combine_diff_paths. Timings for `git log --raw --no-abbrev --no-renames` without `-c` ("git log") and with `-c` ("git log -c") and with `-c --merges` ("git log -c --merges") before and after the patch are as follows: linux.git v3.10..v3.11 log log -c log -c --merges before 1.9s 16.4s 15.2s after 1.9s 2.4s 1.1s The result stayed the same. Signed-off-by: Kirill Smelkov Signed-off-by: Junio C Hamano --- combine-diff.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++--- diff.c | 1 + 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 1732dfd110664e..12764fb733f3ca 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1303,7 +1303,7 @@ static const char *path_path(void *obj) /* find set of paths that every parent touches */ -static struct combine_diff_path *find_paths(const unsigned char *sha1, +static struct combine_diff_path *find_paths_generic(const unsigned char *sha1, const struct sha1_array *parents, struct diff_options *opt) { struct combine_diff_path *paths = NULL; @@ -1316,6 +1316,7 @@ static struct combine_diff_path *find_paths(const unsigned char *sha1, /* tell diff_tree to emit paths in sorted (=tree) order */ opt->orderfile = NULL; + /* D(A,P1...Pn) = D(A,P1) ^ ... ^ D(A,Pn) (wrt paths) */ for (i = 0; i < num_parent; i++) { /* * show stat against the first parent even when doing @@ -1346,6 +1347,35 @@ static struct combine_diff_path *find_paths(const unsigned char *sha1, } +/* + * find set of paths that everybody touches, assuming diff is run without + * rename/copy detection, etc, comparing all trees simultaneously (= faster). + */ +static struct combine_diff_path *find_paths_multitree( + const unsigned char *sha1, const struct sha1_array *parents, + struct diff_options *opt) +{ + int i, nparent = parents->nr; + const unsigned char **parents_sha1; + struct combine_diff_path paths_head; + struct strbuf base; + + parents_sha1 = xmalloc(nparent * sizeof(parents_sha1[0])); + for (i = 0; i < nparent; i++) + parents_sha1[i] = parents->sha1[i]; + + /* fake list head, so worker can assume it is non-NULL */ + paths_head.next = NULL; + + strbuf_init(&base, PATH_MAX); + diff_tree_paths(&paths_head, sha1, parents_sha1, nparent, &base, opt); + + strbuf_release(&base); + free(parents_sha1); + return paths_head.next; +} + + void diff_tree_combined(const unsigned char *sha1, const struct sha1_array *parents, int dense, @@ -1355,6 +1385,7 @@ void diff_tree_combined(const unsigned char *sha1, struct diff_options diffopts; struct combine_diff_path *p, *paths; int i, num_paths, needsep, show_log_first, num_parent = parents->nr; + int need_generic_pathscan; /* nothing to do, if no parents */ if (!num_parent) @@ -1377,11 +1408,58 @@ void diff_tree_combined(const unsigned char *sha1, /* find set of paths that everybody touches * - * NOTE find_paths() also handles --stat, as it computes - * diff(sha1,parent_i) for all i to do the job, specifically - * for parent0. + * NOTE + * + * Diffcore transformations are bound to diff_filespec and logic + * comparing two entries - i.e. they do not apply directly to combine + * diff. + * + * If some of such transformations is requested - we launch generic + * path scanning, which works significantly slower compared to + * simultaneous all-trees-in-one-go scan in find_paths_multitree(). + * + * TODO some of the filters could be ported to work on + * combine_diff_paths - i.e. all functionality that skips paths, so in + * theory, we could end up having only multitree path scanning. + * + * NOTE please keep this semantically in sync with diffcore_std() */ - paths = find_paths(sha1, parents, &diffopts); + need_generic_pathscan = opt->skip_stat_unmatch || + DIFF_OPT_TST(opt, FOLLOW_RENAMES) || + opt->break_opt != -1 || + opt->detect_rename || + opt->pickaxe || + opt->filter; + + + if (need_generic_pathscan) { + /* + * NOTE generic case also handles --stat, as it computes + * diff(sha1,parent_i) for all i to do the job, specifically + * for parent0. + */ + paths = find_paths_generic(sha1, parents, &diffopts); + } + else { + int stat_opt; + paths = find_paths_multitree(sha1, parents, &diffopts); + + /* + * show stat against the first parent even + * when doing combined diff. + */ + stat_opt = (opt->output_format & + (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT)); + if (stat_opt) { + diffopts.output_format = stat_opt; + + diff_tree_sha1(parents->sha1[0], sha1, "", &diffopts); + diffcore_std(&diffopts); + if (opt->orderfile) + diffcore_order(opt->orderfile); + diff_flush(&diffopts); + } + } /* find out number of surviving paths */ for (num_paths = 0, p = paths; p; p = p->next) diff --git a/diff.c b/diff.c index cda4aa8f859b5d..f2fff4667d6402 100644 --- a/diff.c +++ b/diff.c @@ -4764,6 +4764,7 @@ void diffcore_fix_diff_index(struct diff_options *options) void diffcore_std(struct diff_options *options) { + /* NOTE please keep the following in sync with diff_tree_combined() */ if (options->skip_stat_unmatch) diffcore_skip_stat_unmatch(options); if (!options->found_follow) { From 22f4c27e68f448d5fce316a73ea3f7bab6aa1268 Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Wed, 9 Apr 2014 16:48:27 +0400 Subject: [PATCH 052/760] mingw: activate alloca Both MSVC and MINGW have alloca(3) definitions in malloc.h, so by moving win32-compat alloca.h from compat/vcbuild/include/ to compat/win32/ , which is included by both MSVC and MINGW CFLAGS, we can make alloca() work on both those Windows environments. In MINGW, malloc.h has explicit check for GNUC and if it is so, defines alloca to __builtin_alloca, so it looks like we don't need to add any code to here-shipped alloca.h to get optimum performance. Compile-tested on Windows in MSysGit. Signed-off-by: Kirill Smelkov Acked-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- compat/{vcbuild/include => win32}/alloca.h | 0 config.mak.uname | 1 + 2 files changed, 1 insertion(+) rename compat/{vcbuild/include => win32}/alloca.h (100%) diff --git a/compat/vcbuild/include/alloca.h b/compat/win32/alloca.h similarity index 100% rename from compat/vcbuild/include/alloca.h rename to compat/win32/alloca.h diff --git a/config.mak.uname b/config.mak.uname index 71602ee9a16951..9967de66a2c7f4 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -480,6 +480,7 @@ ifeq ($(uname_S),NONSTOP_KERNEL) endif ifneq (,$(findstring MINGW,$(uname_S))) pathsep = ; + HAVE_ALLOCA_H = YesPlease NO_PREAD = YesPlease NEEDS_CRYPTO_WITH_SSL = YesPlease NO_LIBGEN_H = YesPlease From 9aa91af0361e3c32fde5f8388dee963838308cd6 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Thu, 10 Apr 2014 21:54:12 +0300 Subject: [PATCH 053/760] wrapper.c: add xpread() similar to xread() It is a common mistake to call read(2)/pread(2) and forget to anticipate that they may return error with EAGAIN/EINTR when the system call is interrupted. We have xread() helper to relieve callers of read(2) from having to worry about it; add xpread() helper to do the same for pread(2). Update the caller in the builtin/index-pack.c and the mmap emulation in compat/. Signed-off-by: Yiannis Marangos Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 2 +- compat/mmap.c | 4 +--- git-compat-util.h | 1 + wrapper.c | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 9e9eb4b74e8335..e7a6b537b4b8c9 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -542,7 +542,7 @@ static void *unpack_data(struct object_entry *obj, do { ssize_t n = (len < 64*1024) ? len : 64*1024; - n = pread(pack_fd, inbuf, n, from); + n = xpread(pack_fd, inbuf, n, from); if (n < 0) die_errno(_("cannot pread pack file")); if (!n) diff --git a/compat/mmap.c b/compat/mmap.c index c9d46d174259f4..7f662fef7bcb40 100644 --- a/compat/mmap.c +++ b/compat/mmap.c @@ -14,7 +14,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of } while (n < length) { - ssize_t count = pread(fd, (char *)start + n, length - n, offset + n); + ssize_t count = xpread(fd, (char *)start + n, length - n, offset + n); if (count == 0) { memset((char *)start+n, 0, length-n); @@ -22,8 +22,6 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of } if (count < 0) { - if (errno == EAGAIN || errno == EINTR) - continue; free(start); errno = EACCES; return MAP_FAILED; diff --git a/git-compat-util.h b/git-compat-util.h index 7776f126d3bd4f..9eec5fb52b6fc8 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -534,6 +534,7 @@ extern void *xcalloc(size_t nmemb, size_t size); extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); extern ssize_t xread(int fd, void *buf, size_t len); extern ssize_t xwrite(int fd, const void *buf, size_t len); +extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset); extern int xdup(int fd); extern FILE *xfdopen(int fd, const char *mode); extern int xmkstemp(char *template); diff --git a/wrapper.c b/wrapper.c index 0cc56368bd8cce..5b3c7fceb34c0a 100644 --- a/wrapper.c +++ b/wrapper.c @@ -174,6 +174,24 @@ ssize_t xwrite(int fd, const void *buf, size_t len) } } +/* + * xpread() is the same as pread(), but it automatically restarts pread() + * operations with a recoverable error (EAGAIN and EINTR). xpread() DOES + * NOT GUARANTEE that "len" bytes is read even if the data is available. + */ +ssize_t xpread(int fd, void *buf, size_t len, off_t offset) +{ + ssize_t nr; + if (len > MAX_IO_SIZE) + len = MAX_IO_SIZE; + while (1) { + nr = pread(fd, buf, len, offset); + if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) + continue; + return nr; + } +} + ssize_t read_in_full(int fd, void *buf, size_t count) { char *p = buf; From 426ddeead6112955dfb50ccf9bb4af05d1ca9082 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Thu, 10 Apr 2014 21:31:21 +0300 Subject: [PATCH 054/760] read-cache.c: verify index file before we opportunistically update it Before we proceed to opportunistically update the index (often done by an otherwise read-only operation like "git status" and "git diff" that internally refreshes the index), we must verify that the current index file is the same as the one that we read earlier before we took the lock on it, in order to avoid a possible race. In the example below git-status does "opportunistic update" and git-rebase updates the index, but the race can happen in general. 1. process A calls git-rebase (or does anything that uses the index) 2. process A applies 1st commit 3. process B calls git-status (or does anything that updates the index) 4. process B reads index 5. process A applies 2nd commit 6. process B takes the lock, then overwrites process A's changes. 7. process A applies 3rd commit As an end result the 3rd commit will have a revert of the 2nd commit. When process B takes the lock, it needs to make sure that the index hasn't changed since step 4. Signed-off-by: Yiannis Marangos Signed-off-by: Junio C Hamano --- cache.h | 3 +++ read-cache.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- wrapper.c | 20 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index ce377e1354a4d0..9244c387c39b3a 100644 --- a/cache.h +++ b/cache.h @@ -279,6 +279,7 @@ struct index_state { initialized : 1; struct hash_table name_hash; struct hash_table dir_hash; + unsigned char sha1[20]; }; extern struct index_state the_index; @@ -1199,6 +1200,8 @@ extern void fsync_or_die(int fd, const char *); extern ssize_t read_in_full(int fd, void *buf, size_t count); extern ssize_t write_in_full(int fd, const void *buf, size_t count); +extern ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); + static inline ssize_t write_str_in_full(int fd, const char *str) { return write_in_full(fd, str, strlen(str)); diff --git a/read-cache.c b/read-cache.c index 33dd676ccbbd24..f4a0d6168b8db2 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1464,6 +1464,7 @@ int read_index_from(struct index_state *istate, const char *path) if (verify_hdr(hdr, mmap_size) < 0) goto unmap; + hashcpy(istate->sha1, (unsigned char *)hdr + mmap_size - 20); istate->version = ntohl(hdr->hdr_version); istate->cache_nr = ntohl(hdr->hdr_entries); istate->cache_alloc = alloc_nr(istate->cache_nr); @@ -1747,6 +1748,50 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce, return result; } +/* + * This function verifies if index_state has the correct sha1 of the + * index file. Don't die if we have any other failure, just return 0. + */ +static int verify_index_from(const struct index_state *istate, const char *path) +{ + int fd; + ssize_t n; + struct stat st; + unsigned char sha1[20]; + + if (!istate->initialized) + return 0; + + fd = open(path, O_RDONLY); + if (fd < 0) + return 0; + + if (fstat(fd, &st)) + goto out; + + if (st.st_size < sizeof(struct cache_header) + 20) + goto out; + + n = pread_in_full(fd, sha1, 20, st.st_size - 20); + if (n != 20) + goto out; + + if (hashcmp(istate->sha1, sha1)) + goto out; + + close(fd); + return 1; + +out: + close(fd); + return 0; +} + +static int verify_index(const struct index_state *istate) +{ + return verify_index_from(istate, get_index_file()); +} + static int has_racy_timestamp(struct index_state *istate) { int entries = istate->cache_nr; @@ -1766,7 +1811,7 @@ static int has_racy_timestamp(struct index_state *istate) void update_index_if_able(struct index_state *istate, struct lock_file *lockfile) { if ((istate->cache_changed || has_racy_timestamp(istate)) && - !write_index(istate, lockfile->fd)) + verify_index(istate) && !write_index(istate, lockfile->fd)) commit_locked_index(lockfile); else rollback_lock_file(lockfile); diff --git a/wrapper.c b/wrapper.c index 5b3c7fceb34c0a..bc1bfb86003cb4 100644 --- a/wrapper.c +++ b/wrapper.c @@ -232,6 +232,26 @@ ssize_t write_in_full(int fd, const void *buf, size_t count) return total; } +ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset) +{ + char *p = buf; + ssize_t total = 0; + + while (count > 0) { + ssize_t loaded = xpread(fd, p, count, offset); + if (loaded < 0) + return -1; + if (loaded == 0) + return total; + count -= loaded; + p += loaded; + total += loaded; + offset += loaded; + } + + return total; +} + int xdup(int fd) { int ret = dup(fd); From 39539495acb24abfb4dee551e3e9f2e696be7abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Tue, 25 Mar 2014 20:41:41 +0700 Subject: [PATCH 055/760] index-pack: work around thread-unsafe pread() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Multi-threaing of index-pack was disabled with c0f8654 (index-pack: Disable threading on cygwin - 2012-06-26), because pread() implementations for Cygwin and MSYS were not thread safe. Recent Cygwin does offer usable pread() and we enabled multi-threading with 103d530f (Cygwin 1.7 has thread-safe pread, 2013-07-19). Work around this problem on platforms with a thread-unsafe pread() emulation by opening one file handle per thread; it would prevent parallel pread() on different file handles from stepping on each other. Also remove NO_THREAD_SAFE_PREAD that was introduced in c0f8654 because it's no longer used anywhere. This workaround is unconditional, even for platforms with thread-safe pread() because the overhead is small (a couple file handles more) and not worth fragmenting the code. Signed-off-by: Nguyễn Thái Ngọc Duy Tested-by: Johannes Sixt Signed-off-by: Junio C Hamano --- Makefile | 7 ------- builtin/index-pack.c | 27 +++++++++++++++++---------- config.mak.uname | 1 - 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index dddaf4f287cf5c..00a70840eb17d7 100644 --- a/Makefile +++ b/Makefile @@ -191,9 +191,6 @@ all:: # Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval # This also implies NO_SETITIMER # -# Define NO_THREAD_SAFE_PREAD if your pread() implementation is not -# thread-safe. (e.g. compat/pread.c or cygwin) -# # Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is # generally faster on your platform than accessing the working directory. # @@ -1341,10 +1338,6 @@ endif ifdef NO_PREAD COMPAT_CFLAGS += -DNO_PREAD COMPAT_OBJS += compat/pread.o - NO_THREAD_SAFE_PREAD = YesPlease -endif -ifdef NO_THREAD_SAFE_PREAD - BASIC_CFLAGS += -DNO_THREAD_SAFE_PREAD endif ifdef NO_FAST_WORKING_DIRECTORY BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 2f37a38fbcdf13..ed489bbe9aab3a 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -40,17 +40,13 @@ struct base_data { int ofs_first, ofs_last; }; -#if !defined(NO_PTHREADS) && defined(NO_THREAD_SAFE_PREAD) -/* pread() emulation is not thread-safe. Disable threading. */ -#define NO_PTHREADS -#endif - struct thread_local { #ifndef NO_PTHREADS pthread_t thread; #endif struct base_data *base_cache; size_t base_cache_used; + int pack_fd; }; /* @@ -91,7 +87,8 @@ static off_t consumed_bytes; static unsigned deepest_delta; static git_SHA_CTX input_ctx; static uint32_t input_crc32; -static int input_fd, output_fd, pack_fd; +static int input_fd, output_fd; +static const char *curr_pack; #ifndef NO_PTHREADS @@ -134,6 +131,7 @@ static inline void unlock_mutex(pthread_mutex_t *mutex) */ static void init_thread(void) { + int i; init_recursive_mutex(&read_mutex); pthread_mutex_init(&counter_mutex, NULL); pthread_mutex_init(&work_mutex, NULL); @@ -141,11 +139,18 @@ static void init_thread(void) pthread_mutex_init(&deepest_delta_mutex, NULL); pthread_key_create(&key, NULL); thread_data = xcalloc(nr_threads, sizeof(*thread_data)); + for (i = 0; i < nr_threads; i++) { + thread_data[i].pack_fd = open(curr_pack, O_RDONLY); + if (thread_data[i].pack_fd == -1) + die_errno(_("unable to open %s"), curr_pack); + } + threads_active = 1; } static void cleanup_thread(void) { + int i; if (!threads_active) return; threads_active = 0; @@ -154,6 +159,8 @@ static void cleanup_thread(void) pthread_mutex_destroy(&work_mutex); if (show_stat) pthread_mutex_destroy(&deepest_delta_mutex); + for (i = 0; i < nr_threads; i++) + close(thread_data[i].pack_fd); pthread_key_delete(key); free(thread_data); } @@ -288,13 +295,13 @@ static const char *open_pack_file(const char *pack_name) output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600); if (output_fd < 0) die_errno(_("unable to create '%s'"), pack_name); - pack_fd = output_fd; + nothread_data.pack_fd = output_fd; } else { input_fd = open(pack_name, O_RDONLY); if (input_fd < 0) die_errno(_("cannot open packfile '%s'"), pack_name); output_fd = -1; - pack_fd = input_fd; + nothread_data.pack_fd = input_fd; } git_SHA1_Init(&input_ctx); return pack_name; @@ -542,7 +549,7 @@ static void *unpack_data(struct object_entry *obj, do { ssize_t n = (len < 64*1024) ? len : 64*1024; - n = pread(pack_fd, inbuf, n, from); + n = pread(get_thread_data()->pack_fd, inbuf, n, from); if (n < 0) die_errno(_("cannot pread pack file")); if (!n) @@ -1490,7 +1497,7 @@ static void show_pack_info(int stat_only) int cmd_index_pack(int argc, const char **argv, const char *prefix) { int i, fix_thin_pack = 0, verify = 0, stat_only = 0; - const char *curr_pack, *curr_index; + const char *curr_index; const char *index_name = NULL, *pack_name = NULL; const char *keep_name = NULL, *keep_msg = NULL; char *index_name_buf = NULL, *keep_name_buf = NULL; diff --git a/config.mak.uname b/config.mak.uname index 7d31fad241761e..db5c249b4ca291 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -158,7 +158,6 @@ ifeq ($(uname_O),Cygwin) NO_SYMLINK_HEAD = YesPlease NO_IPV6 = YesPlease OLD_ICONV = UnfortunatelyYes - NO_THREAD_SAFE_PREAD = YesPlease # There are conflicting reports about this. # On some boxes NO_MMAP is needed, and not so elsewhere. # Try commenting this out if you suspect MMAP is more efficient From cb005c1fdf814d3b65b5b43f5f4fa25aa1bcdf46 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Wed, 16 Apr 2014 10:08:18 +0200 Subject: [PATCH 056/760] send-email: recognize absolute path on Windows On Windows, absolute paths might start with a DOS drive prefix, which these two checks failed to recognize. Unfortunately, we cannot simply use the file_name_is_absolute helper in File::Spec::Functions, because Git for Windows has an MSYS-based Perl, where this helper doesn't grok DOS drive-prefixes. So let's manually check for these in that case, and fall back to the File::Spec-helper on other platforms (e.g Win32 with native Perl) Signed-off-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- git-send-email.perl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index fdb0029b597898..8f5f986e649c14 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1113,6 +1113,18 @@ sub ssl_verify_params { } } +sub file_name_is_absolute { + my ($path) = @_; + + # msys does not grok DOS drive-prefixes + if ($^O eq 'msys') { + return ($path =~ m#^/# || $path =~ m#[a-zA-Z]\:#) + } + + require File::Spec::Functions; + return File::Spec::Functions::file_name_is_absolute($path); +} + # Returns 1 if the message was sent, and 0 otherwise. # In actuality, the whole program dies when there # is an error sending a message. @@ -1197,7 +1209,7 @@ sub send_message { if ($dry_run) { # We don't want to send the email. - } elsif ($smtp_server =~ m#^/#) { + } elsif (file_name_is_absolute($smtp_server)) { my $pid = open my $sm, '|-'; defined $pid or die $!; if (!$pid) { @@ -1271,7 +1283,7 @@ sub send_message { printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject); } else { print (($dry_run ? "Dry-" : "")."OK. Log says:\n"); - if ($smtp_server !~ m#^/#) { + if (!file_name_is_absolute($smtp_server)) { print "Server: $smtp_server\n"; print "MAIL FROM:<$raw_from>\n"; foreach my $entry (@recipients) { From 784f4b6f33afb439a3d95e5751731a88df545889 Mon Sep 17 00:00:00 2001 From: RomanBelinsky Date: Tue, 11 Feb 2014 18:23:02 +0200 Subject: [PATCH 057/760] SVN.pm::parse_svn_date: allow timestamps with a single-digit hour Some broken subversion server gives timestamps with only one digit in the hour part, like this: 2014-01-07T5:01:02.048176Z Loosen the regexp that expected to see two-digit hour, minute and second parts to accept a single-digit hour (but not minute or second). Signed-off-by: Stepan Kasal Signed-off-by: Junio C Hamano --- perl/Git/SVN.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm index a59564fb34fbed..09cff135efd98a 100644 --- a/perl/Git/SVN.pm +++ b/perl/Git/SVN.pm @@ -1321,7 +1321,7 @@ sub get_untracked { sub parse_svn_date { my $date = shift || return '+0000 1970-01-01 00:00:00'; my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T - (\d\d)\:(\d\d)\:(\d\d)\.\d*Z$/x) or + (\d\d?)\:(\d\d)\:(\d\d)\.\d*Z$/x) or croak "Unable to parse date: $date\n"; my $parsed_date; # Set next. From 651ab9f553a1fd8bb847bd42922dacb14f8ec77f Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 16 Apr 2014 11:56:52 -0700 Subject: [PATCH 058/760] sequencer.c: check for lock failure and bail early in fast_forward_to Change fast_forward_to() to check if locking the ref failed, print a nice error message and bail out early. The old code did not check if ref_lock was NULL and relied on the fact that the write_ref_sha1() would safely detect this condition and set the return variable ret to indicate an error. While that is safe, it makes the code harder to read for two reasons: * Inconsistency. Almost all other places we do check the lock for NULL explicitly, so the naive reader is confused "why don't we check here?" * And relying on write_ref_sha1() to detect and return an error for when a previous lock_any_ref_for_update() failed feels obfuscated. This change should not change any functionality or logic aside from adding an extra error message when this condition is triggered (write_ref_sha1() returns an error silently for this condition). Signed-off-by: Ronnie Sahlberg Signed-off-by: Junio C Hamano --- sequencer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sequencer.c b/sequencer.c index bde5f047b01376..0a80c58d1194c3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -281,8 +281,12 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from, exit(1); /* the callee should have complained already */ ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from, 0, NULL); + if (!ref_lock) + return error(_("Failed to lock HEAD during fast_forward_to")); + strbuf_addf(&sb, "%s: fast-forward", action_name(opts)); ret = write_ref_sha1(ref_lock, to, sb.buf); + strbuf_release(&sb); return ret; } From 55a5c8d72b03ad3727b89900069a1d58664fe5e4 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Wed, 16 Apr 2014 11:56:53 -0700 Subject: [PATCH 059/760] commit.c: check for lock error and return early Move the check for the lock failure to happen immediately after lock_any_ref_for_update(). Previously the lock and the check-if-lock-failed was separated by a handful of string manipulation statements. Moving the check to occur immediately after the failed lock makes the code slightly easier to read and makes it follow the pattern of try-to-take-a-lock(); if (check-if-lock-failed) { error(); } Signed-off-by: Ronnie Sahlberg Signed-off-by: Junio C Hamano --- builtin/commit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 9cfef6c6cca619..f0b790640d6324 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1672,6 +1672,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix) ? NULL : current_head->object.sha1, 0, NULL); + if (!ref_lock) { + rollback_index_files(); + die(_("cannot lock HEAD ref")); + } nl = strchr(sb.buf, '\n'); if (nl) @@ -1681,10 +1685,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix) strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg)); strbuf_insert(&sb, strlen(reflog_msg), ": ", 2); - if (!ref_lock) { - rollback_index_files(); - die(_("cannot lock HEAD ref")); - } if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) { rollback_index_files(); die(_("cannot update HEAD ref")); From ae049c955c8858899467f6c5c0259c48a5294385 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 19 Apr 2014 15:17:25 -0400 Subject: [PATCH 060/760] run_external_diff: use an argv_array for the environment We currently use static buffers and a static array for formatting the environment passed to the external diff. There's nothing wrong in the code, but it is much easier to verify that it is correct if we use a dynamic argv_array. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/diff.c b/diff.c index 76ae3790324c6e..c7b433ffcd8a8d 100644 --- a/diff.c +++ b/diff.c @@ -2908,11 +2908,9 @@ static void run_external_diff(const char *pgm, struct diff_options *o) { struct argv_array argv = ARGV_ARRAY_INIT; + struct argv_array env = ARGV_ARRAY_INIT; int retval; struct diff_queue_struct *q = &diff_queued_diff; - const char *env[3] = { NULL }; - char env_counter[50]; - char env_total[50]; if (one && two) { struct diff_tempfile *temp_one, *temp_two; @@ -2937,15 +2935,13 @@ static void run_external_diff(const char *pgm, } fflush(NULL); - env[0] = env_counter; - snprintf(env_counter, sizeof(env_counter), "GIT_DIFF_PATH_COUNTER=%d", - ++o->diff_path_counter); - env[1] = env_total; - snprintf(env_total, sizeof(env_total), "GIT_DIFF_PATH_TOTAL=%d", q->nr); + argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); + argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); - retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env); + retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv); remove_tempfile(); argv_array_clear(&argv); + argv_array_clear(&env); if (retval) { fprintf(stderr, "external diff died, stopping at %s.\n", name); exit(1); From 89294d143d42db2540ec587d0bce20c6c7718051 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 19 Apr 2014 15:19:19 -0400 Subject: [PATCH 061/760] run_external_diff: clean up error handling When the external diff reports an error, we try to clean up and die. However, we can make this process a bit simpler: 1. We do not need to bother freeing memory, since we are about to exit. Nor do we need to clean up our tempfiles, since the atexit() handler will do it for us. So we can die as soon as we see the error. 3. We can just call die() rather than fprintf/exit. This does technically change our exit code, but the exit code of "1" is not meaningful here. In fact, it is probably wrong, since "1" from diff usually means "completed successfully, but there were differences". And while we're there, we can mark the error message for translation, and drop the full stop at the end to make it more like our other messages. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 9 +++------ t/t7800-difftool.sh | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/diff.c b/diff.c index c7b433ffcd8a8d..174f146d0d89e0 100644 --- a/diff.c +++ b/diff.c @@ -2909,7 +2909,6 @@ static void run_external_diff(const char *pgm, { struct argv_array argv = ARGV_ARRAY_INIT; struct argv_array env = ARGV_ARRAY_INIT; - int retval; struct diff_queue_struct *q = &diff_queued_diff; if (one && two) { @@ -2938,14 +2937,12 @@ static void run_external_diff(const char *pgm, argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); - retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv); + if (run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv)) + die(_("external diff died, stopping at %s"), name); + remove_tempfile(); argv_array_clear(&argv); argv_array_clear(&env); - if (retval) { - fprintf(stderr, "external diff died, stopping at %s.\n", name); - exit(1); - } } static int similarity_index(struct diff_filepair *p) diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 5a193c500d282c..dc30a514bf681d 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -58,7 +58,7 @@ test_expect_success PERL 'custom tool commands override built-ins' ' test_expect_success PERL 'difftool ignores bad --tool values' ' : >expect && - test_expect_code 1 \ + test_must_fail \ git difftool --no-prompt --tool=bad-tool branch >actual && test_cmp expect actual ' From 5b88caa417ab221c8f8576332fba8d41dd3986d7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 19 Apr 2014 15:19:30 -0400 Subject: [PATCH 062/760] run_external_diff: drop fflush(NULL) This fflush was added in d5535ec (Use run_command() to spawn external diff programs instead of fork/exec., 2007-10-19), because flushing buffers before forking is a good habit. But later, 7d0b18a (Add output flushing before fork(), 2008-08-04) added it to the generic run-command interface, meaning that our flush here is redundant. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 1 - 1 file changed, 1 deletion(-) diff --git a/diff.c b/diff.c index 174f146d0d89e0..4bad556812898b 100644 --- a/diff.c +++ b/diff.c @@ -2932,7 +2932,6 @@ static void run_external_diff(const char *pgm, argv_array_push(&argv, pgm); argv_array_push(&argv, name); } - fflush(NULL); argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); From 0d4217d92e3043e23a8960519a51cc7a36ed8914 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 19 Apr 2014 15:20:46 -0400 Subject: [PATCH 063/760] run_external_diff: hoist common bits out of conditional Whether we have diff_filespecs to give to the diff command or not, we always are going to run the program and pass it the pathname. Let's pull that duplicated part out of the conditional to make it more obvious. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/diff.c b/diff.c index 4bad556812898b..a360ab5063e602 100644 --- a/diff.c +++ b/diff.c @@ -2911,13 +2911,14 @@ static void run_external_diff(const char *pgm, struct argv_array env = ARGV_ARRAY_INIT; struct diff_queue_struct *q = &diff_queued_diff; + argv_array_push(&argv, pgm); + argv_array_push(&argv, name); + if (one && two) { struct diff_tempfile *temp_one, *temp_two; const char *othername = (other ? other : name); temp_one = prepare_temp_file(name, one); temp_two = prepare_temp_file(othername, two); - argv_array_push(&argv, pgm); - argv_array_push(&argv, name); argv_array_push(&argv, temp_one->name); argv_array_push(&argv, temp_one->hex); argv_array_push(&argv, temp_one->mode); @@ -2928,9 +2929,6 @@ static void run_external_diff(const char *pgm, argv_array_push(&argv, other); argv_array_push(&argv, xfrm_msg); } - } else { - argv_array_push(&argv, pgm); - argv_array_push(&argv, name); } argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); From f3efe78782b36d68dc71a4f48a7bd3381c6b5669 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 19 Apr 2014 15:22:25 -0400 Subject: [PATCH 064/760] run_external_diff: refactor cmdline setup logic The current logic makes it hard to see what gets put onto the command line in which cases. Pulling out a helper function lets us see that we have two sets of file data, and the second set either uses the original name, or the "other" renamed/copy name. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/diff.c b/diff.c index a360ab5063e602..680f52db4b867f 100644 --- a/diff.c +++ b/diff.c @@ -2892,6 +2892,16 @@ static struct diff_tempfile *prepare_temp_file(const char *name, return temp; } +static void add_external_diff_name(struct argv_array *argv, + const char *name, + struct diff_filespec *df) +{ + struct diff_tempfile *temp = prepare_temp_file(name, df); + argv_array_push(argv, temp->name); + argv_array_push(argv, temp->hex); + argv_array_push(argv, temp->mode); +} + /* An external diff command takes: * * diff-cmd name infile1 infile1-sha1 infile1-mode \ @@ -2915,17 +2925,11 @@ static void run_external_diff(const char *pgm, argv_array_push(&argv, name); if (one && two) { - struct diff_tempfile *temp_one, *temp_two; - const char *othername = (other ? other : name); - temp_one = prepare_temp_file(name, one); - temp_two = prepare_temp_file(othername, two); - argv_array_push(&argv, temp_one->name); - argv_array_push(&argv, temp_one->hex); - argv_array_push(&argv, temp_one->mode); - argv_array_push(&argv, temp_two->name); - argv_array_push(&argv, temp_two->hex); - argv_array_push(&argv, temp_two->mode); - if (other) { + add_external_diff_name(&argv, name, one); + if (!other) + add_external_diff_name(&argv, name, two); + else { + add_external_diff_name(&argv, other, two); argv_array_push(&argv, other); argv_array_push(&argv, xfrm_msg); } From 8b2f86a76146ebbd4ac4f9c2182b3f7bda4492ff Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:23 -0500 Subject: [PATCH 065/760] fast-export: improve argument parsing We don't want to pass arguments specific to fast-export to setup_revisions. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/fast-export.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index b8d8a3aaf9ee82..bc3490cd56ebea 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -701,8 +701,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) revs.topo_order = 1; revs.show_source = 1; revs.rewrite_parents = 1; + argc = parse_options(argc, argv, prefix, options, fast_export_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); argc = setup_revisions(argc, argv, &revs, NULL); - argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0); if (argc > 1) usage_with_options (fast_export_usage, options); From 03e9010c66adfe5e1693eae039e6754d925b7bf4 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:24 -0500 Subject: [PATCH 066/760] fast-export: add new --refspec option So that we can convert the exported ref names. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- Documentation/git-fast-export.txt | 4 ++++ builtin/fast-export.c | 32 +++++++++++++++++++++++++++++++ t/t9350-fast-export.sh | 7 +++++++ 3 files changed, 43 insertions(+) diff --git a/Documentation/git-fast-export.txt b/Documentation/git-fast-export.txt index 85f1f30fdf5c0a..221506b04ba55f 100644 --- a/Documentation/git-fast-export.txt +++ b/Documentation/git-fast-export.txt @@ -105,6 +105,10 @@ marks the same across runs. in the commit (as opposed to just listing the files which are different from the commit's first parent). +--refspec:: + Apply the specified refspec to each ref exported. Multiple of them can + be specified. + [...]:: A list of arguments, acceptable to 'git rev-parse' and 'git rev-list', that specifies the specific objects and references diff --git a/builtin/fast-export.c b/builtin/fast-export.c index bc3490cd56ebea..ad9c17e8e78bb8 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -17,6 +17,7 @@ #include "utf8.h" #include "parse-options.h" #include "quote.h" +#include "remote.h" static const char *fast_export_usage[] = { N_("git fast-export [rev-list-opts]"), @@ -31,6 +32,8 @@ static int use_done_feature; static int no_data; static int full_tree; static struct string_list extra_refs = STRING_LIST_INIT_NODUP; +static struct refspec *refspecs; +static int refspecs_nr; static int parse_opt_signed_tag_mode(const struct option *opt, const char *arg, int unset) @@ -525,6 +528,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1) continue; + if (refspecs) { + char *private; + private = apply_refspecs(refspecs, refspecs_nr, full_name); + if (private) { + free(full_name); + full_name = private; + } + } + commit = get_commit(e, full_name); if (!commit) { warning("%s: Unexpected object of type %s, skipping.", @@ -668,6 +680,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) struct commit *commit; char *export_filename = NULL, *import_filename = NULL; uint32_t lastimportid; + struct string_list refspecs_list = STRING_LIST_INIT_NODUP; struct option options[] = { OPT_INTEGER(0, "progress", &progress, N_("show progress after objects")), @@ -688,6 +701,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "use-done-feature", &use_done_feature, N_("Use the done feature to terminate the stream")), OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")), + OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"), + N_("Apply refspec to exported refs")), OPT_END() }; @@ -707,6 +722,21 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) if (argc > 1) usage_with_options (fast_export_usage, options); + if (refspecs_list.nr) { + const char **refspecs_str; + int i; + + refspecs_str = xmalloc(sizeof(*refspecs_str) * refspecs_list.nr); + for (i = 0; i < refspecs_list.nr; i++) + refspecs_str[i] = refspecs_list.items[i].string; + + refspecs_nr = refspecs_list.nr; + refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str); + + string_list_clear(&refspecs_list, 1); + free(refspecs_str); + } + if (use_done_feature) printf("feature done\n"); @@ -741,5 +771,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) if (use_done_feature) printf("done\n"); + free_refspec(refspecs_nr, refspecs); + return 0; } diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 2312dec8f096fe..3d475af173fffb 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -504,4 +504,11 @@ test_expect_success 'refs are updated even if no commits need to be exported' ' test_cmp expected actual ' +test_expect_success 'use refspec' ' + git fast-export --refspec refs/heads/master:refs/heads/foobar master | \ + grep "^commit " | sort | uniq > actual && + echo "commit refs/heads/foobar" > expected && + test_cmp expected actual +' + test_done From d98c81538015630603fd20f6e08e960555a38c52 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:25 -0500 Subject: [PATCH 067/760] transport-helper: add support for old:new refspec By using fast-export's new --refspec option. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- t/t5801-remote-helpers.sh | 2 +- transport-helper.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 25fd2e7f46cb55..52b3c99478a278 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -87,7 +87,7 @@ test_expect_success 'push new branch by name' ' compare_refs local HEAD server refs/heads/new-name ' -test_expect_failure 'push new branch with old:new refspec' ' +test_expect_success 'push new branch with old:new refspec' ' (cd local && git push origin new-name:new-refspec ) && diff --git a/transport-helper.c b/transport-helper.c index 86e1679c1e0e1e..3f45c478fa8a77 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -856,7 +856,7 @@ static int push_refs_with_export(struct transport *transport, struct ref *ref; struct child_process *helper, exporter; struct helper_data *data = transport->data; - struct string_list revlist_args = STRING_LIST_INIT_NODUP; + struct string_list revlist_args = STRING_LIST_INIT_DUP; struct strbuf buf = STRBUF_INIT; if (!data->refspecs) @@ -894,8 +894,13 @@ static int push_refs_with_export(struct transport *transport, free(private); if (ref->peer_ref) { - if (strcmp(ref->peer_ref->name, ref->name)) - die("remote-helpers do not support old:new syntax"); + if (strcmp(ref->name, ref->peer_ref->name)) { + struct strbuf buf = STRBUF_INIT; + strbuf_addf(&buf, "%s:%s", ref->peer_ref->name, ref->name); + string_list_append(&revlist_args, "--refspec"); + string_list_append(&revlist_args, buf.buf); + strbuf_release(&buf); + } string_list_append(&revlist_args, ref->peer_ref->name); } } @@ -903,6 +908,8 @@ static int push_refs_with_export(struct transport *transport, if (get_exporter(transport, &exporter, &revlist_args)) die("Couldn't run fast-export"); + string_list_clear(&revlist_args, 1); + if (finish_command(&exporter)) die("Error while running fast-export"); push_update_refs_status(data, remote_refs, flags); From 9193f742350d1b97e32b0687d1577dc2b2a0d713 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:26 -0500 Subject: [PATCH 068/760] transport-helper: add support to push symbolic refs For example 'HEAD'. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- t/t5801-remote-helpers.sh | 8 ++++++++ transport-helper.c | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 52b3c99478a278..828866930d40b5 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -94,6 +94,14 @@ test_expect_success 'push new branch with old:new refspec' ' compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'push new branch with HEAD:new refspec' ' + (cd local && + git checkout new-name + git push origin HEAD:new-refspec-2 + ) && + compare_refs local HEAD server refs/heads/new-refspec-2 +' + test_expect_success 'forced push' ' (cd local && git checkout -b force-test && diff --git a/transport-helper.c b/transport-helper.c index 3f45c478fa8a77..f74eb57046868d 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -896,7 +896,16 @@ static int push_refs_with_export(struct transport *transport, if (ref->peer_ref) { if (strcmp(ref->name, ref->peer_ref->name)) { struct strbuf buf = STRBUF_INIT; - strbuf_addf(&buf, "%s:%s", ref->peer_ref->name, ref->name); + const char *name; + int flag; + + /* Follow symbolic refs (mainly for HEAD). */ + name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag); + if (!name || !(flag & REF_ISSYMREF)) + name = ref->peer_ref->name; + + strbuf_addf(&buf, "%s:%s", name, ref->name); + string_list_append(&revlist_args, "--refspec"); string_list_append(&revlist_args, buf.buf); strbuf_release(&buf); From 4ee1b225b99f155cc9372397b5e120c2c0eee2bf Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:27 -0500 Subject: [PATCH 069/760] fast-import: add support to delete refs Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- Documentation/git-fast-import.txt | 3 +++ fast-import.c | 13 ++++++++++--- t/t9300-fast-import.sh | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index fd22a9a0c13123..c32a9a5aeed233 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used. * Any valid Git SHA-1 expression that resolves to a commit. See ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details. +* The special null SHA-1 (40 zeros) specifies that the branch is to be + removed. + The special case of restarting an incremental import from the current branch value should be written as: ---- diff --git a/fast-import.c b/fast-import.c index fb4738d373a5a1..6707a66471f203 100644 --- a/fast-import.c +++ b/fast-import.c @@ -248,6 +248,7 @@ struct branch { uintmax_t last_commit; uintmax_t num_notes; unsigned active : 1; + unsigned delete : 1; unsigned pack_id : PACK_ID_BITS; unsigned char sha1[20]; }; @@ -1681,10 +1682,13 @@ static int update_branch(struct branch *b) struct ref_lock *lock; unsigned char old_sha1[20]; - if (is_null_sha1(b->sha1)) - return 0; if (read_ref(b->name, old_sha1)) hashclr(old_sha1); + if (is_null_sha1(b->sha1)) { + if (b->delete) + delete_ref(b->name, old_sha1, 0); + return 0; + } lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL); if (!lock) return error("Unable to lock %s", b->name); @@ -2611,8 +2615,11 @@ static int parse_from(struct branch *b) free(buf); } else parse_from_existing(b); - } else if (!get_sha1(from, b->sha1)) + } else if (!get_sha1(from, b->sha1)) { parse_from_existing(b); + if (is_null_sha1(b->sha1)) + b->delete = 1; + } else die("Invalid ref name or SHA1 expression: %s", from); diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 27263dfb80420a..5fc9ef262ac129 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' ' test_cmp expect actual ' +test_expect_success 'T: delete branch' ' + git branch to-delete && + git fast-import <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + EOF + test_must_fail git rev-parse --verify refs/heads/to-delete +' + +test_expect_success 'T: empty reset doesnt delete branch' ' + git branch not-to-delete && + git fast-import <<-EOF && + reset refs/heads/not-to-delete + EOF + git show-ref && + git rev-parse --verify refs/heads/not-to-delete +' + test_done From 60ed26438c909fd273528e67b399ee6ca4028e1e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:28 -0500 Subject: [PATCH 070/760] fast-export: add support to delete refs Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/fast-export.c | 14 ++++++++++++++ t/t9350-fast-export.sh | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/builtin/fast-export.c b/builtin/fast-export.c index ad9c17e8e78bb8..ef4481615fd2f4 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -673,6 +673,19 @@ static void import_marks(char *input_file) fclose(f); } +static void handle_deletes(void) +{ + int i; + for (i = 0; i < refspecs_nr; i++) { + struct refspec *refspec = &refspecs[i]; + if (*refspec->src) + continue; + + printf("reset %s\nfrom %s\n\n", + refspec->dst, sha1_to_hex(null_sha1)); + } +} + int cmd_fast_export(int argc, const char **argv, const char *prefix) { struct rev_info revs; @@ -764,6 +777,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) } handle_tags_and_duplicates(); + handle_deletes(); if (export_filename && lastimportid != last_idnum) export_marks(export_filename); diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 3d475af173fffb..66c8b0a371e37f 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -511,4 +511,15 @@ test_expect_success 'use refspec' ' test_cmp expected actual ' +test_expect_success 'delete refspec' ' + git branch to-delete && + git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual && + cat > expected <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + + EOF + test_cmp expected actual +' + test_done From f3d0376356756c55a85a3d745858a42c26956e74 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:29 -0500 Subject: [PATCH 071/760] transport-helper: add support to delete branches For remote-helpers that use 'export' to push. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- t/t5801-remote-helpers.sh | 8 ++++++++ transport-helper.c | 24 +++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 828866930d40b5..aec924b2e1d669 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -102,6 +102,14 @@ test_expect_success 'push new branch with HEAD:new refspec' ' compare_refs local HEAD server refs/heads/new-refspec-2 ' +test_expect_success 'push delete branch' ' + (cd local && + git push origin :new-name + ) && + test_must_fail git --git-dir="server/.git" \ + rev-parse --verify refs/heads/new-name +' + test_expect_success 'forced push' ' (cd local && git checkout -b force-test && diff --git a/transport-helper.c b/transport-helper.c index f74eb57046868d..36fbf9349e0847 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -882,9 +882,6 @@ static int push_refs_with_export(struct transport *transport, char *private; unsigned char sha1[20]; - if (ref->deletion) - die("remote-helpers do not support ref deletion"); - private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name); if (private && !get_sha1(private, sha1)) { strbuf_addf(&buf, "^%s", private); @@ -896,21 +893,26 @@ static int push_refs_with_export(struct transport *transport, if (ref->peer_ref) { if (strcmp(ref->name, ref->peer_ref->name)) { struct strbuf buf = STRBUF_INIT; - const char *name; - int flag; - /* Follow symbolic refs (mainly for HEAD). */ - name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag); - if (!name || !(flag & REF_ISSYMREF)) - name = ref->peer_ref->name; + if (!ref->deletion) { + const char *name; + int flag; + + /* Follow symbolic refs (mainly for HEAD). */ + name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag); + if (!name || !(flag & REF_ISSYMREF)) + name = ref->peer_ref->name; - strbuf_addf(&buf, "%s:%s", name, ref->name); + strbuf_addf(&buf, "%s:%s", name, ref->name); + } else + strbuf_addf(&buf, ":%s", ref->name); string_list_append(&revlist_args, "--refspec"); string_list_append(&revlist_args, buf.buf); strbuf_release(&buf); } - string_list_append(&revlist_args, ref->peer_ref->name); + if (!ref->deletion) + string_list_append(&revlist_args, ref->peer_ref->name); } } From e143ef4f6b08e0f948180f28ad3ba77c9a2e0a61 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 13:59:30 -0500 Subject: [PATCH 072/760] transport-helper: remove unnecessary strbuf resets Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- transport-helper.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index 36fbf9349e0847..a90094d4a3b613 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -876,8 +876,6 @@ static int push_refs_with_export(struct transport *transport, write_constant(helper->in, "export\n"); - strbuf_reset(&buf); - for (ref = remote_refs; ref; ref = ref->next) { char *private; unsigned char sha1[20]; @@ -892,8 +890,6 @@ static int push_refs_with_export(struct transport *transport, if (ref->peer_ref) { if (strcmp(ref->name, ref->peer_ref->name)) { - struct strbuf buf = STRBUF_INIT; - if (!ref->deletion) { const char *name; int flag; From 27bd38d4e5a44da233a9e7d01c6a518aba355297 Mon Sep 17 00:00:00 2001 From: "Luis R. Rodriguez" Date: Mon, 21 Apr 2014 17:47:56 -0700 Subject: [PATCH 073/760] git.c: treat RUN_SETUP_GENTLY and RUN_SETUP as mutually exclusive This saves us a few branches when RUN_SETUP is set up. Signed-off-by: Luis R. Rodriguez Signed-off-by: Junio C Hamano --- git.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git.c b/git.c index 7cf2953eff47ca..32f4f6cb899c8b 100644 --- a/git.c +++ b/git.c @@ -290,7 +290,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) if (!help) { if (p->option & RUN_SETUP) prefix = setup_git_directory(); - if (p->option & RUN_SETUP_GENTLY) { + else if (p->option & RUN_SETUP_GENTLY) { int nongit_ok; prefix = setup_git_directory_gently(&nongit_ok); } From 7c147b77d34f072c40b912fafba499727921fa6e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 19:24:20 -0500 Subject: [PATCH 074/760] mergetools: add vimdiff3 mode It's similar to the default, except that the other windows are hidden. This ensures that removed/added colors are still visible on the main merge window, but the other windows not visible. Specially useful with merge.conflictstyle=diff3. Signed-off-by: Felipe Contreras Acked-by: David Aguilar Signed-off-by: Junio C Hamano --- mergetools/gvimdiff3 | 1 + mergetools/vimdiff | 14 ++++++++++++-- mergetools/vimdiff3 | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 mergetools/gvimdiff3 create mode 100644 mergetools/vimdiff3 diff --git a/mergetools/gvimdiff3 b/mergetools/gvimdiff3 new file mode 100644 index 00000000000000..04a5bb0ea84842 --- /dev/null +++ b/mergetools/gvimdiff3 @@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/vimdiff" diff --git a/mergetools/vimdiff b/mergetools/vimdiff index 39d032771b8525..1ddfbfcd782d3b 100644 --- a/mergetools/vimdiff +++ b/mergetools/vimdiff @@ -20,16 +20,26 @@ merge_cmd () { "$merge_tool_path" -f -d -c 'wincmd l' \ "$LOCAL" "$MERGED" "$REMOTE" ;; + gvimdiff3|vimdiff3) + if $base_present + then + "$merge_tool_path" -f -d -c 'hid | hid | hid' \ + "$LOCAL" "$REMOTE" "$BASE" "$MERGED" + else + "$merge_tool_path" -f -d -c 'hid | hid' \ + "$LOCAL" "$REMOTE" "$MERGED" + fi + ;; esac check_unchanged } translate_merge_tool_path() { case "$1" in - gvimdiff|gvimdiff2) + gvimdiff|gvimdiff2|gvimdiff3) echo gvim ;; - vimdiff|vimdiff2) + vimdiff|vimdiff2|vimdiff3) echo vim ;; esac diff --git a/mergetools/vimdiff3 b/mergetools/vimdiff3 new file mode 100644 index 00000000000000..04a5bb0ea84842 --- /dev/null +++ b/mergetools/vimdiff3 @@ -0,0 +1 @@ +. "$MERGE_TOOLS_DIR/vimdiff" From 4ecc63d7f982aa65038048bcdaf49e99b428b028 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 19:17:34 -0500 Subject: [PATCH 075/760] mergetool: run prompt only if guessed tool It's annoying to see the prompt: Hit return to start merge resolution tool (foo): Every time the user does 'git mergetool' even if the user already configured 'foo' as the wanted tool. Display this prompt only when the user hasn't explicitly configured a tool. Signed-off-by: Felipe Contreras Acked-by: David Aguilar Signed-off-by: Junio C Hamano --- git-mergetool.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/git-mergetool.sh b/git-mergetool.sh index 332528ff455611..d08dc92589b366 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -277,7 +277,7 @@ merge_file () { echo "Normal merge conflict for '$MERGED':" describe_file "$local_mode" "local" "$LOCAL" describe_file "$remote_mode" "remote" "$REMOTE" - if "$prompt" = true + if test "$guessed_merge_tool" = true || test "$prompt" = true then printf "Hit return to start merge resolution tool (%s): " "$merge_tool" read ans || return 1 @@ -315,7 +315,8 @@ merge_file () { return 0 } -prompt=$(git config --bool mergetool.prompt || echo true) +prompt=$(git config --bool mergetool.prompt) +guessed_merge_tool=false while test $# != 0 do @@ -373,7 +374,14 @@ prompt_after_failed_merge () { if test -z "$merge_tool" then - merge_tool=$(get_merge_tool "$merge_tool") || exit + # Check if a merge tool has been configured + merge_tool=$(get_configured_merge_tool) + # Try to guess an appropriate merge tool if no tool has been set. + if test -z "$merge_tool" + then + merge_tool=$(guess_merge_tool) || exit + guessed_merge_tool=true + fi fi merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)" merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)" From a01f7f2ba0e73ffbee0fa1ec9a5a78f276cc173d Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 20 Apr 2014 19:17:33 -0500 Subject: [PATCH 076/760] merge: enable defaulttoupstream by default There's no point in this: % git merge fatal: No commit specified and merge.defaultToUpstream not set. We know the most likely scenario is that the user wants to merge the upstream, and if not, he can set merge.defaultToUpstream to false. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- Documentation/git-merge.txt | 5 ++--- builtin/merge.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index a3c1fa332abb8d..cf2c374b710673 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -101,9 +101,8 @@ commit or stash your changes before running 'git merge'. Specifying more than one commit will create a merge with more than two parents (affectionately called an Octopus merge). + -If no commit is given from the command line, and if `merge.defaultToUpstream` -configuration variable is set, merge the remote-tracking branches -that the current branch is configured to use as its upstream. +If no commit is given from the command line, merge the remote-tracking +branches that the current branch is configured to use as its upstream. See also the configuration section of this manual page. diff --git a/builtin/merge.c b/builtin/merge.c index 66d8843301b22a..1fc9319d8f06f2 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -63,7 +63,7 @@ static int verbosity; static int allow_rerere_auto; static int abort_current_merge; static int show_progress = -1; -static int default_to_upstream; +static int default_to_upstream = 1; static const char *sign_commit; static struct strategy all_strategy[] = { From bccce0f8099fac6bcc80914726ddf43ca544b3c1 Mon Sep 17 00:00:00 2001 From: Jiang Xin Date: Mon, 21 Apr 2014 14:02:03 +0800 Subject: [PATCH 077/760] blame: fix broken time_buf paddings in relative timestamp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Command `git blame --date relative` aligns the date field with a fixed-width (defined by blame_date_width), and if time_str is shorter than that, it adds spaces for padding. But there are two bugs in the following codes: time_len = strlen(time_str); ... memset(time_buf + time_len, ' ', blame_date_width - time_len); 1. The type of blame_date_width is size_t, which is unsigned. If time_len is greater than blame_date_width, the result of "blame_date_width - time_len" will never be a negative number, but a really big positive number, and will cause memory overwrite. This bug can be triggered if either l10n message for function show_date_relative() in date.c is longer than 30 characters, then `git blame --date relative` may exit abnormally. 2. When show blame information with relative time, the UTF-8 characters in time_str will break the alignment of columns after the date field. This is because the time_buf padding with spaces should have a constant display width, not a fixed strlen size. So we should call utf8_strwidth() instead of strlen() for width calibration. Helped-by: Nguyễn Thái Ngọc Duy Helped-by: Eric Sunshine Signed-off-by: Jiang Xin Signed-off-by: Junio C Hamano --- builtin/blame.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 88cb7997274de6..35e95db15dc0b6 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1556,22 +1556,29 @@ static void assign_blame(struct scoreboard *sb, int opt) static const char *format_time(unsigned long time, const char *tz_str, int show_raw_time) { - static char time_buf[128]; + static struct strbuf time_buf = STRBUF_INIT; + strbuf_reset(&time_buf); if (show_raw_time) { - snprintf(time_buf, sizeof(time_buf), "%lu %s", time, tz_str); + strbuf_addf(&time_buf, "%lu %s", time, tz_str); } else { const char *time_str; - int time_len; + size_t time_width; int tz; tz = atoi(tz_str); time_str = show_date(time, tz, blame_date_mode); - time_len = strlen(time_str); - memcpy(time_buf, time_str, time_len); - memset(time_buf + time_len, ' ', blame_date_width - time_len); + strbuf_addstr(&time_buf, time_str); + /* + * Add space paddings to time_buf to display a fixed width + * string, and use time_width for display width calibration. + */ + for (time_width = utf8_strwidth(time_str); + time_width < blame_date_width; + time_width++) + strbuf_addch(&time_buf, ' '); } - return time_buf; + return time_buf.buf; } #define OUTPUT_ANNOTATE_COMPAT 001 From dd75553b357d4483d2b58a9e1ac86352f3d2e103 Mon Sep 17 00:00:00 2001 From: Jiang Xin Date: Tue, 22 Apr 2014 22:39:10 +0800 Subject: [PATCH 078/760] blame: dynamic blame_date_width for different locales When show date in relative date format for git-blame, the max display width of datetime is set as the length of the string "Thu Oct 19 16:00:04 2006 -0700" (30 characters long). But actually the max width for C locale is only 22 (the length of string "x years, xx months ago"). And for other locale, it maybe smaller. E.g. For Chinese locale, only needs a half (16-character width). Set blame_date_width as the display width of _("4 years, 11 months ago"), so that translators can make the choice. Helped-by: Junio C Hamano Signed-off-by: Jiang Xin Signed-off-by: Junio C Hamano --- builtin/blame.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/builtin/blame.c b/builtin/blame.c index 35e95db15dc0b6..128fc64d64f46a 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2338,7 +2338,14 @@ int cmd_blame(int argc, const char **argv, const char *prefix) blame_date_width = sizeof("2006-10-19"); break; case DATE_RELATIVE: - /* "normal" is used as the fallback for "relative" */ + /* TRANSLATORS: This string is used to tell us the maximum + display width for a relative timestamp in "git blame" + output. For C locale, "4 years, 11 months ago", which + takes 22 places, is the longest among various forms of + relative timestamps, but your language may need more or + fewer display columns. */ + blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */ + break; case DATE_LOCAL: case DATE_NORMAL: blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700"); From f24ecf5998a6c913ea6111dc0650c91165149264 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 23 Apr 2014 09:37:38 -0700 Subject: [PATCH 079/760] send-email: windows drive prefix (e.g. C:) appears only at the beginning Tighten the regexp used in the "file_name_is_absolute" replacement used on msys to declare that only "[a-zA-Z]:" that appear at the very beginning is a path with a drive-prefix. Signed-off-by: Junio C Hamano --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 8f5f986e649c14..abd62b484cdaef 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1118,7 +1118,7 @@ sub file_name_is_absolute { # msys does not grok DOS drive-prefixes if ($^O eq 'msys') { - return ($path =~ m#^/# || $path =~ m#[a-zA-Z]\:#) + return ($path =~ m#^/# || $path =~ m#^[a-zA-Z]\:#) } require File::Spec::Functions; From 9bfeaa0bcf2d7150836b583196e18f973c3be17f Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:43:53 -0700 Subject: [PATCH 080/760] t9365-continuing-queries.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- contrib/mw-to-git/t/t9365-continuing-queries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/mw-to-git/t/t9365-continuing-queries.sh b/contrib/mw-to-git/t/t9365-continuing-queries.sh index 27e267f5329749..016454749f8dfa 100755 --- a/contrib/mw-to-git/t/t9365-continuing-queries.sh +++ b/contrib/mw-to-git/t/t9365-continuing-queries.sh @@ -9,7 +9,7 @@ test_check_precond test_expect_success 'creating page w/ >500 revisions' ' wiki_reset && - for i in `test_seq 501` + for i in $(test_seq 501) do echo "creating revision $i" && wiki_editpage foo "revision $i
" true From 0eca37c63a1e03e4f33366157eb406c8182bf0e9 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:43:54 -0700 Subject: [PATCH 081/760] test-gitmw-lib.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- contrib/mw-to-git/t/test-gitmw-lib.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/mw-to-git/t/test-gitmw-lib.sh b/contrib/mw-to-git/t/test-gitmw-lib.sh index 3372b2af346ac2..c783752e02041e 100755 --- a/contrib/mw-to-git/t/test-gitmw-lib.sh +++ b/contrib/mw-to-git/t/test-gitmw-lib.sh @@ -90,7 +90,7 @@ test_diff_directories () { # # Check that contains exactly files test_contains_N_files () { - if test `ls -- "$1" | wc -l` -ne "$2"; then + if test $(ls -- "$1" | wc -l) -ne "$2"; then echo "directory $1 should contain $2 files" echo "it contains these files:" ls "$1" @@ -341,10 +341,10 @@ wiki_install () { "http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/"\ "$MW_FILENAME. "\ "Please fix your connection and launch the script again." - echo "$MW_FILENAME downloaded in `pwd`. "\ + echo "$MW_FILENAME downloaded in $(pwd). "\ "You can delete it later if you want." else - echo "Reusing existing $MW_FILENAME downloaded in `pwd`." + echo "Reusing existing $MW_FILENAME downloaded in $(pwd)." fi archive_abs_path=$(pwd)/$MW_FILENAME cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" || From 5c00acdd25b0b214e511fa35faaff8595467c480 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:43:55 -0700 Subject: [PATCH 082/760] t7900-subtree.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- contrib/subtree/t/t7900-subtree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index 66ce4b07c2dc2d..b22b710c262ed6 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -76,7 +76,7 @@ test_expect_success 'add sub1' ' # Save this hash for testing later. -subdir_hash=`git rev-parse HEAD` +subdir_hash=$(git rev-parse HEAD) test_expect_success 'add sub2' ' create sub2 && From faf58f4ee6a5599c3b8790b770d6e1736174b7a3 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:43:56 -0700 Subject: [PATCH 083/760] appp.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- contrib/thunderbird-patch-inline/appp.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/thunderbird-patch-inline/appp.sh b/contrib/thunderbird-patch-inline/appp.sh index 5eb4a5164397e3..8dc73ece15a075 100755 --- a/contrib/thunderbird-patch-inline/appp.sh +++ b/contrib/thunderbird-patch-inline/appp.sh @@ -10,7 +10,7 @@ CONFFILE=~/.appprc SEP="-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=-" if [ -e "$CONFFILE" ] ; then - LAST_DIR=`grep -m 1 "^LAST_DIR=" "${CONFFILE}"|sed -e 's/^LAST_DIR=//'` + LAST_DIR=$(grep -m 1 "^LAST_DIR=" "${CONFFILE}"|sed -e 's/^LAST_DIR=//') cd "${LAST_DIR}" else cd > /dev/null @@ -25,11 +25,11 @@ fi cd - > /dev/null -SUBJECT=`sed -n -e '/^Subject: /p' "${PATCH}"` -HEADERS=`sed -e '/^'"${SEP}"'$/,$d' $1` -BODY=`sed -e "1,/${SEP}/d" $1` -CMT_MSG=`sed -e '1,/^$/d' -e '/^---$/,$d' "${PATCH}"` -DIFF=`sed -e '1,/^---$/d' "${PATCH}"` +SUBJECT=$(sed -n -e '/^Subject: /p' "${PATCH}") +HEADERS=$(sed -e '/^'"${SEP}"'$/,$d' $1) +BODY=$(sed -e "1,/${SEP}/d" $1) +CMT_MSG=$(sed -e '1,/^$/d' -e '/^---$/,$d' "${PATCH}") +DIFF=$(sed -e '1,/^---$/d' "${PATCH}") CCS=`echo -e "$CMT_MSG\n$HEADERS" | sed -n -e 's/^Cc: \(.*\)$/\1,/gp' \ -e 's/^Signed-off-by: \(.*\)/\1,/gp'` @@ -48,7 +48,7 @@ if [ "x${BODY}x" != "xx" ] ; then fi echo "$DIFF" >> $1 -LAST_DIR=`dirname "${PATCH}"` +LAST_DIR=$(dirname "${PATCH}") grep -v "^LAST_DIR=" "${CONFFILE}" > "${CONFFILE}_" echo "LAST_DIR=${LAST_DIR}" >> "${CONFFILE}_" From eadf619cd434135bdfa598566376b3e3dbf9f2b5 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:43:58 -0700 Subject: [PATCH 084/760] git-pull.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-pull.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-pull.sh b/git-pull.sh index 6cd8ebc534c174..cfc589dc15061c 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -108,7 +108,7 @@ do -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) case "$#,$1" in *,*=*) - strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;; + strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) usage ;; *) From f257482c9ccbb27e70f190da6a8152469b0fed1b Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:43:59 -0700 Subject: [PATCH 085/760] git-rebase--merge.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-rebase--merge.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh index 5381857c59968c..dc064f82b60a00 100644 --- a/git-rebase--merge.sh +++ b/git-rebase--merge.sh @@ -24,7 +24,7 @@ continue_merge () { die "$resolvemsg" fi - cmt=`cat "$state_dir/current"` + cmt=$(cat "$state_dir/current") if ! git diff-index --quiet --ignore-submodules HEAD -- then if ! git commit ${gpg_sign_opt:+"$gpg_sign_opt"} --no-verify -C "$cmt" @@ -132,7 +132,7 @@ echo "$onto_name" > "$state_dir/onto_name" write_basic_state msgnum=0 -for cmt in `git rev-list --reverse --no-merges "$revisions"` +for cmt in $(git rev-list --reverse --no-merges "$revisions") do msgnum=$(($msgnum + 1)) echo "$cmt" > "$state_dir/cmt.$msgnum" From 728fc79c0016fd7133c32f1d193d0a243e552257 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:44:00 -0700 Subject: [PATCH 086/760] git-rebase.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-rebase.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index 5f6732bf3dce78..a209ab9ce4ecc5 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -462,8 +462,8 @@ then else if test -z "$onto" then - empty_tree=`git hash-object -t tree /dev/null` - onto=`git commit-tree $empty_tree Date: Wed, 23 Apr 2014 06:44:01 -0700 Subject: [PATCH 087/760] git-stash.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-stash.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-stash.sh b/git-stash.sh index 4798bcf0e51b70..af549c731779db 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -13,7 +13,7 @@ USAGE="list [] SUBDIRECTORY_OK=Yes OPTIONS_SPEC= -START_DIR=`pwd` +START_DIR=$(pwd) . git-sh-setup . git-sh-i18n require_work_tree From 9e5878fbede57c0499133adf73844261849cd7b2 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:44:02 -0700 Subject: [PATCH 088/760] git-web--browse.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- git-web--browse.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-web--browse.sh b/git-web--browse.sh index ebdfba6c94db94..ae152534f5026d 100755 --- a/git-web--browse.sh +++ b/git-web--browse.sh @@ -59,7 +59,7 @@ do -b|--browser*|-t|--tool*) case "$#,$1" in *,*=*) - browser=`expr "z$1" : 'z-[^=]*=\(.*\)'` + browser=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) usage ;; @@ -71,7 +71,7 @@ do -c|--config*) case "$#,$1" in *,*=*) - conf=`expr "z$1" : 'z-[^=]*=\(.*\)'` + conf=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;; 1,*) usage ;; @@ -100,7 +100,7 @@ then for opt in "$conf" "web.browser" do test -z "$opt" && continue - browser="`git config $opt`" + browser="$(git config $opt)" test -z "$browser" || break done if test -n "$browser" && ! valid_tool "$browser"; then From 5a4352024ae71613186730e3a3ab670f43904ad6 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:44:03 -0700 Subject: [PATCH 089/760] lib-credential.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/lib-credential.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/lib-credential.sh b/t/lib-credential.sh index 957ae936e8b785..9e7d7962b0678d 100755 --- a/t/lib-credential.sh +++ b/t/lib-credential.sh @@ -281,7 +281,7 @@ helper_test_timeout() { cat >askpass <<\EOF #!/bin/sh echo >&2 askpass: $* -what=`echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z` +what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z) echo "askpass-$what" EOF chmod +x askpass From 03db917867bfd27c7a1f8e5b713d7bd7d3f6370e Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:44:04 -0700 Subject: [PATCH 090/760] lib-cvs.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/lib-cvs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/lib-cvs.sh b/t/lib-cvs.sh index 5076718916388d..9b2bcfb1b0e38e 100644 --- a/t/lib-cvs.sh +++ b/t/lib-cvs.sh @@ -13,7 +13,7 @@ fi CVS="cvs -f" export CVS -cvsps_version=`cvsps -h 2>&1 | sed -ne 's/cvsps version //p'` +cvsps_version=$(cvsps -h 2>&1 | sed -ne 's/cvsps version //p') case "$cvsps_version" in 2.1 | 2.2*) ;; From be194d53c0ce38ab3e040c6be249550fab4e8e1c Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:44:05 -0700 Subject: [PATCH 091/760] lib-gpg.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/lib-gpg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh index 05824fa8e4d182..fd499e7c498449 100755 --- a/t/lib-gpg.sh +++ b/t/lib-gpg.sh @@ -1,6 +1,6 @@ #!/bin/sh -gpg_version=`gpg --version 2>&1` +gpg_version=$(gpg --version 2>&1) if test $? = 127; then say "You do not seem to have gpg installed" else From 4717659144984c7fbfd2c01a2c22f342756e2abd Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 23 Apr 2014 06:44:06 -0700 Subject: [PATCH 092/760] p5302-pack-index.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/perf/p5302-pack-index.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/perf/p5302-pack-index.sh b/t/perf/p5302-pack-index.sh index 6cb5b0d55b6d6e..5ee9211f988dce 100755 --- a/t/perf/p5302-pack-index.sh +++ b/t/perf/p5302-pack-index.sh @@ -8,7 +8,7 @@ test_perf_large_repo test_expect_success 'repack' ' git repack -ad && - PACK=`ls .git/objects/pack/*.pack | head -n1` && + PACK=$(ls .git/objects/pack/*.pack | head -n1) && test -f "$PACK" && export PACK ' From 1c4ea83902e2a64472ccf99ced4ea773ad3dd8aa Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 23 Apr 2014 16:34:28 +0200 Subject: [PATCH 093/760] git-remote-mediawiki: allow stop/start-ing the test server Previously, the user had to launch a complete re-install after a lighttpd stop (e.g. a reboot). Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- contrib/mw-to-git/t/install-wiki.sh | 10 ++++++++++ contrib/mw-to-git/t/test-gitmw-lib.sh | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/contrib/mw-to-git/t/install-wiki.sh b/contrib/mw-to-git/t/install-wiki.sh index 70a53f67fd06bd..c215213c4bfddb 100755 --- a/contrib/mw-to-git/t/install-wiki.sh +++ b/contrib/mw-to-git/t/install-wiki.sh @@ -20,6 +20,8 @@ usage () { echo " install | -i : Install a wiki on your computer." echo " delete | -d : Delete the wiki and all its pages and " echo " content." + echo " start | -s : Start the previously configured lighttpd daemon" + echo " stop : Stop lighttpd daemon." } @@ -33,6 +35,14 @@ case "$1" in wiki_delete exit 0 ;; + "start" | "-s") + start_lighttpd + exit + ;; + "stop") + stop_lighttpd + exit + ;; "--help" | "-h") usage exit 0 diff --git a/contrib/mw-to-git/t/test-gitmw-lib.sh b/contrib/mw-to-git/t/test-gitmw-lib.sh index 3372b2af346ac2..d9a114995a0f75 100755 --- a/contrib/mw-to-git/t/test-gitmw-lib.sh +++ b/contrib/mw-to-git/t/test-gitmw-lib.sh @@ -289,7 +289,6 @@ start_lighttpd () { # Kill daemon lighttpd and removes files and folders associated. stop_lighttpd () { test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid") - rm -rf "$WEB" } # Create the SQLite database of the MediaWiki. If the database file already @@ -415,6 +414,7 @@ wiki_reset () { wiki_delete () { if test $LIGHTTPD = "true"; then stop_lighttpd + rm -fr "$WEB" else # Delete the wiki's directory. rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" || From 9742fb7e53b2f3bd85b5f01e563aee2cad7e77b8 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 23 Apr 2014 16:34:29 +0200 Subject: [PATCH 094/760] git-remote-mediawiki: fix encoding issue for UTF-8 media files When a media file contains valid UTF-8, git-remote-mediawiki tried to be too clever about the encoding, and the call to utf8::downgrade() on the downloaded content was failing with Wide character in subroutine entry at git-remote-mediawiki line 583. Instead, use $response->decode() to apply decoding linked to the Content-Encoding: header, and return the content without attempting any charset decoding. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- contrib/mw-to-git/git-remote-mediawiki.perl | 7 ++++++- .../t/t9363-mw-to-git-export-import.sh | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl index 3f8d993afaca53..8dd74a9a406e9c 100755 --- a/contrib/mw-to-git/git-remote-mediawiki.perl +++ b/contrib/mw-to-git/git-remote-mediawiki.perl @@ -461,7 +461,12 @@ sub download_mw_mediafile { my $response = $mediawiki->{ua}->get($download_url); if ($response->code == HTTP_CODE_OK) { - return $response->decoded_content; + # It is tempting to return + # $response->decoded_content({charset => "none"}), but + # when doing so, utf8::downgrade($content) fails with + # "Wide character in subroutine entry". + $response->decode(); + return $response->content(); } else { print {*STDERR} "Error downloading mediafile from :\n"; print {*STDERR} "URL: ${download_url}\n"; diff --git a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh index 5a0373935f1f4b..3ff3a095670ecd 100755 --- a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh +++ b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh @@ -58,6 +58,25 @@ test_expect_success 'git clone works on previously created wiki with media files test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt ' +test_expect_success 'git push can upload media (File:) files containing valid UTF-8' ' + wiki_reset && + git clone mediawiki::'"$WIKI_URL"' mw_dir && + ( + cd mw_dir && + "$PERL_PATH" -e "print STDOUT \"UTF-8 content: éèàéê€.\";" >Bar.txt && + git add Bar.txt && + git commit -m "add a text file with UTF-8 content" && + git push + ) +' + +test_expect_success 'git clone works on previously created wiki with media files containing valid UTF-8' ' + test_when_finished "rm -rf mw_dir mw_dir_clone" && + git clone -c remote.origin.mediaimport=true \ + mediawiki::'"$WIKI_URL"' mw_dir_clone && + test_cmp mw_dir_clone/Bar.txt mw_dir/Bar.txt +' + test_expect_success 'git push & pull work with locally renamed media files' ' wiki_reset && git clone mediawiki::'"$WIKI_URL"' mw_dir && From c15bb0cad73e4dad52a6d4869a254baf3a689b6a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 23 Apr 2014 10:07:20 -0700 Subject: [PATCH 095/760] mergetool: document the default for --[no-]prompt The original motivation of using the prompt was to confirm to run a tool on this particular (as opposed to another) path, but the user can also take the prompt as to confirm to run this (as opposed to some other) tool. The latter of which of course is irritating for those who told which exact tool to use, which is the reason why we are flipping the default. During the review discussion of the patch, many people (including the maintainer) missed that a user can find the prompt useful way to skip running the tool on particular paths. Clarify it by adding a brief half-sentence to the description. Signed-off-by: Junio C Hamano --- Documentation/git-mergetool.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt index 07137f252b0fd5..e846c2ed7f7f86 100644 --- a/Documentation/git-mergetool.txt +++ b/Documentation/git-mergetool.txt @@ -71,11 +71,13 @@ success of the resolution after the custom tool has exited. --no-prompt:: Don't prompt before each invocation of the merge resolution program. + This is the default if the merge resolution program is + explicitly specified with the `--tool` option or with the + `merge.tool` configuration variable. --prompt:: - Prompt before each invocation of the merge resolution program. - This is the default behaviour; the option is provided to - override any configuration settings. + Prompt before each invocation of the merge resolution program + to give the user a chance to skip the path. TEMPORARY FILES --------------- From cbc60b67201e083a4970c8731c5382a575357e36 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Lafay Date: Thu, 24 Apr 2014 14:24:39 +0200 Subject: [PATCH 096/760] git tag --contains: avoid stack overflow In large repos, the recursion implementation of contains(commit, commit_list) may result in a stack overflow. Replace the recursion with a loop to fix it. This problem is more apparent on Windows than on Linux, where the stack is more limited by default. See also this thread on the msysGit list: https://groups.google.com/d/topic/msysgit/FqT6boJrb2g/discussion [jes: re-written to imitate the original recursion more closely] Thomas Braun pointed out several documentation shortcomings. Tests are run only if ulimit -s is available. This means they cannot be run on Windows. Signed-off-by: Jean-Jacques Lafay Signed-off-by: Johannes Schindelin Tested-by: Stepan Kasal Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/tag.c | 90 +++++++++++++++++++++++++++++++++++++++++--------- t/t7004-tag.sh | 26 +++++++++++++++ 2 files changed, 101 insertions(+), 15 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index 6c7c6bde9de9cb..f3440023abecc6 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -80,11 +80,19 @@ static int in_commit_list(const struct commit_list *want, struct commit *c) return 0; } -static int contains_recurse(struct commit *candidate, +enum contains_result { + CONTAINS_UNKNOWN = -1, + CONTAINS_NO = 0, + CONTAINS_YES = 1, +}; + +/* + * Test whether the candidate or one of its parents is contained in the list. + * Do not recurse to find out, though, but return -1 if inconclusive. + */ +static enum contains_result contains_test(struct commit *candidate, const struct commit_list *want) { - struct commit_list *p; - /* was it previously marked as containing a want commit? */ if (candidate->object.flags & TMP_MARK) return 1; @@ -92,26 +100,78 @@ static int contains_recurse(struct commit *candidate, if (candidate->object.flags & UNINTERESTING) return 0; /* or are we it? */ - if (in_commit_list(want, candidate)) + if (in_commit_list(want, candidate)) { + candidate->object.flags |= TMP_MARK; return 1; + } if (parse_commit(candidate) < 0) return 0; - /* Otherwise recurse and mark ourselves for future traversals. */ - for (p = candidate->parents; p; p = p->next) { - if (contains_recurse(p->item, want)) { - candidate->object.flags |= TMP_MARK; - return 1; - } - } - candidate->object.flags |= UNINTERESTING; - return 0; + return -1; } -static int contains(struct commit *candidate, const struct commit_list *want) +/* + * Mimicking the real stack, this stack lives on the heap, avoiding stack + * overflows. + * + * At each recursion step, the stack items points to the commits whose + * ancestors are to be inspected. + */ +struct stack { + int nr, alloc; + struct stack_entry { + struct commit *commit; + struct commit_list *parents; + } *stack; +}; + +static void push_to_stack(struct commit *candidate, struct stack *stack) +{ + int index = stack->nr++; + ALLOC_GROW(stack->stack, stack->nr, stack->alloc); + stack->stack[index].commit = candidate; + stack->stack[index].parents = candidate->parents; +} + +static enum contains_result contains(struct commit *candidate, + const struct commit_list *want) { - return contains_recurse(candidate, want); + struct stack stack = { 0, 0, NULL }; + int result = contains_test(candidate, want); + + if (result != CONTAINS_UNKNOWN) + return result; + + push_to_stack(candidate, &stack); + while (stack.nr) { + struct stack_entry *entry = &stack.stack[stack.nr - 1]; + struct commit *commit = entry->commit; + struct commit_list *parents = entry->parents; + + if (!parents) { + commit->object.flags |= UNINTERESTING; + stack.nr--; + } + /* + * If we just popped the stack, parents->item has been marked, + * therefore contains_test will return a meaningful 0 or 1. + */ + else switch (contains_test(parents->item, want)) { + case CONTAINS_YES: + commit->object.flags |= TMP_MARK; + stack.nr--; + break; + case CONTAINS_NO: + entry->parents = parents->next; + break; + case CONTAINS_UNKNOWN: + push_to_stack(parents->item, &stack); + break; + } + } + free(stack.stack); + return contains_test(candidate, want); } static void show_tag_lines(const unsigned char *sha1, int lines) diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 143a8ea60507a3..e4ab0f5b64194d 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1423,4 +1423,30 @@ EOF test_cmp expect actual ' +run_with_limited_stack () { + (ulimit -s 64 && "$@") +} + +test_lazy_prereq ULIMIT 'run_with_limited_stack true' + +# we require ulimit, this excludes Windows +test_expect_success ULIMIT '--contains works in a deep repo' ' + >expect && + i=1 && + while test $i -lt 4000 + do + echo "commit refs/heads/master +committer A U Thor $((1000000000 + $i * 100)) +0200 +data <actual && + test_cmp expect actual +' + test_done From 076cbd6341182d296671cb101c75145eb3bfda0a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 25 Apr 2014 19:11:15 -0400 Subject: [PATCH 097/760] commit: do not complain of empty messages from -C When we pick another commit's message, we die() immediately if we find that it's empty and we are not going to run an editor (i.e., when running "-C" instead of "-c"). However, this check is redundant and harmful. It's redundant because we will already notice the empty message later, after we would have run the editor, and die there (just as we would for a regular, not "-C" case, where the user provided an empty message in the editor). It's harmful for a few reasons: 1. It does not respect --allow-empty-message. As a result, a "git rebase -i" cannot "pick" such a commit. So you cannot even go back in time to fix it with a "reword" or "edit" instruction. 2. It does not take into account other ways besides the editor to modify the message. For example, "git commit -C empty-commit -m foo" could take the author information from empty-commit, but add a message to it. There's more to do to make that work correctly (and right now we explicitly forbid "-C with -m"), but this removes one roadblock. 3. The existing check is not enough to prevent segfaults. We try to find the "\n\n" header/body boundary in the commit. If it is at the end of the string (i.e., no body), _or_ if we cannot find it at all (i.e., a truncated commit object), we consider the message empty. With "-C", that's OK; we die in either case. But with "-c", we continue on, and in the case of a truncated commit may end up dereferencing NULL+2. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/commit.c | 5 ++--- t/t7500-commit.sh | 11 ++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index fedb45af8c65d2..aa04507174765a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -650,9 +650,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, hook_arg1 = "message"; } else if (use_message) { buffer = strstr(use_message_buffer, "\n\n"); - if (!use_editor && (!buffer || buffer[2] == '\0')) - die(_("commit has empty message")); - strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); + if (buffer) + strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); hook_arg1 = "commit"; hook_arg2 = use_message; } else if (fixup_message) { diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh index bdc1f295030b61..116885a260a56f 100755 --- a/t/t7500-commit.sh +++ b/t/t7500-commit.sh @@ -223,7 +223,8 @@ test_expect_success 'Commit without message is allowed with --allow-empty-messag git add foo && >empty && git commit --allow-empty-message >foo && + git add foo && + test_must_fail git commit -C empty-message-commit && + git commit -C empty-message-commit --allow-empty-message && + commit_msg_is "" +' + commit_for_rebase_autosquash_setup () { echo "first content line" >>foo && git add foo && From 7e6ac6e4391caa0fc379cb699013d503380e4214 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 26 Apr 2014 01:56:49 +0200 Subject: [PATCH 098/760] blame: large-scale performance rewrite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous implementation used a single sorted linear list of blame entries for organizing all partial or completed work. Every subtask had to scan the whole list, with most entries not being relevant to the task. The resulting run-time was quadratic to the number of separate chunks. This change gives every subtask its own data to work with. Subtasks are organized into "struct origin" chains hanging off particular commits. Commits are organized into a priority queue, processing them in commit date order in order to keep most of the work affecting a particular blob collated even in the presence of an extensive merge history. For large files with a diversified history, a speedup by a factor of 3 or more is not unusual. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- builtin/blame.c | 865 +++++++++++++++++++++++++++++++----------------- 1 file changed, 567 insertions(+), 298 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 88cb7997274de6..224f0ff07716a1 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1,7 +1,8 @@ /* * Blame * - * Copyright (c) 2006, Junio C Hamano + * Copyright (c) 2006, 2014 by its authors + * See COPYING for licensing conditions */ #include "cache.h" @@ -18,7 +19,9 @@ #include "cache-tree.h" #include "string-list.h" #include "mailmap.h" +#include "mergesort.h" #include "parse-options.h" +#include "prio-queue.h" #include "utf8.h" #include "userdiff.h" #include "line-range.h" @@ -83,11 +86,42 @@ static unsigned blame_copy_score; */ struct origin { int refcnt; + /* Record preceding blame record for this blob */ struct origin *previous; + /* origins are put in a list linked via `next' hanging off the + * corresponding commit's util field in order to make finding + * them fast. The presence in this chain does not count + * towards the origin's reference count. It is tempting to + * let it count as long as the commit is pending examination, + * but even under circumstances where the commit will be + * present multiple times in the priority queue of unexamined + * commits, processing the first instance will not leave any + * work requiring the origin data for the second instance. An + * interspersed commit changing that would have to be + * preexisting with a different ancestry and with the same + * commit date in order to wedge itself between two instances + * of the same commit in the priority queue _and_ produce + * blame entries relevant for it. While we don't want to let + * us get tripped up by this case, it certainly does not seem + * worth optimizing for. + */ + struct origin *next; struct commit *commit; + /* `suspects' contains blame entries that may be attributed to + * this origin's commit or to parent commits. When a commit + * is being processed, all suspects will be moved, either by + * assigning them to an origin in a different commit, or by + * shipping them to the scoreboard's ent list because they + * cannot be attributed to a different commit. + */ + struct blame_entry *suspects; mmfile_t file; unsigned char blob_sha1[20]; unsigned mode; + /* guilty gets set when shipping any suspects to the final + * blame list instead of other commits + */ + char guilty; char path[FLEX_ARRAY]; }; @@ -176,10 +210,22 @@ static inline struct origin *origin_incref(struct origin *o) static void origin_decref(struct origin *o) { if (o && --o->refcnt <= 0) { + struct origin *p, *l = NULL; if (o->previous) origin_decref(o->previous); free(o->file.ptr); - free(o); + /* Should be present exactly once in commit chain */ + for (p = o->commit->util; p; l = p, p = p->next) { + if (p == o) { + if (l) + l->next = p->next; + else + o->commit->util = p->next; + free(o); + return; + } + } + die("internal error in blame::origin_decref"); } } @@ -193,8 +239,12 @@ static void drop_origin_blob(struct origin *o) /* * Each group of lines is described by a blame_entry; it can be split - * as we pass blame to the parents. They form a linked list in the - * scoreboard structure, sorted by the target line number. + * as we pass blame to the parents. They are arranged in linked lists + * kept as `suspects' of some unprocessed origin, or entered (when the + * blame origin has been finalized) into the scoreboard structure. + * While the scoreboard structure is only sorted at the end of + * processing (according to final image line number), the lists + * attached to an origin are sorted by the target line number. */ struct blame_entry { struct blame_entry *next; @@ -210,15 +260,6 @@ struct blame_entry { /* the commit that introduced this group into the final image */ struct origin *suspect; - /* true if the suspect is truly guilty; false while we have not - * checked if the group came from one of its parents. - */ - char guilty; - - /* true if the entry has been scanned for copies in the current parent - */ - char scanned; - /* the line number of the first line of this group in the * suspect's file; internally all line numbers are 0 based. */ @@ -230,12 +271,113 @@ struct blame_entry { unsigned score; }; +/* + * Any merge of blames happens on lists of blames that arrived via + * different parents in a single suspect. In this case, we want to + * sort according to the suspect line numbers as opposed to the final + * image line numbers. The function body is somewhat longish because + * it avoids unnecessary writes. + */ + +static struct blame_entry *blame_merge(struct blame_entry *list1, + struct blame_entry *list2) +{ + struct blame_entry *p1 = list1, *p2 = list2, + **tail = &list1; + + if (!p1) + return p2; + if (!p2) + return p1; + + if (p1->s_lno <= p2->s_lno) { + do { + tail = &p1->next; + if ((p1 = *tail) == NULL) { + *tail = p2; + return list1; + } + } while (p1->s_lno <= p2->s_lno); + } + for (;;) { + *tail = p2; + do { + tail = &p2->next; + if ((p2 = *tail) == NULL) { + *tail = p1; + return list1; + } + } while (p1->s_lno > p2->s_lno); + *tail = p1; + do { + tail = &p1->next; + if ((p1 = *tail) == NULL) { + *tail = p2; + return list1; + } + } while (p1->s_lno <= p2->s_lno); + } +} + +static void *get_next_blame(const void *p) +{ + return ((struct blame_entry *)p)->next; +} + +static void set_next_blame(void *p1, void *p2) +{ + ((struct blame_entry *)p1)->next = p2; +} + +/* + * Final image line numbers are all different, so we don't need a + * three-way comparison here. + */ + +static int compare_blame_final(const void *p1, const void *p2) +{ + return ((struct blame_entry *)p1)->lno > ((struct blame_entry *)p2)->lno + ? 1 : -1; +} + +static int compare_blame_suspect(const void *p1, const void *p2) +{ + const struct blame_entry *s1 = p1, *s2 = p2; + /* + * to allow for collating suspects, we sort according to the + * respective pointer value as the primary sorting criterion. + * The actual relation is pretty unimportant as long as it + * establishes a total order. Comparing as integers gives us + * that. + */ + if (s1->suspect != s2->suspect) + return (intptr_t)s1->suspect > (intptr_t)s2->suspect ? 1 : -1; + if (s1->s_lno == s2->s_lno) + return 0; + return s1->s_lno > s2->s_lno ? 1 : -1; +} + +static struct blame_entry *blame_sort(struct blame_entry *head, + int (*compare_fn)(const void *, const void *)) +{ + return llist_mergesort (head, get_next_blame, set_next_blame, compare_fn); +} + +static int compare_commits_by_reverse_commit_date(const void *a, + const void *b, + void *c) +{ + return -compare_commits_by_commit_date(a, b, c); +} + /* * The current state of the blame assignment. */ struct scoreboard { /* the final commit (i.e. where we started digging from) */ struct commit *final; + /* Priority queue for commits with unassigned blame records */ + struct prio_queue commits; struct rev_info *revs; const char *path; @@ -268,7 +410,6 @@ static void coalesce(struct scoreboard *sb) for (ent = sb->ent; ent && (next = ent->next); ent = next) { if (ent->suspect == next->suspect && - ent->guilty == next->guilty && ent->s_lno + ent->num_lines == next->s_lno) { ent->num_lines += next->num_lines; ent->next = next->next; @@ -283,6 +424,30 @@ static void coalesce(struct scoreboard *sb) sanity_check_refcnt(sb); } +/* + * Merge the given sorted list of blames into a preexisting origin. + * If there were no previous blames to that commit, it is entered into + * the commit priority queue of the score board. + */ + +static void queue_blames(struct scoreboard *sb, struct origin *porigin, + struct blame_entry *sorted) +{ + if (porigin->suspects) + porigin->suspects = blame_merge(porigin->suspects, sorted); + else { + struct origin *o; + for (o = porigin->commit->util; o; o = o->next) { + if (o->suspects) { + porigin->suspects = sorted; + return; + } + } + porigin->suspects = sorted; + prio_queue_put(&sb->commits, porigin->commit); + } +} + /* * Given a commit and a path in it, create a new origin structure. * The callers that add blame to the scoreboard should use @@ -295,23 +460,32 @@ static struct origin *make_origin(struct commit *commit, const char *path) o = xcalloc(1, sizeof(*o) + strlen(path) + 1); o->commit = commit; o->refcnt = 1; + o->next = commit->util; + commit->util = o; strcpy(o->path, path); return o; } /* * Locate an existing origin or create a new one. + * This moves the origin to front position in the commit util list. */ static struct origin *get_origin(struct scoreboard *sb, struct commit *commit, const char *path) { - struct blame_entry *e; + struct origin *o, *l; - for (e = sb->ent; e; e = e->next) { - if (e->suspect->commit == commit && - !strcmp(e->suspect->path, path)) - return origin_incref(e->suspect); + for (o = commit->util, l = NULL; o; l = o, o = o->next) { + if (!strcmp(o->path, path)) { + /* bump to front */ + if (l) { + l->next = o->next; + o->next = commit->util; + commit->util = o; + } + return origin_incref(o); + } } return make_origin(commit, path); } @@ -350,41 +524,19 @@ static struct origin *find_origin(struct scoreboard *sb, struct commit *parent, struct origin *origin) { - struct origin *porigin = NULL; + struct origin *porigin; struct diff_options diff_opts; const char *paths[2]; - if (parent->util) { - /* - * Each commit object can cache one origin in that - * commit. This is a freestanding copy of origin and - * not refcounted. - */ - struct origin *cached = parent->util; - if (!strcmp(cached->path, origin->path)) { + /* First check any existing origins */ + for (porigin = parent->util; porigin; porigin = porigin->next) + if (!strcmp(porigin->path, origin->path)) { /* * The same path between origin and its parent * without renaming -- the most common case. */ - porigin = get_origin(sb, parent, cached->path); - - /* - * If the origin was newly created (i.e. get_origin - * would call make_origin if none is found in the - * scoreboard), it does not know the blob_sha1/mode, - * so copy it. Otherwise porigin was in the - * scoreboard and already knows blob_sha1/mode. - */ - if (porigin->refcnt == 1) { - hashcpy(porigin->blob_sha1, cached->blob_sha1); - porigin->mode = cached->mode; - } - return porigin; + return origin_incref (porigin); } - /* otherwise it was not very useful; free it */ - free(parent->util); - parent->util = NULL; - } /* See if the origin->path is different between parent * and origin first. Most of the time they are the @@ -450,19 +602,6 @@ static struct origin *find_origin(struct scoreboard *sb, } diff_flush(&diff_opts); free_pathspec(&diff_opts.pathspec); - if (porigin) { - /* - * Create a freestanding copy that is not part of - * the refcounted origin found in the scoreboard, and - * cache it in the commit. - */ - struct origin *cached; - - cached = make_origin(porigin->commit, porigin->path); - hashcpy(cached->blob_sha1, porigin->blob_sha1); - cached->mode = porigin->mode; - parent->util = cached; - } return porigin; } @@ -509,46 +648,31 @@ static struct origin *find_rename(struct scoreboard *sb, } /* - * Link in a new blame entry to the scoreboard. Entries that cover the - * same line range have been removed from the scoreboard previously. + * Append a new blame entry to a given output queue. */ -static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e) +static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e) { - struct blame_entry *ent, *prev = NULL; - origin_incref(e->suspect); - for (ent = sb->ent; ent && ent->lno < e->lno; ent = ent->next) - prev = ent; - - /* prev, if not NULL, is the last one that is below e */ - - if (prev) { - e->next = prev->next; - prev->next = e; - } - else { - e->next = sb->ent; - sb->ent = e; - } + e->next = **queue; + **queue = e; + *queue = &e->next; } /* * src typically is on-stack; we want to copy the information in it to - * a malloced blame_entry that is already on the linked list of the - * scoreboard. The origin of dst loses a refcnt while the origin of src - * gains one. + * a malloced blame_entry that gets added to the given queue. The + * origin of dst loses a refcnt. */ -static void dup_entry(struct blame_entry *dst, struct blame_entry *src) +static void dup_entry(struct blame_entry ***queue, + struct blame_entry *dst, struct blame_entry *src) { - struct blame_entry *n; - - n = dst->next; origin_incref(src->suspect); origin_decref(dst->suspect); memcpy(dst, src, sizeof(*src)); - dst->next = n; - dst->score = 0; + dst->next = **queue; + **queue = dst; + *queue = &dst->next; } static const char *nth_line(struct scoreboard *sb, long lno) @@ -620,10 +744,11 @@ static void split_overlap(struct blame_entry *split, /* * split_overlap() divided an existing blame e into up to three parts - * in split. Adjust the linked list of blames in the scoreboard to + * in split. Any assigned blame is moved to queue to * reflect the split. */ -static void split_blame(struct scoreboard *sb, +static void split_blame(struct blame_entry ***blamed, + struct blame_entry ***unblamed, struct blame_entry *split, struct blame_entry *e) { @@ -631,61 +756,39 @@ static void split_blame(struct scoreboard *sb, if (split[0].suspect && split[2].suspect) { /* The first part (reuse storage for the existing entry e) */ - dup_entry(e, &split[0]); + dup_entry(unblamed, e, &split[0]); /* The last part -- me */ new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[2]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); + add_blame_entry(unblamed, new_entry); /* ... and the middle part -- parent */ new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[1]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); + add_blame_entry(blamed, new_entry); } else if (!split[0].suspect && !split[2].suspect) /* * The parent covers the entire area; reuse storage for * e and replace it with the parent. */ - dup_entry(e, &split[1]); + dup_entry(blamed, e, &split[1]); else if (split[0].suspect) { /* me and then parent */ - dup_entry(e, &split[0]); + dup_entry(unblamed, e, &split[0]); new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[1]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); + add_blame_entry(blamed, new_entry); } else { /* parent and then me */ - dup_entry(e, &split[1]); + dup_entry(blamed, e, &split[1]); new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[2]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); - } - - if (DEBUG) { /* sanity */ - struct blame_entry *ent; - int lno = sb->ent->lno, corrupt = 0; - - for (ent = sb->ent; ent; ent = ent->next) { - if (lno != ent->lno) - corrupt = 1; - if (ent->s_lno < 0) - corrupt = 1; - lno += ent->num_lines; - } - if (corrupt) { - lno = sb->ent->lno; - for (ent = sb->ent; ent; ent = ent->next) { - printf("L %8d l %8d n %8d\n", - lno, ent->lno, ent->num_lines); - lno = ent->lno + ent->num_lines; - } - die("oops"); - } + add_blame_entry(unblamed, new_entry); } } @@ -702,74 +805,146 @@ static void decref_split(struct blame_entry *split) } /* - * Helper for blame_chunk(). blame_entry e is known to overlap with - * the patch hunk; split it and pass blame to the parent. + * reverse_blame reverses the list given in head, appending tail. + * That allows us to build lists in reverse order, then reverse them + * afterwards. This can be faster than building the list in proper + * order right away. The reason is that building in proper order + * requires writing a link in the _previous_ element, while building + * in reverse order just requires placing the list head into the + * _current_ element. */ -static void blame_overlap(struct scoreboard *sb, struct blame_entry *e, - int tlno, int plno, int same, - struct origin *parent) -{ - struct blame_entry split[3]; - - split_overlap(split, e, tlno, plno, same, parent); - if (split[1].suspect) - split_blame(sb, split, e); - decref_split(split); -} -/* - * Find the line number of the last line the target is suspected for. - */ -static int find_last_in_target(struct scoreboard *sb, struct origin *target) +static struct blame_entry *reverse_blame(struct blame_entry *head, + struct blame_entry *tail) { - struct blame_entry *e; - int last_in_target = -1; - - for (e = sb->ent; e; e = e->next) { - if (e->guilty || e->suspect != target) - continue; - if (last_in_target < e->s_lno + e->num_lines) - last_in_target = e->s_lno + e->num_lines; + while (head) { + struct blame_entry *next = head->next; + head->next = tail; + tail = head; + head = next; } - return last_in_target; + return tail; } /* * Process one hunk from the patch between the current suspect for - * blame_entry e and its parent. Find and split the overlap, and - * pass blame to the overlapping part to the parent. + * blame_entry e and its parent. This first blames any unfinished + * entries before the chunk (which is where target and parent start + * differing) on the parent, and then splits blame entries at the + * start and at the end of the difference region. Since use of -M and + * -C options may lead to overlapping/duplicate source line number + * ranges, all we can rely on from sorting/merging is the order of the + * first suspect line number. */ -static void blame_chunk(struct scoreboard *sb, - int tlno, int plno, int same, - struct origin *target, struct origin *parent) +static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, + int tlno, int offset, int same, + struct origin *parent) { - struct blame_entry *e; + struct blame_entry *e = **srcq; + struct blame_entry *samep = NULL, *diffp = NULL; - for (e = sb->ent; e; e = e->next) { - if (e->guilty || e->suspect != target) - continue; - if (same <= e->s_lno) - continue; - if (tlno < e->s_lno + e->num_lines) - blame_overlap(sb, e, tlno, plno, same, parent); + while (e && e->s_lno < tlno) { + struct blame_entry *next = e->next; + /* + * current record starts before differing portion. If + * it reaches into it, we need to split it up and + * examine the second part separately. + */ + if (e->s_lno + e->num_lines > tlno) { + /* Move second half to a new record */ + int len = tlno - e->s_lno; + struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry)); + n->suspect = e->suspect; + n->lno = e->lno + len; + n->s_lno = e->s_lno + len; + n->num_lines = e->num_lines - len; + e->num_lines = len; + e->score = 0; + /* Push new record to diffp */ + n->next = diffp; + diffp = n; + } else + origin_decref(e->suspect); + /* Pass blame for everything before the differing + * chunk to the parent */ + e->suspect = origin_incref(parent); + e->s_lno += offset; + e->next = samep; + samep = e; + e = next; + } + /* + * As we don't know how much of a common stretch after this + * diff will occur, the currently blamed parts are all that we + * can assign to the parent for now. + */ + + if (samep) { + **dstq = reverse_blame(samep, **dstq); + *dstq = &samep->next; } + /* + * Prepend the split off portions: everything after e starts + * after the blameable portion. + */ + e = reverse_blame(diffp, e); + + /* + * Now retain records on the target while parts are different + * from the parent. + */ + samep = NULL; + diffp = NULL; + while (e && e->s_lno < same) { + struct blame_entry *next = e->next; + + /* + * If current record extends into sameness, need to split. + */ + if (e->s_lno + e->num_lines > same) { + /* + * Move second half to a new record to be + * processed by later chunks + */ + int len = same - e->s_lno; + struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry)); + n->suspect = origin_incref(e->suspect); + n->lno = e->lno + len; + n->s_lno = e->s_lno + len; + n->num_lines = e->num_lines - len; + e->num_lines = len; + e->score = 0; + /* Push new record to samep */ + n->next = samep; + samep = n; + } + e->next = diffp; + diffp = e; + e = next; + } + **srcq = reverse_blame(diffp, reverse_blame(samep, e)); + /* Move across elements that are in the unblamable portion */ + if (diffp) + *srcq = &diffp->next; } struct blame_chunk_cb_data { - struct scoreboard *sb; - struct origin *target; struct origin *parent; - long plno; - long tlno; + long offset; + struct blame_entry **dstq; + struct blame_entry **srcq; }; +/* diff chunks are from parent to target */ static int blame_chunk_cb(long start_a, long count_a, long start_b, long count_b, void *data) { struct blame_chunk_cb_data *d = data; - blame_chunk(d->sb, d->tlno, d->plno, start_b, d->target, d->parent); - d->plno = start_a + count_a; - d->tlno = start_b + count_b; + if (start_a - start_b != d->offset) + die("internal error in blame::blame_chunk_cb"); + blame_chunk(&d->dstq, &d->srcq, start_b, start_a - start_b, + start_b + count_b, d->parent); + d->offset = start_a + count_a - (start_b + count_b); return 0; } @@ -778,29 +953,32 @@ static int blame_chunk_cb(long start_a, long count_a, * for the lines it is suspected to its parent. Run diff to find * which lines came from parent and pass blame for them. */ -static int pass_blame_to_parent(struct scoreboard *sb, - struct origin *target, - struct origin *parent) +static void pass_blame_to_parent(struct scoreboard *sb, + struct origin *target, + struct origin *parent) { - int last_in_target; mmfile_t file_p, file_o; struct blame_chunk_cb_data d; + struct blame_entry *newdest = NULL; - memset(&d, 0, sizeof(d)); - d.sb = sb; d.target = target; d.parent = parent; - last_in_target = find_last_in_target(sb, target); - if (last_in_target < 0) - return 1; /* nothing remains for this target */ + if (!target->suspects) + return; /* nothing remains for this target */ + + d.parent = parent; + d.offset = 0; + d.dstq = &newdest; d.srcq = &target->suspects; fill_origin_blob(&sb->revs->diffopt, parent, &file_p); fill_origin_blob(&sb->revs->diffopt, target, &file_o); num_get_patch++; diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d); - /* The rest (i.e. anything after tlno) are the same as the parent */ - blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent); + /* The rest are the same as the parent */ + blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent); + *d.dstq = NULL; + queue_blames(sb, parent, newdest); - return 0; + return; } /* @@ -945,43 +1123,80 @@ static void find_copy_in_blob(struct scoreboard *sb, handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split); } +/* Move all blame entries from list *source that have a score smaller + * than score_min to the front of list *small. + * Returns a pointer to the link pointing to the old head of the small list. + */ + +static struct blame_entry **filter_small(struct scoreboard *sb, + struct blame_entry **small, + struct blame_entry **source, + unsigned score_min) +{ + struct blame_entry *p = *source; + struct blame_entry *oldsmall = *small; + while (p) { + if (ent_score(sb, p) <= score_min) { + *small = p; + small = &p->next; + p = *small; + } else { + *source = p; + source = &p->next; + p = *source; + } + } + *small = oldsmall; + *source = NULL; + return small; +} + /* * See if lines currently target is suspected for can be attributed to * parent. */ -static int find_move_in_parent(struct scoreboard *sb, - struct origin *target, - struct origin *parent) +static void find_move_in_parent(struct scoreboard *sb, + struct blame_entry ***blamed, + struct blame_entry **toosmall, + struct origin *target, + struct origin *parent) { - int last_in_target, made_progress; struct blame_entry *e, split[3]; + struct blame_entry *unblamed = target->suspects; + struct blame_entry *leftover = NULL; mmfile_t file_p; - last_in_target = find_last_in_target(sb, target); - if (last_in_target < 0) - return 1; /* nothing remains for this target */ + if (!unblamed) + return; /* nothing remains for this target */ fill_origin_blob(&sb->revs->diffopt, parent, &file_p); if (!file_p.ptr) - return 0; + return; - made_progress = 1; - while (made_progress) { - made_progress = 0; - for (e = sb->ent; e; e = e->next) { - if (e->guilty || e->suspect != target || - ent_score(sb, e) < blame_move_score) - continue; + /* At each iteration, unblamed has a NULL-terminated list of + * entries that have not yet been tested for blame. leftover + * contains the reversed list of entries that have been tested + * without being assignable to the parent. + */ + do { + struct blame_entry **unblamedtail = &unblamed; + struct blame_entry *next; + for (e = unblamed; e; e = next) { + next = e->next; find_copy_in_blob(sb, e, parent, split, &file_p); if (split[1].suspect && blame_move_score < ent_score(sb, &split[1])) { - split_blame(sb, split, e); - made_progress = 1; + split_blame(blamed, &unblamedtail, split, e); + } else { + e->next = leftover; + leftover = e; } decref_split(split); } - } - return 0; + *unblamedtail = NULL; + toosmall = filter_small(sb, toosmall, &unblamed, blame_move_score); + } while (unblamed); + target->suspects = reverse_blame(leftover, NULL); } struct blame_list { @@ -993,62 +1208,46 @@ struct blame_list { * Count the number of entries the target is suspected for, * and prepare a list of entry and the best split. */ -static struct blame_list *setup_blame_list(struct scoreboard *sb, - struct origin *target, - int min_score, +static struct blame_list *setup_blame_list(struct blame_entry *unblamed, int *num_ents_p) { struct blame_entry *e; int num_ents, i; struct blame_list *blame_list = NULL; - for (e = sb->ent, num_ents = 0; e; e = e->next) - if (!e->scanned && !e->guilty && - e->suspect == target && - min_score < ent_score(sb, e)) - num_ents++; + for (e = unblamed, num_ents = 0; e; e = e->next) + num_ents++; if (num_ents) { blame_list = xcalloc(num_ents, sizeof(struct blame_list)); - for (e = sb->ent, i = 0; e; e = e->next) - if (!e->scanned && !e->guilty && - e->suspect == target && - min_score < ent_score(sb, e)) - blame_list[i++].ent = e; + for (e = unblamed, i = 0; e; e = e->next) + blame_list[i++].ent = e; } *num_ents_p = num_ents; return blame_list; } -/* - * Reset the scanned status on all entries. - */ -static void reset_scanned_flag(struct scoreboard *sb) -{ - struct blame_entry *e; - for (e = sb->ent; e; e = e->next) - e->scanned = 0; -} - /* * For lines target is suspected for, see if we can find code movement * across file boundary from the parent commit. porigin is the path * in the parent we already tried. */ -static int find_copy_in_parent(struct scoreboard *sb, - struct origin *target, - struct commit *parent, - struct origin *porigin, - int opt) +static void find_copy_in_parent(struct scoreboard *sb, + struct blame_entry ***blamed, + struct blame_entry **toosmall, + struct origin *target, + struct commit *parent, + struct origin *porigin, + int opt) { struct diff_options diff_opts; int i, j; - int retval; struct blame_list *blame_list; int num_ents; + struct blame_entry *unblamed = target->suspects; + struct blame_entry *leftover = NULL; - blame_list = setup_blame_list(sb, target, blame_copy_score, &num_ents); - if (!blame_list) - return 1; /* nothing remains for this target */ + if (!unblamed) + return; /* nothing remains for this target */ diff_setup(&diff_opts); DIFF_OPT_SET(&diff_opts, RECURSIVE); @@ -1078,9 +1277,9 @@ static int find_copy_in_parent(struct scoreboard *sb, if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER)) diffcore_std(&diff_opts); - retval = 0; - while (1) { - int made_progress = 0; + do { + struct blame_entry **unblamedtail = &unblamed; + blame_list = setup_blame_list(unblamed, &num_ents); for (i = 0; i < diff_queued_diff.nr; i++) { struct diff_filepair *p = diff_queued_diff.queue[i]; @@ -1117,27 +1316,21 @@ static int find_copy_in_parent(struct scoreboard *sb, struct blame_entry *split = blame_list[j].split; if (split[1].suspect && blame_copy_score < ent_score(sb, &split[1])) { - split_blame(sb, split, blame_list[j].ent); - made_progress = 1; + split_blame(blamed, &unblamedtail, split, + blame_list[j].ent); + } else { + blame_list[j].ent->next = leftover; + leftover = blame_list[j].ent; } - else - blame_list[j].ent->scanned = 1; decref_split(split); } free(blame_list); - - if (!made_progress) - break; - blame_list = setup_blame_list(sb, target, blame_copy_score, &num_ents); - if (!blame_list) { - retval = 1; - break; - } - } - reset_scanned_flag(sb); + *unblamedtail = NULL; + toosmall = filter_small(sb, toosmall, &unblamed, blame_copy_score); + } while (unblamed); + target->suspects = reverse_blame(leftover, NULL); diff_flush(&diff_opts); free_pathspec(&diff_opts.pathspec); - return retval; } /* @@ -1147,20 +1340,21 @@ static int find_copy_in_parent(struct scoreboard *sb, static void pass_whole_blame(struct scoreboard *sb, struct origin *origin, struct origin *porigin) { - struct blame_entry *e; + struct blame_entry *e, *suspects; if (!porigin->file.ptr && origin->file.ptr) { /* Steal its file */ porigin->file = origin->file; origin->file.ptr = NULL; } - for (e = sb->ent; e; e = e->next) { - if (e->suspect != origin) - continue; + suspects = origin->suspects; + origin->suspects = NULL; + for (e = suspects; e; e = e->next) { origin_incref(porigin); origin_decref(e->suspect); e->suspect = porigin; } + queue_blames(sb, porigin, suspects); } /* @@ -1184,6 +1378,27 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit) return cnt; } +/* Distribute collected unsorted blames to the respected sorted lists + * in the various origins. + */ +static void distribute_blame(struct scoreboard *sb, struct blame_entry *blamed) +{ + blamed = blame_sort(blamed, compare_blame_suspect); + while (blamed) + { + struct origin *porigin = blamed->suspect; + struct blame_entry *suspects = NULL; + do { + struct blame_entry *next = blamed->next; + blamed->next = suspects; + suspects = blamed; + blamed = next; + } while (blamed && blamed->suspect == porigin); + suspects = reverse_blame(suspects, NULL); + queue_blames(sb, porigin, suspects); + } +} + #define MAXSG 16 static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) @@ -1194,6 +1409,8 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) struct commit_list *sg; struct origin *sg_buf[MAXSG]; struct origin *porigin, **sg_origin = sg_buf; + struct blame_entry *toosmall = NULL; + struct blame_entry *blames, **blametail = &blames; num_sg = num_scapegoats(revs, commit); if (!num_sg) @@ -1255,38 +1472,71 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) origin_incref(porigin); origin->previous = porigin; } - if (pass_blame_to_parent(sb, origin, porigin)) + pass_blame_to_parent(sb, origin, porigin); + if (!origin->suspects) goto finish; } /* * Optionally find moves in parents' files. */ - if (opt & PICKAXE_BLAME_MOVE) - for (i = 0, sg = first_scapegoat(revs, commit); - i < num_sg && sg; - sg = sg->next, i++) { - struct origin *porigin = sg_origin[i]; - if (!porigin) - continue; - if (find_move_in_parent(sb, origin, porigin)) - goto finish; + if (opt & PICKAXE_BLAME_MOVE) { + filter_small(sb, &toosmall, &origin->suspects, blame_move_score); + if (origin->suspects) { + for (i = 0, sg = first_scapegoat(revs, commit); + i < num_sg && sg; + sg = sg->next, i++) { + struct origin *porigin = sg_origin[i]; + if (!porigin) + continue; + find_move_in_parent(sb, &blametail, &toosmall, origin, porigin); + if (!origin->suspects) + break; + } } + } /* * Optionally find copies from parents' files. */ - if (opt & PICKAXE_BLAME_COPY) + if (opt & PICKAXE_BLAME_COPY) { + if (blame_copy_score > blame_move_score) + filter_small(sb, &toosmall, &origin->suspects, blame_copy_score); + else if (blame_copy_score < blame_move_score) { + origin->suspects = blame_merge(origin->suspects, toosmall); + toosmall = NULL; + filter_small(sb, &toosmall, &origin->suspects, blame_copy_score); + } + if (!origin->suspects) + goto finish; + for (i = 0, sg = first_scapegoat(revs, commit); i < num_sg && sg; sg = sg->next, i++) { struct origin *porigin = sg_origin[i]; - if (find_copy_in_parent(sb, origin, sg->item, - porigin, opt)) + find_copy_in_parent(sb, &blametail, &toosmall, + origin, sg->item, porigin, opt); + if (!origin->suspects) goto finish; } + } - finish: +finish: + *blametail = NULL; + distribute_blame(sb, blames); + /* + * prepend toosmall to origin->suspects + * + * There is no point in sorting: this ends up on a big + * unsorted list in the caller anyway. + */ + if (toosmall) { + struct blame_entry **tail = &toosmall; + while (*tail) + tail = &(*tail)->next; + *tail = origin->suspects; + origin->suspects = toosmall; + } for (i = 0; i < num_sg; i++) { if (sg_origin[i]) { drop_origin_blob(sg_origin[i]); @@ -1481,14 +1731,11 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat) } /* - * The blame_entry is found to be guilty for the range. Mark it - * as such, and show it in incremental output. + * The blame_entry is found to be guilty for the range. + * Show it in incremental output. */ static void found_guilty_entry(struct blame_entry *ent) { - if (ent->guilty) - return; - ent->guilty = 1; if (incremental) { struct origin *suspect = ent->suspect; @@ -1502,32 +1749,34 @@ static void found_guilty_entry(struct blame_entry *ent) } /* - * The main loop -- while the scoreboard has lines whose true origin - * is still unknown, pick one blame_entry, and allow its current - * suspect to pass blames to its parents. - */ + * The main loop -- while we have blobs with lines whose true origin + * is still unknown, pick one blob, and allow its lines to pass blames + * to its parents. */ static void assign_blame(struct scoreboard *sb, int opt) { struct rev_info *revs = sb->revs; + struct commit *commit = prio_queue_get(&sb->commits); - while (1) { + while (commit) { struct blame_entry *ent; - struct commit *commit; - struct origin *suspect = NULL; + struct origin *suspect = commit->util; /* find one suspect to break down */ - for (ent = sb->ent; !suspect && ent; ent = ent->next) - if (!ent->guilty) - suspect = ent->suspect; - if (!suspect) - return; /* all done */ + while (suspect && !suspect->suspects) + suspect = suspect->next; + + if (!suspect) { + commit = prio_queue_get(&sb->commits); + continue; + } + + assert(commit == suspect->commit); /* * We will use this suspect later in the loop, * so hold onto it in the meantime. */ origin_incref(suspect); - commit = suspect->commit; parse_commit(commit); if (reverse || (!(commit->object.flags & UNINTERESTING) && @@ -1543,9 +1792,22 @@ static void assign_blame(struct scoreboard *sb, int opt) commit->object.flags |= UNINTERESTING; /* Take responsibility for the remaining entries */ - for (ent = sb->ent; ent; ent = ent->next) - if (ent->suspect == suspect) + ent = suspect->suspects; + if (ent) { + suspect->guilty = 1; + for (;;) { + struct blame_entry *next = ent->next; found_guilty_entry(ent); + if (next) { + ent = next; + continue; + } + ent->next = sb->ent; + sb->ent = suspect->suspects; + suspect->suspects = NULL; + break; + } + } origin_decref(suspect); if (DEBUG) /* sanity */ @@ -1602,9 +1864,8 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent, char hex[41]; strcpy(hex, sha1_to_hex(suspect->commit->object.sha1)); - printf("%s%c%d %d %d\n", + printf("%s %d %d %d\n", hex, - ent->guilty ? ' ' : '*', /* purely for debugging */ ent->s_lno + 1, ent->lno + 1, ent->num_lines); @@ -1717,17 +1978,16 @@ static void output(struct scoreboard *sb, int option) if (option & OUTPUT_PORCELAIN) { for (ent = sb->ent; ent; ent = ent->next) { - struct blame_entry *oth; - struct origin *suspect = ent->suspect; - struct commit *commit = suspect->commit; + int count = 0; + struct origin *suspect; + struct commit *commit = ent->suspect->commit; if (commit->object.flags & MORE_THAN_ONE_PATH) continue; - for (oth = ent->next; oth; oth = oth->next) { - if ((oth->suspect->commit != commit) || - !strcmp(oth->suspect->path, suspect->path)) - continue; - commit->object.flags |= MORE_THAN_ONE_PATH; - break; + for (suspect = commit->util; suspect; suspect = suspect->next) { + if (suspect->guilty && count++) { + commit->object.flags |= MORE_THAN_ONE_PATH; + break; + } } } } @@ -2092,7 +2352,6 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1); - commit->util = origin; /* * Read the current index, replace the path entry with @@ -2403,12 +2662,16 @@ int cmd_blame(int argc, const char **argv, const char *prefix) memset(&sb, 0, sizeof(sb)); sb.revs = &revs; - if (!reverse) + if (!reverse) { final_commit_name = prepare_final(&sb); + sb.commits.compare = compare_commits_by_commit_date; + } else if (contents_from) die("--contents and --children do not blend well."); - else + else { final_commit_name = prepare_initial(&sb); + sb.commits.compare = compare_commits_by_reverse_commit_date; + } if (!sb.final) { /* @@ -2497,12 +2760,16 @@ int cmd_blame(int argc, const char **argv, const char *prefix) ent->next = next; origin_incref(o); } + + o->suspects = ent; + prio_queue_put(&sb.commits, o->commit); + origin_decref(o); range_set_release(&ranges); string_list_clear(&range_list, 0); - sb.ent = ent; + sb.ent = NULL; sb.path = path; read_mailmap(&mailmap, NULL); @@ -2515,6 +2782,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix) if (incremental) return 0; + sb.ent = blame_sort(sb.ent, compare_blame_final); + coalesce(&sb); if (!(output_option & OUTPUT_PORCELAIN)) From c0459ca4dc47edf5d63850a34a5f67febd966f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Engel?= Date: Mon, 21 Apr 2014 16:46:22 -0400 Subject: [PATCH 099/760] pager: do allow spawning pager recursively MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 88e8f908f2b0c56f9ccf8134d8ff9f689af9cc84, which tried to allow GIT_PAGER="git -p column --mode='dense color'" git -p branch and still wanted to avoid "git -p column" to invoke itself. However, this falls into "don't do that -p then" category. In particular, inside "git log", with results going through less, a potentially interesting commit may be found and from there inside "less", the user may want to execute "git show ". Before the commit being reverted, this used to show the patch in less but it no longer does. Signed-off-by: Jörn Engel Reviewed-by: Jeff King Reviewed-by: Matthieu Moy Acked-by: Duy Nguyen Signed-off-by: Junio C Hamano --- pager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pager.c b/pager.c index 0cc75a8eee32a0..53670a63a7ae4d 100644 --- a/pager.c +++ b/pager.c @@ -64,7 +64,7 @@ void setup_pager(void) { const char *pager = git_pager(isatty(1)); - if (!pager || pager_in_use()) + if (!pager) return; /* From 76e7c8a7ed58250bb74cf55618a81baed1797eca Mon Sep 17 00:00:00 2001 From: Theodore Leblond Date: Wed, 16 May 2012 06:52:49 -0700 Subject: [PATCH 100/760] compat/poll: sleep 1 millisecond to avoid busy wait SwitchToThread() only gives away the rest of the current time slice to another thread in the current process. So if the thread that feeds the file decscriptor we're polling is not in the current process, we get busy-waiting. I played around with this quite a bit. After trying some more complex schemes, I found that what worked best is to just sleep 1 millisecond between iterations. Though it's a very short time, it still completely eliminates the busy wait condition, without hurting perf. There code uses SleepEx(1, TRUE) to sleep. See this page for a good discussion of why that is better than calling SwitchToThread, which is what was used previously: http://stackoverflow.com/questions/1383943/switchtothread-vs-sleep1 Note that calling SleepEx(0, TRUE) does *not* solve the busy wait. The most striking case was when testing on a UNC share with a large repo, on a single CPU machine. Without the fix, it took 4 minutes 15 seconds, and with the fix it took just 1:08! I think it's because git-upload-pack's busy wait was eating the CPU away from the git process that's doing the real work. With multi-proc, the timing is not much different, but tons of CPU time is still wasted, which can be a killer on a server that needs to do bunch of other things. I also tested the very fast local case, and didn't see any measurable difference. On a big repo with 4500 files, the upload-pack took about 2 seconds with and without the fix. [jc: this was first accepted in msysgit tree in May 2012 via a pull request and Paolo Bonzini has also accepted the same fix to Gnulib around the same time; see $gmane/247518 for a bit more detail] Signed-off-by: Stepan Kasal Acked-by: Johannes Sixt Acked-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- compat/poll/poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/poll/poll.c b/compat/poll/poll.c index 31163f2ae7b718..a9b41d89f46520 100644 --- a/compat/poll/poll.c +++ b/compat/poll/poll.c @@ -605,7 +605,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) if (!rc && timeout == INFTIM) { - SwitchToThread(); + SleepEx (1, TRUE); goto restart; } From 750b2e4785e5956122b3c565af65eb1929714fba Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 28 Apr 2014 12:16:31 -0400 Subject: [PATCH 101/760] t3910: show failure of core.precomposeunicode with decomposed filenames If you have existing decomposed filenames in your git repository (e.g., that were created with older versions of git that did not precompose unicode), a modern git with core.precomposeunicode set does not handle them well. The problem is that we normalize the paths coming from the disk into their precomposed form, and then compare them against the literal bytes in the index. This makes things better if you have the precomposed form in the index. It makes things worse if you actually have the decomposed form in the index. As a result, paths with decomposed filenames may have their precomposed variants listed as untracked files (even though the precomposed variants do not exist on-disk at all). This patch just adds a test to demonstrate the breakage. Some possible fixes are: 1. Tell everyone that NFD in the git repo is wrong, and they should make a new commit to normalize all their in-repo files to be precomposed. This is probably not the right thing to do, because it still doesn't fix checkouts of old history. And it spreads the problem to people on byte-preserving filesystems (like ext4), because now they have to start precomposing their filenames as they are adde to git. 2. Do all index filename comparisons using a UTF-8 aware comparison function when core.precomposeunicode is set. This would probably have bad performance, and somewhat defeats the point of converting the filenames at the readdir level in the first place. 3. Convert index filenames to their precomposed form when we read the index from disk. This would be efficient, but we would have to be careful not to write the precomposed forms back out to disk. 4. Introduce some infrastructure to efficiently match up the precomposed/decomposed forms. We already do something similar for case-insensitive files using name-hash.c. We might be able to adapt that strategy here. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t3910-mac-os-precompose.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh index e4ba6013e41927..23aa61ef090445 100755 --- a/t/t3910-mac-os-precompose.sh +++ b/t/t3910-mac-os-precompose.sh @@ -140,6 +140,16 @@ test_expect_success "Add long precomposed filename" ' git add * && git commit -m "Long filename" ' + +test_expect_failure 'handle existing decomposed filenames' ' + echo content >"verbatim.$Adiarnfd" && + git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && + git commit -m "existing decomposed file" && + >expect && + git ls-files --exclude-standard -o "verbatim*" >untracked && + test_cmp expect untracked +' + # Test if the global core.precomposeunicode stops autosensing # Must be the last test case test_expect_success "respect git config --global core.precomposeunicode" ' From 791643a865ac15a381e629a35f252293911b0fb0 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Mon, 28 Apr 2014 20:00:04 -0700 Subject: [PATCH 102/760] imap-send: use git-credential git-imap-send was directly prompting for a password rather than using git-credential. git-send-email, on the other hand, supports git-credential. This is a necessary improvement for users that use two factor authentication, as they should not be expected to remember all of their app specific passwords. Signed-off-by: Dan Albert Acked-by: Jeff King Signed-off-by: Junio C Hamano --- imap-send.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/imap-send.c b/imap-send.c index 0bc6f7fae151ea..5c4f336330e416 100644 --- a/imap-send.c +++ b/imap-send.c @@ -23,9 +23,9 @@ */ #include "cache.h" +#include "credential.h" #include "exec_cmd.h" #include "run-command.h" -#include "prompt.h" #ifdef NO_OPENSSL typedef void *SSL; #endif @@ -946,6 +946,7 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha static struct imap_store *imap_open_store(struct imap_server_conf *srvc) { + struct credential cred = CREDENTIAL_INIT; struct imap_store *ctx; struct imap *imap; char *arg, *rsp; @@ -1096,25 +1097,23 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc) } #endif imap_info("Logging in...\n"); - if (!srvc->user) { - fprintf(stderr, "Skipping server %s, no user\n", srvc->host); - goto bail; - } - if (!srvc->pass) { - struct strbuf prompt = STRBUF_INIT; - strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host); - arg = git_getpass(prompt.buf); - strbuf_release(&prompt); - if (!*arg) { - fprintf(stderr, "Skipping account %s@%s, no password\n", srvc->user, srvc->host); - goto bail; - } - /* - * getpass() returns a pointer to a static buffer. make a copy - * for long term storage. - */ - srvc->pass = xstrdup(arg); + if (!srvc->user || !srvc->pass) { + cred.protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap"); + cred.host = xstrdup(srvc->host); + + if (srvc->user) + cred.username = xstrdup(srvc->user); + if (srvc->pass) + cred.password = xstrdup(srvc->pass); + + credential_fill(&cred); + + if (!srvc->user) + srvc->user = xstrdup(cred.username); + if (!srvc->pass) + srvc->pass = xstrdup(cred.password); } + if (CAP(NOLOGIN)) { fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host); goto bail; @@ -1153,10 +1152,18 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc) } } /* !preauth */ + if (cred.username) + credential_approve(&cred); + credential_clear(&cred); + ctx->prefix = ""; return ctx; bail: + if (cred.username) + credential_reject(&cred); + credential_clear(&cred); + imap_close_store(ctx); return NULL; } From f515c904fb4d1b95bb8b94cb00fb6b5768cf0ed4 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Tue, 29 Apr 2014 08:41:16 +0300 Subject: [PATCH 103/760] git-send-email: two new options: to-cover, cc-cover Allow extracting To/Cc addresses from the first patch (typically the cover letter), and use them as To/Cc addresses of the remainder of the series. Signed-off-by: Michael S. Tsirkin Signed-off-by: Junio C Hamano --- Documentation/git-send-email.txt | 12 ++++++++++++ git-send-email.perl | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index f0e57a597b6e55..b983053f8598e4 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -248,6 +248,18 @@ Automating cc list. Default is the value of 'sendemail.signedoffbycc' configuration value; if that is unspecified, default to --signed-off-by-cc. +--[no-]cc-cover:: + If this is set, emails found in Cc: headers in the first patch of + the series (typically the cover letter) are added to the cc list + for each email set. Default is the value of 'sendemail.cccover' + configuration value; if that is unspecified, default to --no-cc-cover. + +--[no-]to-cover:: + If this is set, emails found in To: headers in the first patch of + the series (typically the cover letter) are added to the to list + for each email set. Default is the value of 'sendemail.tocover' + configuration value; if that is unspecified, default to --no-to-cover. + --suppress-cc=:: Specify an additional category of recipients to suppress the auto-cc of: diff --git a/git-send-email.perl b/git-send-email.perl index fdb0029b597898..d884b4821d6479 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -80,6 +80,8 @@ sub usage { --to-cmd * Email To: via ` \$patch_path` --cc-cmd * Email Cc: via ` \$patch_path` --suppress-cc * author, self, sob, cc, cccmd, body, bodycc, all. + --[no-]cc-cover * Email Cc: addresses in the cover letter. + --[no-]to-cover * Email To: addresses in the cover letter. --[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on. --[no-]suppress-from * Send to self. Default off. --[no-]chain-reply-to * Chain In-Reply-To: fields. Default off. @@ -195,6 +197,7 @@ sub do_edit { # Variables with corresponding config settings my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc); +my ($cover_cc, $cover_to); my ($to_cmd, $cc_cmd); my ($smtp_server, $smtp_server_port, @smtp_server_options); my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path); @@ -211,6 +214,8 @@ sub do_edit { "chainreplyto" => [\$chain_reply_to, 0], "suppressfrom" => [\$suppress_from, undef], "signedoffbycc" => [\$signed_off_by_cc, undef], + "cccover" => [\$cover_cc, undef], + "tocover" => [\$cover_to, undef], "signedoffcc" => [\$signed_off_by_cc, undef], # Deprecated "validate" => [\$validate, 1], "multiedit" => [\$multiedit, undef], @@ -302,6 +307,8 @@ sub signal_handler { "suppress-from!" => \$suppress_from, "suppress-cc=s" => \@suppress_cc, "signed-off-cc|signed-off-by-cc!" => \$signed_off_by_cc, + "cc-cover|cc-cover!" => \$cover_cc, + "to-cover|to-cover!" => \$cover_to, "confirm=s" => \$confirm, "dry-run" => \$dry_run, "envelope-sender=s" => \$envelope_sender, @@ -1469,6 +1476,15 @@ sub send_message { @to = (@initial_to, @to); @cc = (@initial_cc, @cc); + if ($message_num == 1) { + if (defined $cover_cc and $cover_cc) { + @initial_cc = @cc; + } + if (defined $cover_to and $cover_to) { + @initial_to = @to; + } + } + my $message_was_sent = send_message(); # set up for the next message From 8ccc4e42604636a38114fafa976ea9e25a578094 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Tue, 29 Apr 2014 08:41:18 +0300 Subject: [PATCH 104/760] test/send-email: to-cover, cc-cover tests Add tests for the new feature. Signed-off-by: Michael S. Tsirkin Signed-off-by: Junio C Hamano --- t/t9001-send-email.sh | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1ecdacb6fd0ceb..64d9434da9ff24 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1334,6 +1334,51 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' ' test -n "$(ls msgtxt*)" ' +test_cover_addresses () { + header="$1" + shift + clean_fake_sendmail && + rm -fr outdir && + git format-patch --cover-letter -2 -o outdir && + cover=`echo outdir/0000-*.patch` && + mv $cover cover-to-edit.patch && + sed "s/^From:/$header: extra@address.com\nFrom:/" cover-to-edit.patch >"$cover" && + git send-email \ + --force \ + --from="Example " \ + --no-to --no-cc \ + "$@" \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0000-*.patch \ + outdir/0001-*.patch \ + outdir/0002-*.patch \ + 2>errors >out && + grep "^$header: extra@address.com" msgtxt1 >to1 && + grep "^$header: extra@address.com" msgtxt2 >to2 && + grep "^$header: extra@address.com" msgtxt3 >to3 && + test_line_count = 1 to1 && + test_line_count = 1 to2 && + test_line_count = 1 to3 +} + +test_expect_success $PREREQ 'to-cover adds To to all mail' ' + test_cover_addresses "To" --to-cover +' + +test_expect_success $PREREQ 'cc-cover adds Cc to all mail' ' + test_cover_addresses "Cc" --cc-cover +' + +test_expect_success $PREREQ 'tocover adds To to all mail' ' + test_config sendemail.tocover true && + test_cover_addresses "To" +' + +test_expect_success $PREREQ 'cccover adds Cc to all mail' ' + test_config sendemail.cccover true && + test_cover_addresses "Cc" +' + test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' clean_fake_sendmail && echo "alias sbd somebody@example.org" >.mailrc && From 3f495f67bc4ec744ac60f6e7bec0924022670998 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 26 Apr 2014 22:00:54 +0200 Subject: [PATCH 105/760] replace: refactor command-mode determination The git-replace command has three modes: listing, deleting, and replacing. The first two are selected explicitly. If none is selected, we fallback to listing when there are no arguments, and replacing otherwise. Let's figure out up front which operation we are going to do, before getting into the application logic. That lets us simplify our option checks (e.g., we currently have to check whether a useless "--force" is given both along with an explicit list, as well as with an implicit one). This saves some lines, makes the logic easier to follow, and will facilitate further cleanups. Signed-off-by: Jeff King Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index b62420a01af820..28db96fcce1197 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -182,12 +182,16 @@ int cmd_replace(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0); + if (!list && !delete) + if (!argc) + list = 1; + if (list && delete) usage_msg_opt("-l and -d cannot be used together", git_replace_usage, options); - if (format && delete) - usage_msg_opt("--format and -d cannot be used together", + if (format && !list) + usage_msg_opt("--format cannot be used when not listing", git_replace_usage, options); if (force && (list || delete)) @@ -207,9 +211,6 @@ int cmd_replace(int argc, const char **argv, const char *prefix) if (argc != 2) usage_msg_opt("bad number of arguments", git_replace_usage, options); - if (format) - usage_msg_opt("--format cannot be used when not listing", - git_replace_usage, options); return replace_object(argv[0], argv[1], force); } @@ -217,9 +218,6 @@ int cmd_replace(int argc, const char **argv, const char *prefix) if (argc > 1) usage_msg_opt("only one pattern can be given with -l", git_replace_usage, options); - if (force) - usage_msg_opt("-f needs some arguments", - git_replace_usage, options); return list_replace_refs(argv[0], format); } From 70c7bd6dafc83eee7bf76d33d12027224d80f20d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 26 Apr 2014 22:00:55 +0200 Subject: [PATCH 106/760] replace: use OPT_CMDMODE to handle modes By using OPT_CMDMODE, the mutual exclusion between modes is taken care of for us. It also makes it easy for us to maintain a single variable with the mode, which makes its intent more clear. We can use a single switch() to make sure we have covered all of the modes. This ends up breaking even in code size, but the win will be much bigger when we start adding more modes. Signed-off-by: Jeff King Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 49 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 28db96fcce1197..29cf699659a13a 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -168,11 +168,17 @@ static int replace_object(const char *object_ref, const char *replace_ref, int cmd_replace(int argc, const char **argv, const char *prefix) { - int list = 0, delete = 0, force = 0; + int force = 0; const char *format = NULL; + enum { + MODE_UNSPECIFIED = 0, + MODE_LIST, + MODE_DELETE, + MODE_REPLACE + } cmdmode = MODE_UNSPECIFIED; struct option options[] = { - OPT_BOOL('l', "list", &list, N_("list replace refs")), - OPT_BOOL('d', "delete", &delete, N_("delete replace refs")), + OPT_CMDMODE('l', "list", &cmdmode, N_("list replace refs"), MODE_LIST), + OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE), OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")), OPT_STRING(0, "format", &format, N_("format"), N_("use this format")), OPT_END() @@ -182,42 +188,37 @@ int cmd_replace(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0); - if (!list && !delete) - if (!argc) - list = 1; + if (!cmdmode) + cmdmode = argc ? MODE_REPLACE : MODE_LIST; - if (list && delete) - usage_msg_opt("-l and -d cannot be used together", - git_replace_usage, options); - - if (format && !list) + if (format && cmdmode != MODE_LIST) usage_msg_opt("--format cannot be used when not listing", git_replace_usage, options); - if (force && (list || delete)) - usage_msg_opt("-f cannot be used with -d or -l", + if (force && cmdmode != MODE_REPLACE) + usage_msg_opt("-f only makes sense when writing a replacement", git_replace_usage, options); - /* Delete refs */ - if (delete) { + switch (cmdmode) { + case MODE_DELETE: if (argc < 1) usage_msg_opt("-d needs at least one argument", git_replace_usage, options); return for_each_replace_name(argv, delete_replace_ref); - } - /* Replace object */ - if (!list && argc) { + case MODE_REPLACE: if (argc != 2) usage_msg_opt("bad number of arguments", git_replace_usage, options); return replace_object(argv[0], argv[1], force); - } - /* List refs, even if "list" is not set */ - if (argc > 1) - usage_msg_opt("only one pattern can be given with -l", - git_replace_usage, options); + case MODE_LIST: + if (argc > 1) + usage_msg_opt("only one pattern can be given with -l", + git_replace_usage, options); + return list_replace_refs(argv[0], format); - return list_replace_refs(argv[0], format); + default: + die("BUG: invalid cmdmode %d", (int)cmdmode); + } } From 479bd75751d81b6f3ffc29fcece56f9a200493a1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 26 Apr 2014 22:00:56 +0200 Subject: [PATCH 107/760] replace: factor object resolution out of replace_object As we add new options that operate on objects before replacing them, we'll want to be able to feed raw sha1s straight into replace_object. Split replace_object into the object-resolution part and the actual replacement. Signed-off-by: Jeff King Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 29cf699659a13a..af40129c8fc30d 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -123,19 +123,17 @@ static int delete_replace_ref(const char *name, const char *ref, return 0; } -static int replace_object(const char *object_ref, const char *replace_ref, - int force) +static int replace_object_sha1(const char *object_ref, + unsigned char object[20], + const char *replace_ref, + unsigned char repl[20], + int force) { - unsigned char object[20], prev[20], repl[20]; + unsigned char prev[20]; enum object_type obj_type, repl_type; char ref[PATH_MAX]; struct ref_lock *lock; - if (get_sha1(object_ref, object)) - die("Failed to resolve '%s' as a valid ref.", object_ref); - if (get_sha1(replace_ref, repl)) - die("Failed to resolve '%s' as a valid ref.", replace_ref); - if (snprintf(ref, sizeof(ref), "refs/replace/%s", sha1_to_hex(object)) > sizeof(ref) - 1) @@ -166,6 +164,18 @@ static int replace_object(const char *object_ref, const char *replace_ref, return 0; } +static int replace_object(const char *object_ref, const char *replace_ref, int force) +{ + unsigned char object[20], repl[20]; + + if (get_sha1(object_ref, object)) + die("Failed to resolve '%s' as a valid ref.", object_ref); + if (get_sha1(replace_ref, repl)) + die("Failed to resolve '%s' as a valid ref.", replace_ref); + + return replace_object_sha1(object_ref, object, replace_ref, repl, force); +} + int cmd_replace(int argc, const char **argv, const char *prefix) { int force = 0; From b892bb45eacb484be281a992bef66ea723210717 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 26 Apr 2014 22:00:57 +0200 Subject: [PATCH 108/760] replace: add --edit option This allows you to run: git replace --edit SHA1 to get dumped in an editor with the contents of the object for SHA1. The result is then read back in and used as a "replace" object for SHA1. The writing/reading is type-aware, so you get to edit "ls-tree" output rather than the binary tree format. Missing documentation and tests. Signed-off-by: Jeff King Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 112 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/builtin/replace.c b/builtin/replace.c index af40129c8fc30d..3da1bae0a60942 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -12,6 +12,7 @@ #include "builtin.h" #include "refs.h" #include "parse-options.h" +#include "run-command.h" static const char * const git_replace_usage[] = { N_("git replace [-f] "), @@ -176,6 +177,107 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f return replace_object_sha1(object_ref, object, replace_ref, repl, force); } +/* + * Write the contents of the object named by "sha1" to the file "filename", + * pretty-printed for human editing based on its type. + */ +static void export_object(const unsigned char *sha1, const char *filename) +{ + const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL }; + struct child_process cmd = { argv }; + int fd; + + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd < 0) + die_errno("unable to open %s for writing", filename); + + argv[3] = sha1_to_hex(sha1); + cmd.git_cmd = 1; + cmd.out = fd; + + if (run_command(&cmd)) + die("cat-file reported failure"); + + close(fd); +} + +/* + * Read a previously-exported (and possibly edited) object back from "filename", + * interpreting it as "type", and writing the result to the object database. + * The sha1 of the written object is returned via sha1. + */ +static void import_object(unsigned char *sha1, enum object_type type, + const char *filename) +{ + int fd; + + fd = open(filename, O_RDONLY); + if (fd < 0) + die_errno("unable to open %s for reading", filename); + + if (type == OBJ_TREE) { + const char *argv[] = { "mktree", NULL }; + struct child_process cmd = { argv }; + struct strbuf result = STRBUF_INIT; + + cmd.argv = argv; + cmd.git_cmd = 1; + cmd.in = fd; + cmd.out = -1; + + if (start_command(&cmd)) + die("unable to spawn mktree"); + + if (strbuf_read(&result, cmd.out, 41) < 0) + die_errno("unable to read from mktree"); + close(cmd.out); + + if (finish_command(&cmd)) + die("mktree reported failure"); + if (get_sha1_hex(result.buf, sha1) < 0) + die("mktree did not return an object name"); + + strbuf_release(&result); + } else { + struct stat st; + int flags = HASH_FORMAT_CHECK | HASH_WRITE_OBJECT; + + if (fstat(fd, &st) < 0) + die_errno("unable to fstat %s", filename); + if (index_fd(sha1, fd, &st, type, NULL, flags) < 0) + die("unable to write object to database"); + /* index_fd close()s fd for us */ + } + + /* + * No need to close(fd) here; both run-command and index-fd + * will have done it for us. + */ +} + +static int edit_and_replace(const char *object_ref, int force) +{ + char *tmpfile = git_pathdup("REPLACE_EDITOBJ"); + enum object_type type; + unsigned char old[20], new[20]; + + if (get_sha1(object_ref, old) < 0) + die("Not a valid object name: '%s'", object_ref); + + type = sha1_object_info(old, NULL); + if (type < 0) + die("unable to get object type for %s", sha1_to_hex(old)); + + export_object(old, tmpfile); + if (launch_editor(tmpfile, NULL, NULL) < 0) + die("editing object file failed"); + import_object(new, type, tmpfile); + + free(tmpfile); + + return replace_object_sha1(object_ref, old, "replacement", new, force); +} + int cmd_replace(int argc, const char **argv, const char *prefix) { int force = 0; @@ -184,11 +286,13 @@ int cmd_replace(int argc, const char **argv, const char *prefix) MODE_UNSPECIFIED = 0, MODE_LIST, MODE_DELETE, + MODE_EDIT, MODE_REPLACE } cmdmode = MODE_UNSPECIFIED; struct option options[] = { OPT_CMDMODE('l', "list", &cmdmode, N_("list replace refs"), MODE_LIST), OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE), + OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT), OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")), OPT_STRING(0, "format", &format, N_("format"), N_("use this format")), OPT_END() @@ -205,7 +309,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix) usage_msg_opt("--format cannot be used when not listing", git_replace_usage, options); - if (force && cmdmode != MODE_REPLACE) + if (force && cmdmode != MODE_REPLACE && cmdmode != MODE_EDIT) usage_msg_opt("-f only makes sense when writing a replacement", git_replace_usage, options); @@ -222,6 +326,12 @@ int cmd_replace(int argc, const char **argv, const char *prefix) git_replace_usage, options); return replace_object(argv[0], argv[1], force); + case MODE_EDIT: + if (argc != 1) + usage_msg_opt("-e needs exactly one argument", + git_replace_usage, options); + return edit_and_replace(argv[0], force); + case MODE_LIST: if (argc > 1) usage_msg_opt("only one pattern can be given with -l", From a0a2f7d79c953b012adcfb0be3f9a60d5efbf644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 28 Apr 2014 17:55:22 +0700 Subject: [PATCH 109/760] ewah: fix constness of ewah_read_mmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- ewah/ewah_io.c | 4 ++-- ewah/ewok.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ewah/ewah_io.c b/ewah/ewah_io.c index f7f700ef516eea..1c2d7afd4cb9b7 100644 --- a/ewah/ewah_io.c +++ b/ewah/ewah_io.c @@ -110,9 +110,9 @@ int ewah_serialize(struct ewah_bitmap *self, int fd) return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd); } -int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len) +int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len) { - uint8_t *ptr = map; + const uint8_t *ptr = map; size_t i; self->bit_size = get_be32(ptr); diff --git a/ewah/ewok.h b/ewah/ewok.h index 43adeb5c689338..0556ca5fb06e80 100644 --- a/ewah/ewok.h +++ b/ewah/ewok.h @@ -99,7 +99,7 @@ int ewah_serialize(struct ewah_bitmap *self, int fd); int ewah_serialize_native(struct ewah_bitmap *self, int fd); int ewah_deserialize(struct ewah_bitmap *self, int fd); -int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len); +int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len); int ewah_read_mmap_native(struct ewah_bitmap *self, void *map, size_t len); uint32_t ewah_checksum(struct ewah_bitmap *self); From 16fc2b7a9ca54b12b06bb3d677db65e5e64638c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 28 Apr 2014 17:55:23 +0700 Subject: [PATCH 110/760] ewah: delete unused ewah_read_mmap_native declaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- ewah/ewok.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ewah/ewok.h b/ewah/ewok.h index 0556ca5fb06e80..f6ad190a038a55 100644 --- a/ewah/ewok.h +++ b/ewah/ewok.h @@ -100,7 +100,6 @@ int ewah_serialize_native(struct ewah_bitmap *self, int fd); int ewah_deserialize(struct ewah_bitmap *self, int fd); int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len); -int ewah_read_mmap_native(struct ewah_bitmap *self, void *map, size_t len); uint32_t ewah_checksum(struct ewah_bitmap *self); From 33c297aacc0ce0f945198fbcdf48fbf2fd27d01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 28 Apr 2014 17:55:24 +0700 Subject: [PATCH 111/760] sequencer: do not update/refresh index if the lock cannot be held MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- sequencer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index bde5f047b01376..7b886a67dd3eb3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -679,7 +679,7 @@ static void read_and_refresh_cache(struct replay_opts *opts) if (read_index_preload(&the_index, NULL) < 0) die(_("git %s: failed to read the index"), action_name(opts)); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL); - if (the_index.cache_changed) { + if (the_index.cache_changed && index_fd >= 0) { if (write_index(&the_index, index_fd) || commit_locked_index(&index_lock)) die(_("git %s: failed to refresh the index"), action_name(opts)); From 88619b3ee4bd21254d3306b12f47be3f0d9ad04b Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:24 -0700 Subject: [PATCH 112/760] t0001-init.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 9fb582b192e7d4..32821fe450d611 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -250,7 +250,7 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' ) && check_config init-bare-shared-override true unset && test x0666 = \ - x`git config -f init-bare-shared-override/config core.sharedRepository` + x$(git config -f init-bare-shared-override/config core.sharedRepository) ' test_expect_success 'init honors global core.sharedRepository' ' @@ -262,7 +262,7 @@ test_expect_success 'init honors global core.sharedRepository' ' git init ) && test x0666 = \ - x`git config -f shared-honor-global/.git/config core.sharedRepository` + x$(git config -f shared-honor-global/.git/config core.sharedRepository) ' test_expect_success 'init rejects insanely long --template' ' @@ -374,7 +374,7 @@ test_expect_success 'init prefers command line to GIT_DIR' ' test_expect_success 'init with separate gitdir' ' rm -rf newdir && git init --separate-git-dir realgitdir newdir && - echo "gitdir: `pwd`/realgitdir" >expected && + echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test -d realgitdir/refs ' @@ -388,7 +388,7 @@ test_expect_success 're-init to update git link' ' cd newdir && git init --separate-git-dir ../surrealgitdir ) && - echo "gitdir: `pwd`/surrealgitdir" >expected && + echo "gitdir: $(pwd)/surrealgitdir" >expected && test_cmp expected newdir/.git && test -d surrealgitdir/refs && ! test -d realgitdir/refs @@ -401,7 +401,7 @@ test_expect_success 're-init to move gitdir' ' cd newdir && git init --separate-git-dir ../realgitdir ) && - echo "gitdir: `pwd`/realgitdir" >expected && + echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test -d realgitdir/refs ' @@ -415,7 +415,7 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' ' ln -s here .git && git init --separate-git-dir ../realgitdir ) && - echo "gitdir: `pwd`/realgitdir" >expected && + echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test -d realgitdir/refs && ! test -d newdir/here From 8fc5593c53218d19c7a0bac34debeaf6328e4f62 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:25 -0700 Subject: [PATCH 113/760] t0010-racy-git.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0010-racy-git.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0010-racy-git.sh b/t/t0010-racy-git.sh index e45a9e40e43252..5657c5a87b6e25 100755 --- a/t/t0010-racy-git.sh +++ b/t/t0010-racy-git.sh @@ -14,7 +14,7 @@ do git update-index --add infocom echo xyzzy >infocom - files=`git diff-files -p` + files=$(git diff-files -p) test_expect_success \ "Racy GIT trial #$trial part A" \ 'test "" != "$files"' @@ -23,7 +23,7 @@ do echo xyzzy >cornerstone git update-index --add cornerstone - files=`git diff-files -p` + files=$(git diff-files -p) test_expect_success \ "Racy GIT trial #$trial part B" \ 'test "" != "$files"' From def226bdbb53d32f6c3f6bb66cfe1810089033df Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:26 -0700 Subject: [PATCH 114/760] t0020-crlf.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0020-crlf.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh index e526184a0bfa3c..d2e51a81bc0897 100755 --- a/t/t0020-crlf.sh +++ b/t/t0020-crlf.sh @@ -20,14 +20,14 @@ test_expect_success setup ' git commit -m initial && - one=`git rev-parse HEAD:one` && - dir=`git rev-parse HEAD:dir` && - two=`git rev-parse HEAD:dir/two` && - three=`git rev-parse HEAD:three` && + one=$(git rev-parse HEAD:one) && + dir=$(git rev-parse HEAD:dir) && + two=$(git rev-parse HEAD:dir/two) && + three=$(git rev-parse HEAD:three) && for w in Some extra lines here; do echo $w; done >>one && git diff >patch.file && - patched=`git hash-object --stdin Date: Mon, 28 Apr 2014 05:57:27 -0700 Subject: [PATCH 115/760] t0025-crlf-auto.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0025-crlf-auto.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh index f5f67a6337320c..b0e5694ebd07b5 100755 --- a/t/t0025-crlf-auto.sh +++ b/t/t0025-crlf-auto.sh @@ -19,9 +19,9 @@ test_expect_success setup ' git commit -m initial && - one=`git rev-parse HEAD:one` && - two=`git rev-parse HEAD:two` && - three=`git rev-parse HEAD:three` && + one=$(git rev-parse HEAD:one) && + two=$(git rev-parse HEAD:two) && + three=$(git rev-parse HEAD:three) && echo happy. ' @@ -33,9 +33,9 @@ test_expect_success 'default settings cause no changes' ' ! has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - threediff=`git diff three` && + onediff=$(git diff one) && + twodiff=$(git diff two) && + threediff=$(git diff three) && test -z "$onediff" -a -z "$twodiff" -a -z "$threediff" ' @@ -48,7 +48,7 @@ test_expect_success 'crlf=true causes a CRLF file to be normalized' ' # Note, "normalized" means that git will normalize it if added has_cr two && - twodiff=`git diff two` && + twodiff=$(git diff two) && test -n "$twodiff" ' @@ -60,7 +60,7 @@ test_expect_success 'text=true causes a CRLF file to be normalized' ' # Note, "normalized" means that git will normalize it if added has_cr two && - twodiff=`git diff two` && + twodiff=$(git diff two) && test -n "$twodiff" ' @@ -72,7 +72,7 @@ test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' git read-tree --reset -u HEAD && has_cr one && - onediff=`git diff one` && + onediff=$(git diff one) && test -z "$onediff" ' @@ -84,7 +84,7 @@ test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' git read-tree --reset -u HEAD && has_cr one && - onediff=`git diff one` && + onediff=$(git diff one) && test -z "$onediff" ' @@ -96,7 +96,7 @@ test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' ' git read-tree --reset -u HEAD && ! has_cr one && - onediff=`git diff one` && + onediff=$(git diff one) && test -z "$onediff" ' @@ -108,9 +108,9 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' ' has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - threediff=`git diff three` && + onediff=$(git diff one) && + twodiff=$(git diff two) && + threediff=$(git diff three) && test -z "$onediff" -a -z "$twodiff" -a -z "$threediff" ' @@ -123,9 +123,9 @@ test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' ' has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - threediff=`git diff three` && + onediff=$(git diff one) && + twodiff=$(git diff two) && + threediff=$(git diff three) && test -z "$onediff" -a -n "$twodiff" -a -z "$threediff" ' @@ -137,7 +137,7 @@ test_expect_success 'text=auto, autocrlf=true does not normalize binary files' ' git read-tree --reset -u HEAD && ! has_cr three && - threediff=`git diff three` && + threediff=$(git diff three) && test -z "$threediff" ' @@ -148,7 +148,7 @@ test_expect_success 'eol=crlf _does_ normalize binary files' ' git read-tree --reset -u HEAD && has_cr three && - threediff=`git diff three` && + threediff=$(git diff three) && test -z "$threediff" ' From 8deeab4a2413868b44fda4a0d0c56d2a7c45c6be Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:28 -0700 Subject: [PATCH 116/760] t0026-eol-config.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0026-eol-config.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh index fe0164be62ad9a..e1126aa7cc05ff 100755 --- a/t/t0026-eol-config.sh +++ b/t/t0026-eol-config.sh @@ -20,8 +20,8 @@ test_expect_success setup ' git commit -m initial && - one=`git rev-parse HEAD:one` && - two=`git rev-parse HEAD:two` && + one=$(git rev-parse HEAD:one) && + two=$(git rev-parse HEAD:two) && echo happy. ' @@ -34,8 +34,8 @@ test_expect_success 'eol=lf puts LFs in normalized file' ' ! has_cr one && ! has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && + onediff=$(git diff one) && + twodiff=$(git diff two) && test -z "$onediff" -a -z "$twodiff" ' @@ -47,8 +47,8 @@ test_expect_success 'eol=crlf puts CRLFs in normalized file' ' has_cr one && ! has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && + onediff=$(git diff one) && + twodiff=$(git diff two) && test -z "$onediff" -a -z "$twodiff" ' @@ -61,8 +61,8 @@ test_expect_success 'autocrlf=true overrides eol=lf' ' has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && + onediff=$(git diff one) && + twodiff=$(git diff two) && test -z "$onediff" -a -z "$twodiff" ' @@ -75,8 +75,8 @@ test_expect_success 'autocrlf=true overrides unset eol' ' has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && + onediff=$(git diff one) && + twodiff=$(git diff two) && test -z "$onediff" -a -z "$twodiff" ' From 4d713567f9e79f738e7b309ad0222e1517871f9c Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:29 -0700 Subject: [PATCH 117/760] t0030-stripspace.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0030-stripspace.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh index a8e84d85463617..0333dd9875af9f 100755 --- a/t/t0030-stripspace.sh +++ b/t/t0030-stripspace.sh @@ -225,22 +225,22 @@ test_expect_success \ test_expect_success \ 'text without newline at end should end with newline' ' - test `printf "$ttt" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0 + test $(printf "$ttt" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 ' # text plus spaces at the end: test_expect_success \ 'text plus spaces without newline at end should end with newline' ' - test `printf "$ttt$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$sss$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$sss$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$sss$sss$sss" | git stripspace | wc -l` -gt 0 + test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0 ' test_expect_success \ From dd64267fe2151b1ea3f19b5745d0fa8321995381 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:30 -0700 Subject: [PATCH 118/760] t0300-credentials.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t0300-credentials.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh index 538ea5fb1c27bf..57ea5a10c5c716 100755 --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@ -6,7 +6,7 @@ test_description='basic credential helper tests' test_expect_success 'setup helper scripts' ' cat >dump <<-\EOF && - whoami=`echo $0 | sed s/.*git-credential-//` + whoami=$(echo $0 | sed s/.*git-credential-//) echo >&2 "$whoami: $*" OIFS=$IFS IFS== From 86e30432177470f50be4207da2cc0422f86a24f7 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:31 -0700 Subject: [PATCH 119/760] t1000-read-tree-m-3way.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1000-read-tree-m-3way.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh index babcdd23433348..a0b79b4839fb21 100755 --- a/t/t1000-read-tree-m-3way.sh +++ b/t/t1000-read-tree-m-3way.sh @@ -519,10 +519,10 @@ test_expect_success \ 'rm -f .git/index F16 && echo F16 >F16 && git update-index --add F16 && - tree0=`git write-tree` && + tree0=$(git write-tree) && echo E16 >F16 && git update-index F16 && - tree1=`git write-tree` && + tree1=$(git write-tree) && read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 && git ls-files --stage' From 142efa3e43e9c61cb5b97dbe69d36ca090d683d5 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:32 -0700 Subject: [PATCH 120/760] t1001-read-tree-m-2way.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1001-read-tree-m-2way.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index acaab07fac672e..f0d8eb91b42d7a 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -36,7 +36,7 @@ compare_change () { } check_cache_at () { - clean_if_empty=`git diff-files -- "$1"` + clean_if_empty=$(git diff-files -- "$1") case "$clean_if_empty" in '') echo "$1: clean" ;; ?*) echo "$1: dirty" ;; @@ -68,14 +68,14 @@ test_expect_success \ echo rezrov >rezrov && echo yomin >yomin && git update-index --add nitfol bozbar rezrov && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH && cat bozbar-new >bozbar && git update-index --add frotz bozbar --force-remove rezrov && git ls-files --stage >M.out && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && git diff-tree $treeH $treeM' @@ -315,7 +315,7 @@ test_expect_success \ 'rm -f .git/index && echo DF >DF && git update-index --add DF && - treeDF=`git write-tree` && + treeDF=$(git write-tree) && echo treeDF $treeDF && git ls-tree $treeDF && @@ -323,7 +323,7 @@ test_expect_success \ mkdir DF && echo DF/DF >DF/DF && git update-index --add --remove DF DF/DF && - treeDFDF=`git write-tree` && + treeDFDF=$(git write-tree) && echo treeDFDF $treeDFDF && git ls-tree $treeDFDF && git ls-files --stage >DFDF.out' @@ -345,7 +345,7 @@ test_expect_success \ 'rm -f .git/index && : >a && git update-index --add a && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && git ls-files --stage >treeM.out && @@ -354,7 +354,7 @@ test_expect_success \ git update-index --remove a && mkdir a && : >a/b && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH' @@ -372,7 +372,7 @@ test_expect_success \ mkdir c && : >c/d && git update-index --add a c/d && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && git ls-files --stage >treeM.out && @@ -381,7 +381,7 @@ test_expect_success \ mkdir a && : >a/b && git update-index --add --remove a a/b && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH' From 9b3bc877f0b01826beaa3ef00b5e3b2c49fb09cc Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:33 -0700 Subject: [PATCH 121/760] t1002-read-tree-m-u-2way.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1002-read-tree-m-u-2way.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh index a847709a1354a8..fed877b20f428a 100755 --- a/t/t1002-read-tree-m-u-2way.sh +++ b/t/t1002-read-tree-m-u-2way.sh @@ -21,7 +21,7 @@ compare_change () { } check_cache_at () { - clean_if_empty=`git diff-files -- "$1"` + clean_if_empty=$(git diff-files -- "$1") case "$clean_if_empty" in '') echo "$1: clean" ;; ?*) echo "$1: dirty" ;; @@ -41,14 +41,14 @@ test_expect_success \ echo bozbar >bozbar && echo rezrov >rezrov && git update-index --add nitfol bozbar rezrov && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH && echo gnusto >bozbar && git update-index --add frotz bozbar --force-remove rezrov && git ls-files --stage >M.out && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && sum bozbar frotz nitfol >M.sum && @@ -318,7 +318,7 @@ test_expect_success \ 'rm -f .git/index && echo DF >DF && git update-index --add DF && - treeDF=`git write-tree` && + treeDF=$(git write-tree) && echo treeDF $treeDF && git ls-tree $treeDF && @@ -326,7 +326,7 @@ test_expect_success \ mkdir DF && echo DF/DF >DF/DF && git update-index --add --remove DF DF/DF && - treeDFDF=`git write-tree` && + treeDFDF=$(git write-tree) && echo treeDFDF $treeDFDF && git ls-tree $treeDFDF && git ls-files --stage >DFDF.out' From 7f311eb54ba45e1bcdda0900da891e4652614b30 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:34 -0700 Subject: [PATCH 122/760] t1003-read-tree-prefix.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1003-read-tree-prefix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t1003-read-tree-prefix.sh b/t/t1003-read-tree-prefix.sh index 8c6d67edda1468..b6111cd150fdd6 100755 --- a/t/t1003-read-tree-prefix.sh +++ b/t/t1003-read-tree-prefix.sh @@ -11,7 +11,7 @@ test_description='git read-tree --prefix test. test_expect_success setup ' echo hello >one && git update-index --add one && - tree=`git write-tree` && + tree=$(git write-tree) && echo tree is $tree ' From 77317c0c5c24e799a397b7d32080a9490fc23b11 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:35 -0700 Subject: [PATCH 123/760] t1004-read-tree-m-u-wf.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1004-read-tree-m-u-wf.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t1004-read-tree-m-u-wf.sh b/t/t1004-read-tree-m-u-wf.sh index 3e72aff470f8d9..c70cf423008cfb 100755 --- a/t/t1004-read-tree-m-u-wf.sh +++ b/t/t1004-read-tree-m-u-wf.sh @@ -30,7 +30,7 @@ test_expect_success 'two-way not clobbering' ' echo >file2 master creates untracked file2 && echo >subdir/file2 master creates untracked subdir/file2 && - if err=`read_tree_u_must_succeed -m -u master side 2>&1` + if err=$(read_tree_u_must_succeed -m -u master side 2>&1) then echo should have complained false @@ -43,7 +43,7 @@ echo file2 >.gitignore test_expect_success 'two-way with incorrect --exclude-per-directory (1)' ' - if err=`read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1` + if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1) then echo should have complained false @@ -54,7 +54,7 @@ test_expect_success 'two-way with incorrect --exclude-per-directory (1)' ' test_expect_success 'two-way with incorrect --exclude-per-directory (2)' ' - if err=`read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1` + if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1) then echo should have complained false @@ -95,7 +95,7 @@ test_expect_success 'three-way not clobbering a working tree file' ' git checkout master && echo >file3 file three created in master, untracked && echo >subdir/file3 file three created in master, untracked && - if err=`read_tree_u_must_succeed -m -u branch-point master side 2>&1` + if err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1) then echo should have complained false From c9e454ccef2f572ce532e29b9d1317c02764545e Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:36 -0700 Subject: [PATCH 124/760] t1020-subdirectory.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1020-subdirectory.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 6902320e819651..62c0d25af4ca1c 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -20,27 +20,27 @@ test_expect_success setup ' test_expect_success 'update-index and ls-files' ' git update-index --add one && - case "`git ls-files`" in + case "$(git ls-files)" in one) echo pass one ;; *) echo bad one; exit 1 ;; esac && ( cd dir && git update-index --add two && - case "`git ls-files`" in + case "$(git ls-files)" in two) echo pass two ;; *) echo bad two; exit 1 ;; esac ) && - case "`git ls-files`" in + case "$(git ls-files)" in dir/two"$LF"one) echo pass both ;; *) echo bad; exit 1 ;; esac ' test_expect_success 'cat-file' ' - two=`git ls-files -s dir/two` && - two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` && + two=$(git ls-files -s dir/two) && + two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") && echo "$two" && git cat-file -p "$two" >actual && cmp dir/two actual && @@ -55,18 +55,18 @@ rm -f actual dir/actual test_expect_success 'diff-files' ' echo a >>one && echo d >>dir/two && - case "`git diff-files --name-only`" in + case "$(git diff-files --name-only)" in dir/two"$LF"one) echo pass top ;; *) echo bad top; exit 1 ;; esac && # diff should not omit leading paths ( cd dir && - case "`git diff-files --name-only`" in + case "$(git diff-files --name-only)" in dir/two"$LF"one) echo pass subdir ;; *) echo bad subdir; exit 1 ;; esac && - case "`git diff-files --name-only .`" in + case "$(git diff-files --name-only .)" in dir/two) echo pass subdir limited ;; *) echo bad subdir limited; exit 1 ;; esac @@ -74,11 +74,11 @@ test_expect_success 'diff-files' ' ' test_expect_success 'write-tree' ' - top=`git write-tree` && + top=$(git write-tree) && echo $top && ( cd dir && - sub=`git write-tree` && + sub=$(git write-tree) && echo $sub && test "z$top" = "z$sub" ) @@ -96,7 +96,7 @@ test_expect_success 'checkout-index' ' test_expect_success 'read-tree' ' rm -f one dir/two && - tree=`git write-tree` && + tree=$(git write-tree) && read_tree_u_must_succeed --reset -u "$tree" && cmp one original.one && cmp dir/two original.two && From 714c71b2b1531f7e1099d17ab8ae03fa21f4b88c Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Mon, 28 Apr 2014 05:57:37 -0700 Subject: [PATCH 125/760] t1050-large.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1050-large.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t1050-large.sh b/t/t1050-large.sh index fd105280092b7f..aea493646e4400 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -131,7 +131,7 @@ test_expect_success 'git-show a large file' ' ' test_expect_success 'index-pack' ' - git clone file://"`pwd`"/.git foo && + git clone file://"$(pwd)"/.git foo && GIT_DIR=non-existent git index-pack --strict --verify foo/.git/objects/pack/*.pack ' @@ -140,7 +140,7 @@ test_expect_success 'repack' ' ' test_expect_success 'pack-objects with large loose object' ' - SHA1=`git hash-object huge` && + SHA1=$(git hash-object huge) && test_create_repo loose && echo $SHA1 | git pack-objects --stdout | GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects && From de3d8bb7736cafae0ff10e047e2afa994b1dd901 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 29 Apr 2014 23:08:29 -0500 Subject: [PATCH 126/760] rerere: fix for merge.conflictstyle If we use a different conflict style `git rerere forget` is not able to find the matching conflict SHA-1 because the diff generated is actually different from what `git merge` generated, due to the XDL_MERGE_* option differences among the codepaths. The fix is to call git_xmerge_config() so that git_xmerge_style is set properly and the diffs match. Signed-off-by: Felipe Contreras Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/rerere.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/rerere.c b/builtin/rerere.c index 4e51addb3e1354..98eb8c5404914e 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -60,6 +60,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, rerere_usage, 0); + git_config(git_xmerge_config, NULL); + if (autoupdate == 1) flags = RERERE_AUTOUPDATE; if (autoupdate == 0) From cba1262100df44bdb2cd5a00741562afb3eeb9fd Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:22:54 -0700 Subject: [PATCH 127/760] t3905-stash-include-untracked.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t3905-stash-include-untracked.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh index a5e7e6b2ba3138..f372fc8ca8e3b3 100755 --- a/t/t3905-stash-include-untracked.sh +++ b/t/t3905-stash-include-untracked.sh @@ -96,8 +96,8 @@ test_expect_success 'stash pop after save --include-untracked leaves files untra git stash pop && git status --porcelain >actual && test_cmp expect actual && - test "1" = "`cat file2`" && - test untracked = "`cat untracked/untracked`" + test "1" = "$(cat file2)" && + test untracked = "$(cat untracked/untracked)" ' git clean --force --quiet -d From a4cf6b4b91835c1d8d13ebb5cf3ce9241e181f1b Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:22:55 -0700 Subject: [PATCH 128/760] t3910-mac-os-precompose.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t3910-mac-os-precompose.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh index e4ba6013e41927..96941e94cc3b50 100755 --- a/t/t3910-mac-os-precompose.sh +++ b/t/t3910-mac-os-precompose.sh @@ -14,13 +14,13 @@ then fi # create utf-8 variables -Adiarnfc=`printf '\303\204'` -Adiarnfd=`printf 'A\314\210'` +Adiarnfc=$(printf '\303\204') +Adiarnfd=$(printf 'A\314\210') -Odiarnfc=`printf '\303\226'` -Odiarnfd=`printf 'O\314\210'` -AEligatu=`printf '\303\206'` -Invalidu=`printf '\303\377'` +Odiarnfc=$(printf '\303\226') +Odiarnfd=$(printf 'O\314\210') +AEligatu=$(printf '\303\206') +Invalidu=$(printf '\303\377') #Create a string with 255 bytes (decomposed) @@ -35,7 +35,7 @@ Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte Alongc=$Alongc$AEligatu$AEligatu #254 Byte test_expect_success "detect if nfd needed" ' - precomposeunicode=`git config core.precomposeunicode` && + precomposeunicode=$(git config core.precomposeunicode) && test "$precomposeunicode" = true && git config core.precomposeunicode true ' @@ -146,7 +146,7 @@ test_expect_success "respect git config --global core.precomposeunicode" ' git config --global core.precomposeunicode true && rm -rf .git && git init && - precomposeunicode=`git config core.precomposeunicode` && + precomposeunicode=$(git config core.precomposeunicode) && test "$precomposeunicode" = "true" ' From e1d6b55d5db4c1ad305b5ac6e4f1bb4bea3c1bee Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:22:56 -0700 Subject: [PATCH 129/760] t4006-diff-mode.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4006-diff-mode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh index 05911492ca6df3..76f643b2c2a2c7 100755 --- a/t/t4006-diff-mode.sh +++ b/t/t4006-diff-mode.sh @@ -13,7 +13,7 @@ sed_script='s/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /' test_expect_success 'setup' ' echo frotz >rezrov && git update-index --add rezrov && - tree=`git write-tree` && + tree=$(git write-tree) && echo $tree ' From 38b2e5d12cbe681bff8f31cf10e3de8bd6f6db52 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:22:57 -0700 Subject: [PATCH 130/760] t4010-diff-pathspec.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4010-diff-pathspec.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh index 2bb973655bf043..bf078418662c4b 100755 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@ -18,7 +18,7 @@ test_expect_success \ mkdir path1 && echo rezrov >path1/file1 && git update-index --add file0 path1/file1 && - tree=`git write-tree` && + tree=$(git write-tree) && echo "$tree" && echo nitfol >file0 && echo yomin >path1/file1 && @@ -131,7 +131,7 @@ test_expect_success 'diff multiple wildcard pathspecs' ' mkdir path2 && echo rezrov >path2/file1 && git update-index --add path2/file1 && - tree3=`git write-tree` && + tree3=$(git write-tree) && git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && cat <<-\EOF >expect && path1/file1 From e6ce6f4c7a8bcb2a77e664d0dfc42ee9c2d164d0 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:22:58 -0700 Subject: [PATCH 131/760] t4012-diff-binary.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4012-diff-binary.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 1215ae544b6915..643d729157d23c 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -67,18 +67,18 @@ test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' ' git diff >output && sed -e "s/-CIT/xCIT/" broken && test_must_fail git apply --stat --summary broken 2>detected && - detected=`cat detected` && - detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && - detected=`sed -ne "${detected}p" broken` && + detected=$(cat detected) && + detected=$(expr "$detected" : "fatal.*at line \\([0-9]*\\)\$") && + detected=$(sed -ne "${detected}p" broken) && test "$detected" = xCIT ' test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' ' git diff --binary | sed -e "s/-CIT/xCIT/" >broken && test_must_fail git apply --stat --summary broken 2>detected && - detected=`cat detected` && - detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && - detected=`sed -ne "${detected}p" broken` && + detected=$(cat detected) && + detected=$(expr "$detected" : "fatal.*at line \\([0-9]*\\)\$") && + detected=$(sed -ne "${detected}p" broken) && test "$detected" = xCIT ' @@ -88,7 +88,7 @@ test_expect_success 'initial commit' 'git commit -a -m initial' test_expect_success 'diff-index with --binary' ' echo AIT >a && mv b e && echo CIT >c && cat e >d && git update-index --add --remove a b c d e && - tree0=`git write-tree` && + tree0=$(git write-tree) && git diff --cached --binary >current && git apply --stat --summary current ' @@ -96,7 +96,7 @@ test_expect_success 'diff-index with --binary' ' test_expect_success 'apply binary patch' ' git reset --hard && git apply --binary --index Date: Wed, 30 Apr 2014 09:22:59 -0700 Subject: [PATCH 132/760] t4013-diff-various.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4013-diff-various.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index e77c09c37eede2..805b055c899e7c 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -107,14 +107,14 @@ test_expect_success setup ' +*++ [initial] Initial EOF -V=`git version | sed -e 's/^git version //' -e 's/\./\\./g'` +V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') while read cmd do case "$cmd" in '' | '#'*) continue ;; esac - test=`echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g'` - pfx=`printf "%04d" $test_count` + test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g') + pfx=$(printf "%04d" $test_count) expect="$TEST_DIRECTORY/t4013/diff.$test" actual="$pfx-diff.$test" From 54835fc57ea16ed19d1689b37073806537f14cf7 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:00 -0700 Subject: [PATCH 133/760] t4014-format-patch.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4014-format-patch.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 73194b2c3dbe26..f9ed598afbba10 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -43,7 +43,7 @@ test_expect_success setup ' test_expect_success "format-patch --ignore-if-in-upstream" ' git format-patch --stdout master..side >patch0 && - cnt=`grep "^From " patch0 | wc -l` && + cnt=$(grep "^From " patch0 | wc -l) && test $cnt = 3 ' @@ -52,7 +52,7 @@ test_expect_success "format-patch --ignore-if-in-upstream" ' git format-patch --stdout \ --ignore-if-in-upstream master..side >patch1 && - cnt=`grep "^From " patch1 | wc -l` && + cnt=$(grep "^From " patch1 | wc -l) && test $cnt = 2 ' @@ -69,7 +69,7 @@ test_expect_success "format-patch doesn't consider merge commits" ' git checkout -b merger master && test_tick && git merge --no-ff slave && - cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` && + cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) && test $cnt = 3 ' @@ -77,7 +77,7 @@ test_expect_success "format-patch result applies" ' git checkout -b rebuild-0 master && git am -3 patch0 && - cnt=`git rev-list master.. | wc -l` && + cnt=$(git rev-list master.. | wc -l) && test $cnt = 2 ' @@ -85,7 +85,7 @@ test_expect_success "format-patch --ignore-if-in-upstream result applies" ' git checkout -b rebuild-1 master && git am -3 patch1 && - cnt=`git rev-list master.. | wc -l` && + cnt=$(git rev-list master.. | wc -l) && test $cnt = 2 ' From 20cb28baf9d03c779f590baa475610788bc6eabf Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:01 -0700 Subject: [PATCH 134/760] t4036-format-patch-signer-mime.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4036-format-patch-signer-mime.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4036-format-patch-signer-mime.sh b/t/t4036-format-patch-signer-mime.sh index ba43f185494630..98d9713d8b2454 100755 --- a/t/t4036-format-patch-signer-mime.sh +++ b/t/t4036-format-patch-signer-mime.sh @@ -42,7 +42,7 @@ test_expect_success 'attach and signoff do not duplicate mime headers' ' GIT_COMMITTER_NAME="はまの ふにおう" \ git format-patch -s --stdout -1 --attach >output && - test `grep -ci ^MIME-Version: output` = 1 + test $(grep -ci ^MIME-Version: output) = 1 ' From 7c0c51baa4855c76a71820fb279c2ca1580d374b Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:02 -0700 Subject: [PATCH 135/760] t4038-diff-combined.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4038-diff-combined.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index 1019d7b35fcb35..41913c3aa30de6 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -94,7 +94,7 @@ test_expect_success 'setup for --cc --raw' ' blob=$(echo file | git hash-object --stdin -w) && base_tree=$(echo "100644 blob $blob file" | git mktree) && trees= && - for i in `test_seq 1 40` + for i in $(test_seq 1 40) do blob=$(echo file$i | git hash-object --stdin -w) && trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" From 274447aa6bbe84c4e65607f48df18380766d24fe Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:03 -0700 Subject: [PATCH 136/760] t4057-diff-combined-paths.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4057-diff-combined-paths.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4057-diff-combined-paths.sh b/t/t4057-diff-combined-paths.sh index 097e63215e1ffc..dff36b77ec8856 100755 --- a/t/t4057-diff-combined-paths.sh +++ b/t/t4057-diff-combined-paths.sh @@ -5,7 +5,7 @@ test_description='combined diff show only paths that are different to all parent . ./test-lib.sh # verify that diffc.expect matches output of -# `git diff -c --name-only HEAD HEAD^ HEAD^2` +# $(git diff -c --name-only HEAD HEAD^ HEAD^2) diffc_verify () { git diff -c --name-only HEAD HEAD^ HEAD^2 >diffc.actual && test_cmp diffc.expect diffc.actual From 991a9c3af984eb28b31f8642c97fd9ddb29cadc4 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:04 -0700 Subject: [PATCH 137/760] t4116-apply-reverse.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4116-apply-reverse.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index 1e4d4380bf01c0..ce8567f496438c 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -30,10 +30,10 @@ test_expect_success setup ' test_expect_success 'apply in forward' ' - T0=`git rev-parse "second^{tree}"` && + T0=$(git rev-parse "second^{tree}") && git reset --hard initial && git apply --index --binary patch && - T1=`git write-tree` && + T1=$(git write-tree) && test "$T0" = "$T1" ' @@ -62,22 +62,22 @@ test_expect_success 'setup separate repository lacking postimage' ' test_expect_success 'apply in forward without postimage' ' - T0=`git rev-parse "second^{tree}"` && + T0=$(git rev-parse "second^{tree}") && ( cd initial && git apply --index --binary ../patch && - T1=`git write-tree` && + T1=$(git write-tree) && test "$T0" = "$T1" ) ' test_expect_success 'apply in reverse without postimage' ' - T0=`git rev-parse "initial^{tree}"` && + T0=$(git rev-parse "initial^{tree}") && ( cd second && git apply --index --binary --reverse ../patch && - T1=`git write-tree` && + T1=$(git write-tree) && test "$T0" = "$T1" ) ' From 6003eb13c69516dfedc9466aeb8c3a32a054c286 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:05 -0700 Subject: [PATCH 138/760] t4119-apply-config.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4119-apply-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4119-apply-config.sh b/t/t4119-apply-config.sh index 3d0384daa8a7b7..c393be691be42a 100755 --- a/t/t4119-apply-config.sh +++ b/t/t4119-apply-config.sh @@ -68,7 +68,7 @@ test_expect_success 'apply --whitespace=strip from config' ' check_result sub/file1 ' -D=`pwd` +D=$(pwd) test_expect_success 'apply --whitespace=strip in subdir' ' From ce21ccfae0729fd73b54f3ae4935fc7769343561 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:06 -0700 Subject: [PATCH 139/760] t4204-patch-id.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4204-patch-id.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh index d2c930de87f721..7940f6f0b952b5 100755 --- a/t/t4204-patch-id.sh +++ b/t/t4204-patch-id.sh @@ -45,8 +45,8 @@ test_expect_success 'patch-id supports git-format-patch output' ' git checkout same && git format-patch -1 --stdout | calc_patch_id same && test_cmp patch-id_master patch-id_same && - set `git format-patch -1 --stdout | git patch-id` && - test "$2" = `git rev-parse HEAD` + set $(git format-patch -1 --stdout | git patch-id) && + test "$2" = $(git rev-parse HEAD) ' test_expect_success 'whitespace is irrelevant in footer' ' From f5efd5196cf2d7931785f663b219b40fd204e1b1 Mon Sep 17 00:00:00 2001 From: Elia Pinto Date: Wed, 30 Apr 2014 09:23:07 -0700 Subject: [PATCH 140/760] t5000-tar-tree.sh: use the $( ... ) construct for command substitution The Git CodingGuidelines prefer the $(...) construct for command substitution instead of using the backquotes `...`. The backquoted form is the traditional method for command substitution, and is supported by POSIX. However, all but the simplest uses become complicated quickly. In particular, embedded command substitutions and/or the use of double quotes require careful escaping with the backslash character. The patch was generated by: for _f in $(find . -name "*.sh") do sed -i 's@`\(.*\)`@$(\1)@g' ${_f} done and then carefully proof-read. Signed-off-by: Elia Pinto Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t5000-tar-tree.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 1cf0a4e10301fe..74fc5a88ecdaf6 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -123,7 +123,7 @@ test_expect_success \ 'add files to repository' \ 'find a -type f | xargs git update-index --add && find a -type l | xargs git update-index --add && - treeid=`git write-tree` && + treeid=$(git write-tree) && echo $treeid >treeid && git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ git commit-tree $treeid remote.tar && test_must_fail git archive --remote=. $sha1 >remote.tar @@ -215,7 +215,7 @@ test_expect_success 'clients cannot access unreachable commits' ' test_expect_success 'upload-archive can allow unreachable commits' ' test_commit unreachable1 && - sha1=`git rev-parse HEAD` && + sha1=$(git rev-parse HEAD) && git reset --hard HEAD^ && git archive $sha1 >remote.tar && test_config uploadarchive.allowUnreachable true && From 1d39dbecc2e55c2f723e2c2af43072891317dde9 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 29 Apr 2014 15:21:34 -0400 Subject: [PATCH 141/760] docs: document RUN_SETUP_GENTLY and clarify RUN_SETUP We only said what happens when we find the Git directory under RUN_SETUP, without saying what happens otherwise. Signed-off-by: David Turner Signed-off-by: Junio C Hamano --- Documentation/technical/api-builtin.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Documentation/technical/api-builtin.txt b/Documentation/technical/api-builtin.txt index e3d6e7a79a6c21..22a39b929932b7 100644 --- a/Documentation/technical/api-builtin.txt +++ b/Documentation/technical/api-builtin.txt @@ -22,11 +22,14 @@ Git: where options is the bitwise-or of: `RUN_SETUP`:: - - Make sure there is a Git directory to work on, and if there is a - work tree, chdir to the top of it if the command was invoked - in a subdirectory. If there is no work tree, no chdir() is - done. + If there is not a Git directory to work on, abort. If there + is a work tree, chdir to the top of it if the command was + invoked in a subdirectory. If there is no work tree, no + chdir() is done. + +`RUN_SETUP_GENTLY`:: + If there is a Git directory, chdir as per RUN_SETUP, otherwise, + don't chdir anywhere. `USE_PAGER`:: From 3cf6bb34063406e107f51aa52db67d65839f5e58 Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Fri, 2 May 2014 08:55:29 +0100 Subject: [PATCH 142/760] compat/bswap.h: detect endianness on more platforms that don't use BYTE_ORDER Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- compat/bswap.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/compat/bswap.h b/compat/bswap.h index 120c6c1d375596..f08a9fe87c7c84 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -101,19 +101,34 @@ static inline uint64_t git_bswap64(uint64_t x) #undef ntohll #undef htonll -#if !defined(__BYTE_ORDER) -# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) -# define __BYTE_ORDER BYTE_ORDER -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __BIG_ENDIAN BIG_ENDIAN +#if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) + +# define GIT_BYTE_ORDER BYTE_ORDER +# define GIT_LITTLE_ENDIAN LITTLE_ENDIAN +# define GIT_BIG_ENDIAN BIG_ENDIAN + +#elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) + +# define GIT_BYTE_ORDER __BYTE_ORDER +# define GIT_LITTLE_ENDIAN __LITTLE_ENDIAN +# define GIT_BIG_ENDIAN __BIG_ENDIAN + +#else + +# define GIT_BIG_ENDIAN 4321 +# define GIT_LITTLE_ENDIAN 1234 + +# if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) +# define GIT_BYTE_ORDER GIT_BIG_ENDIAN +# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) +# define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN +# else +# error "Cannot determine endianness" # endif -#endif -#if !defined(__BYTE_ORDER) -# error "Cannot determine endianness" #endif -#if __BYTE_ORDER == __BIG_ENDIAN +#if GIT_BYTE_ORDER == GIT_BIG_ENDIAN # define ntohll(n) (n) # define htonll(n) (n) #else From 839fa9c500c7771d15831e2bcf77697cd70620f9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 2 May 2014 12:36:10 -0700 Subject: [PATCH 143/760] compat/bswap.h: restore preference __BIG_ENDIAN over BIG_ENDIAN The previous commit swaps the order we check the macros defined by the compiler and the system headers from the original. Since the order of check should not matter (i.e. it is insane to define both __BIG_ENDIAN and friends and BIG_ENDIAN and friends and in a conflicting way), it is the most conservative thing to do not to change it. Signed-off-by: Junio C Hamano --- compat/bswap.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compat/bswap.h b/compat/bswap.h index f08a9fe87c7c84..c4293db004dab6 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -101,18 +101,18 @@ static inline uint64_t git_bswap64(uint64_t x) #undef ntohll #undef htonll -#if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) - -# define GIT_BYTE_ORDER BYTE_ORDER -# define GIT_LITTLE_ENDIAN LITTLE_ENDIAN -# define GIT_BIG_ENDIAN BIG_ENDIAN - -#elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) # define GIT_BYTE_ORDER __BYTE_ORDER # define GIT_LITTLE_ENDIAN __LITTLE_ENDIAN # define GIT_BIG_ENDIAN __BIG_ENDIAN +#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) + +# define GIT_BYTE_ORDER BYTE_ORDER +# define GIT_LITTLE_ENDIAN LITTLE_ENDIAN +# define GIT_BIG_ENDIAN BIG_ENDIAN + #else # define GIT_BIG_ENDIAN 4321 From dd30800bcd236233c82da80bba0d00956a246260 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:23:26 -0700 Subject: [PATCH 144/760] CodingGuidelines: once it is in, it is not worth the code churn Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index f424dbd75c80ab..c405b0b9dff81f 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -18,6 +18,14 @@ code. For Git in general, three rough rules are: judgement call, the decision based more on real world constraints people face than what the paper standard says. + - Fixing style violations while working on a real change as a + preparatory clean-up step is good, but otherwise avoid useless code + churn for the sake of conforming to the style. + + "Once it _is_ in the tree, it's not really worth the patch noise to + go and fix it up." + Cf. http://article.gmane.org/gmane.linux.kernel/943020 + Make your code readable and sensible, and don't try to be clever. As for more concrete guidelines, just imitate the existing code From 79fc3ca1232099fd21e5bdef14c1b6fe1d2dbc1c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:24:08 -0700 Subject: [PATCH 145/760] CodingGuidelines: give an example for case/esac statement Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index c405b0b9dff81f..169b4358c93a84 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -42,7 +42,17 @@ For shell scripts specifically (not exhaustive): - We use tabs for indentation. - - Case arms are indented at the same depth as case and esac lines. + - Case arms are indented at the same depth as case and esac lines, + like this: + + case "$variable" in + pattern1) + do this + ;; + pattern2) + do that + ;; + esac - Redirection operators should be written with space before, but no space after them. In other words, write 'echo test >"$file"' From 6a49909b52b48592234da6a53bfe74ea34c302c6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:24:24 -0700 Subject: [PATCH 146/760] CodingGuidelines: give an example for redirection Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 169b4358c93a84..11704fb84cb3b9 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -61,6 +61,14 @@ For shell scripts specifically (not exhaustive): redirection target in a variable (as shown above), our code does so because some versions of bash issue a warning without the quotes. + (incorrect) + cat hello > world < universe + echo hello >$world + + (correct) + cat hello >world "$world" + - We prefer $( ... ) for command substitution; unlike ``, it properly nests. It should have been the way Bourne spelled it from day one, but unfortunately isn't. From 9dbe780174892a35d6f1e19495c13b9edb9d88fd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:24:52 -0700 Subject: [PATCH 147/760] CodingGuidelines: give an example for control statements Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 11704fb84cb3b9..47db6b3ce36a79 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -107,6 +107,17 @@ For shell scripts specifically (not exhaustive): "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for". + (incorrect) + if test -f hello; then + do this + fi + + (correct) + if test -f hello + then + do this + fi + - We prefer "test" over "[ ... ]". - We do not write the noiseword "function" in front of shell From 6117a3d4946e35c7d4a38c0b443891c81808a838 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:25:11 -0700 Subject: [PATCH 148/760] CodingGuidelines: give an example for shell function preamble Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 47db6b3ce36a79..0a574b204c00d2 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -123,9 +123,17 @@ For shell scripts specifically (not exhaustive): - We do not write the noiseword "function" in front of shell functions. - - We prefer a space between the function name and the parentheses. The - opening "{" should also be on the same line. - E.g.: my_function () { + - We prefer a space between the function name and the parentheses, + and no space inside the parentheses. The opening "{" should also + be on the same line. + + (incorrect) + my_function(){ + ... + + (correct) + my_function () { + ... - As to use of grep, stick to a subset of BRE (namely, no \{m,n\}, [::], [==], or [..]) for portability. From 691d0dd0a9c901286c2a0a28c30ec4d13bcd2032 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:25:47 -0700 Subject: [PATCH 149/760] CodingGuidelines: do not call the conditional statement "if()" The point immediately before it is about having SP after the control keyword. Spell it out as 'an "if" statement' instead. Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 0a574b204c00d2..aeaa82451e8ac6 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -194,7 +194,7 @@ For C programs: of "else if" statements, it can make sense to add braces to single line blocks. - - We try to avoid assignments inside if(). + - We try to avoid assignments in the condition of an "if" statement. - Try to make your code understandable. You may put comments in, but comments invariably tend to stale out when the code From 5db9ab82b94fab16e69b0228aaf1e972520bd04a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 30 Apr 2014 14:26:23 -0700 Subject: [PATCH 150/760] CodingGuidelines: on comparison There are arguments for writing a conditional as "a < b" rather than "b > a", or vice versa. Let's give guidance on which we prefer. See http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126 for the original discussion. Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index aeaa82451e8ac6..02ca67c4ca7d19 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -222,6 +222,33 @@ For C programs: - Double negation is often harder to understand than no negation at all. + - There are two schools of thought when it comes to comparison, + especially inside a loop. Some people prefer to have the less stable + value on the left hand side and the more stable value on the right hand + side, e.g. if you have a loop that counts variable i down to the + lower bound, + + while (i > lower_bound) { + do something; + i--; + } + + Other people prefer to have the textual order of values match the + actual order of values in their comparison, so that they can + mentally draw a number line from left to right and place these + values in order, i.e. + + while (lower_bound < i) { + do something; + i--; + } + + Both are valid, and we use both. However, the more "stable" the + stable side becomes, the more we tend to prefer the former + (comparison with a constant, "i > 0", is an extreme example). + Just do not mix styles in the same part of the code and mimic + existing styles in the neighbourhood. + - Some clever tricks, like using the !! operator with arithmetic constructs, can be extremely confusing to others. Avoid them, unless there is a compelling reason to use them. From f26443da0449c459dab8b91d963bd91dd4335657 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 2 May 2014 13:42:39 -0700 Subject: [PATCH 151/760] CodingGuidelines: on splitting a long line Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 02ca67c4ca7d19..3d08671ad3fee3 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -249,6 +249,61 @@ For C programs: Just do not mix styles in the same part of the code and mimic existing styles in the neighbourhood. + - There are two schools of thought when it comes to splitting a long + logical line into multiple lines. Some people push the second and + subsequent lines far enough to the right with tabs and align them: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of || + the_source_text) { + ... + + while other people prefer to align the second and the subsequent + lines with the column immediately inside the opening parenthesis, + with tabs and spaces, following our "tabstop is always a multiple + of 8" convention: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of || + the_source_text) { + ... + + Both are valid, and we use both. Again, just do not mix styles in + the same part of the code and mimic existing styles in the + neighbourhood. + + - When splitting a long logical line, some people change line before + a binary operator, so that the result looks like a parse tree when + you turn your head 90-degrees counterclockwise: + + if (the_beginning_of_a_very_long_expression_that_has_to + || span_more_than_a_single_line_of_the_source_text) { + + while other people prefer to leave the operator at the end of the + line: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of_the_source_text) { + + Both are valid, but we tend to use the latter more, unless the + expression gets fairly complex, in which case the former tends to + be easier to read. Again, just do not mix styles in the same part + of the code and mimic existing styles in the neighbourhood. + + - When splitting a long logical line, with everything else being + equal, it is preferable to split after the operator at higher + level in the parse tree. That is, this is more preferable: + + if (a_very_long_variable * that_is_used_in + + a_very_long_expression) { + ... + + than + + if (a_very_long_variable * + that_is_used_in + a_very_long_expression) { + ... + - Some clever tricks, like using the !! operator with arithmetic constructs, can be extremely confusing to others. Avoid them, unless there is a compelling reason to use them. From 4701026352ada1ebc36532272ca1e12897b1de11 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 1 May 2014 21:06:57 -0400 Subject: [PATCH 152/760] commit: use split_ident_line to compare author/committer Instead of string-wise comparing the author/committer lines with their timestamps truncated, we can use split_ident_line and ident_cmp. These functions are more robust than our ad-hoc parsing, though in practice it should not matter, as we just generated these ident lines ourselves. However, this will also allow us easy access to the timestamp and tz fields in future patches. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/commit.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 9cfef6c6cca619..728cc9bbfc9294 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -585,13 +585,11 @@ static void determine_author_info(struct strbuf *author_ident) } } -static char *cut_ident_timestamp_part(char *string) +static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf) { - char *ket = strrchr(string, '>'); - if (!ket || ket[1] != ' ') - die(_("Malformed ident string: '%s'"), string); - *++ket = '\0'; - return ket; + if (split_ident_line(id, buf->buf, buf->len) || + !sane_ident_split(id)) + die(_("Malformed ident string: '%s'"), buf->buf); } static int prepare_to_commit(const char *index_file, const char *prefix, @@ -755,7 +753,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (use_editor && include_status) { int ident_shown = 0; int saved_color_setting; - char *ai_tmp, *ci_tmp; + struct ident_split ci, ai; + if (whence != FROM_COMMIT) { if (cleanup_mode == CLEANUP_SCISSORS) wt_status_add_cut_line(s->fp); @@ -795,21 +794,24 @@ static int prepare_to_commit(const char *index_file, const char *prefix, status_printf_ln(s, GIT_COLOR_NORMAL, "%s", only_include_assumed); - ai_tmp = cut_ident_timestamp_part(author_ident->buf); - ci_tmp = cut_ident_timestamp_part(committer_ident.buf); - if (strcmp(author_ident->buf, committer_ident.buf)) + split_ident_or_die(&ai, author_ident); + split_ident_or_die(&ci, &committer_ident); + + if (ident_cmp(&ai, &ci)) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" - "Author: %s"), + "Author: %.*s <%.*s>"), ident_shown++ ? "" : "\n", - author_ident->buf); + (int)(ai.name_end - ai.name_begin), ai.name_begin, + (int)(ai.mail_end - ai.mail_begin), ai.mail_begin); if (!committer_ident_sufficiently_given()) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" - "Committer: %s"), + "Committer: %.*s <%.*s>"), ident_shown++ ? "" : "\n", - committer_ident.buf); + (int)(ci.name_end - ci.name_begin), ci.name_begin, + (int)(ci.mail_end - ci.mail_begin), ci.mail_begin); if (ident_shown) status_printf_ln(s, GIT_COLOR_NORMAL, ""); @@ -818,9 +820,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix, s->use_color = 0; commitable = run_status(s->fp, index_file, prefix, 1, s); s->use_color = saved_color_setting; - - *ai_tmp = ' '; - *ci_tmp = ' '; } else { unsigned char sha1[20]; const char *parent = "HEAD"; From d1053246554d176173893a5283dc0c0fb563ed03 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 1 May 2014 21:07:22 -0400 Subject: [PATCH 153/760] pretty: make show_ident_date public We use this function internally to format "Date" lines in commit logs, but other parts of the code will want it, too. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 7 +++++++ pretty.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cache.h b/cache.h index 107ac61b68f15b..dd9e689daf1249 100644 --- a/cache.h +++ b/cache.h @@ -1045,6 +1045,13 @@ struct ident_split { */ extern int split_ident_line(struct ident_split *, const char *, int); +/* + * Like show_date, but pull the timestamp and tz parameters from + * the ident_split. It will also sanity-check the values and produce + * a well-known sentinel date if they appear bogus. + */ +const char *show_ident_date(const struct ident_split *id, enum date_mode mode); + /* * Compare split idents for equality or strict ordering. Note that we * compare only the ident part of the line, ignoring any timestamp. diff --git a/pretty.c b/pretty.c index 3c43db558aee43..e1e2cad36d6d2d 100644 --- a/pretty.c +++ b/pretty.c @@ -393,8 +393,8 @@ static void add_rfc2047(struct strbuf *sb, const char *line, size_t len, strbuf_addstr(sb, "?="); } -static const char *show_ident_date(const struct ident_split *ident, - enum date_mode mode) +const char *show_ident_date(const struct ident_split *ident, + enum date_mode mode) { unsigned long date = 0; long tz = 0; From b7242b8c9e4b3c57a07c2a76d0337389605aadcc Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 1 May 2014 21:10:01 -0400 Subject: [PATCH 154/760] commit: print "Date" line when the user has set date When we make a commit and the author is not the same as the committer (e.g., because you used "-c $commit" or "--author=$somebody"), we print the author's name and email in both the commit-message template and as part of the commit summary. This is a safety check to give the user a chance to confirm that we are doing what they expect. This patch brings the same safety for the "date" field, which may be set by "-c" or by using "--date". Note that we explicitly do not set it for $GIT_AUTHOR_DATE, as it is probably not of interest when "git commit" is being fed its parameters by a script. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/commit.c | 19 +++++++++++++++++++ t/t3508-cherry-pick-many-commits.sh | 6 ++++++ t/t7501-commit.sh | 5 +++++ t/t7502-commit.sh | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/builtin/commit.c b/builtin/commit.c index 728cc9bbfc9294..a25661f34349f7 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -592,6 +592,11 @@ static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf) die(_("Malformed ident string: '%s'"), buf->buf); } +static int author_date_is_interesting(void) +{ + return author_message || force_date; +} + static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, @@ -805,6 +810,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix, (int)(ai.name_end - ai.name_begin), ai.name_begin, (int)(ai.mail_end - ai.mail_begin), ai.mail_begin); + if (author_date_is_interesting()) + status_printf_ln(s, GIT_COLOR_NORMAL, + _("%s" + "Date: %s"), + ident_shown++ ? "" : "\n", + show_ident_date(&ai, DATE_NORMAL)); + if (!committer_ident_sufficiently_given()) status_printf_ln(s, GIT_COLOR_NORMAL, _("%s" @@ -1355,6 +1367,13 @@ static void print_summary(const char *prefix, const unsigned char *sha1, strbuf_addstr(&format, "\n Author: "); strbuf_addbuf_percentquote(&format, &author_ident); } + if (author_date_is_interesting()) { + struct strbuf date = STRBUF_INIT; + format_commit_message(commit, "%ad", &date, &pctx); + strbuf_addstr(&format, "\n Date: "); + strbuf_addbuf_percentquote(&format, &date); + strbuf_release(&date); + } if (!committer_ident_sufficiently_given()) { strbuf_addstr(&format, "\n Committer: "); strbuf_addbuf_percentquote(&format, &committer_ident); diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh index 19c99d7ef1bc02..b457333e1865de 100755 --- a/t/t3508-cherry-pick-many-commits.sh +++ b/t/t3508-cherry-pick-many-commits.sh @@ -65,12 +65,15 @@ test_expect_success 'output to keep user entertained during multi-pick' ' cat <<-\EOF >expected && [master OBJID] second Author: A U Thor + Date: Thu Apr 7 15:14:13 2005 -0700 1 file changed, 1 insertion(+) [master OBJID] third Author: A U Thor + Date: Thu Apr 7 15:15:13 2005 -0700 1 file changed, 1 insertion(+) [master OBJID] fourth Author: A U Thor + Date: Thu Apr 7 15:16:13 2005 -0700 1 file changed, 1 insertion(+) EOF @@ -98,14 +101,17 @@ test_expect_success 'output during multi-pick indicates merge strategy' ' Trying simple merge. [master OBJID] second Author: A U Thor + Date: Thu Apr 7 15:14:13 2005 -0700 1 file changed, 1 insertion(+) Trying simple merge. [master OBJID] third Author: A U Thor + Date: Thu Apr 7 15:15:13 2005 -0700 1 file changed, 1 insertion(+) Trying simple merge. [master OBJID] fourth Author: A U Thor + Date: Thu Apr 7 15:16:13 2005 -0700 1 file changed, 1 insertion(+) EOF diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index d58b097ff3b3d0..5a76823d4c9433 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -346,6 +346,11 @@ test_expect_success 'amend commit to fix date' ' ' +test_expect_success 'commit mentions forced date in output' ' + git commit --amend --date=2010-01-02T03:04:05 >output && + grep "Date: *Sat Jan 2 03:04:05 2010" output +' + test_expect_success 'commit complains about bogus date' ' test_must_fail git commit --amend --date=10.11.2010 ' diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 9a3f3a1b4151eb..6465cd59afb6dc 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -344,6 +344,13 @@ test_expect_success 'message shows author when it is not equal to committer' ' .git/COMMIT_EDITMSG ' +test_expect_success 'message shows date when it is explicitly set' ' + git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" && + test_i18ngrep \ + "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \ + .git/COMMIT_EDITMSG +' + test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' echo >>negative && From 14ac2864dcd566a025e449ab9db6b5dc57744a32 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 1 May 2014 21:12:42 -0400 Subject: [PATCH 155/760] commit: accept more date formats for "--date" Right now we pass off the string found by "--date" straight to the fmt_ident function, which will use our strict parse_date to normalize it. However, this means obvious things like "--date=now" or "--date=2.days.ago" will not work. Instead, let's fallback to the approxidate function to handle this for us. Note that we must try parse_date ourselves first, even though approxidate will try strict parsing itself. The reason is that approxidate throws away any timezone information it sees from the strict parsing, and we want to preserve it. So asking for: git commit --date="@1234567890 -0700" continues to set the date in -0700, regardless of what the local timezone is. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/commit.c | 27 +++++++++++++++++++++++++-- t/t7501-commit.sh | 12 ++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index a25661f34349f7..d1c90db95d3f89 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -526,10 +526,29 @@ static int sane_ident_split(struct ident_split *person) return 1; } +static int parse_force_date(const char *in, char *out, int len) +{ + if (len < 1) + return -1; + *out++ = '@'; + len--; + + if (parse_date(in, out, len) < 0) { + int errors = 0; + unsigned long t = approxidate_careful(in, &errors); + if (errors) + return -1; + snprintf(out, len, "%lu", t); + } + + return 0; +} + static void determine_author_info(struct strbuf *author_ident) { char *name, *email, *date; struct ident_split author; + char date_buf[64]; name = getenv("GIT_AUTHOR_NAME"); email = getenv("GIT_AUTHOR_EMAIL"); @@ -574,8 +593,12 @@ static void determine_author_info(struct strbuf *author_ident) email = xstrndup(lb + 2, rb - (lb + 2)); } - if (force_date) - date = force_date; + if (force_date) { + if (parse_force_date(force_date, date_buf, sizeof(date_buf))) + die(_("invalid date format: %s"), force_date); + date = date_buf; + } + strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT)); if (!split_ident_line(&author, author_ident->buf, author_ident->len) && sane_ident_split(&author)) { diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 5a76823d4c9433..63e04277f99a08 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -351,8 +351,16 @@ test_expect_success 'commit mentions forced date in output' ' grep "Date: *Sat Jan 2 03:04:05 2010" output ' -test_expect_success 'commit complains about bogus date' ' - test_must_fail git commit --amend --date=10.11.2010 +test_expect_success 'commit complains about completely bogus dates' ' + test_must_fail git commit --amend --date=seventeen +' + +test_expect_success 'commit --date allows approxidate' ' + git commit --amend \ + --date="midnight the 12th of october, anno domini 1979" && + echo "Fri Oct 12 00:00:00 1979 +0000" >expect && + git log -1 --format=%ad >actual && + test_cmp expect actual ' test_expect_success 'sign off (1)' ' From a08e803d76dff22d8c2b428a725be247425963af Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Fri, 7 Jan 2011 17:20:21 +0100 Subject: [PATCH 156/760] MSVC: link dynamically to the CRT Dynamic linking is generally preferred over static linking, and MSVCRT.dll has been integral part of Windows for a long time. This also fixes linker warnings for _malloc and _free in zlib.lib, which seems to be compiled for MSVCRT.dll already. The DLL version also exports some of the CRT initialization functions, which are hidden in the static libcmt.lib (e.g. __wgetmainargs, required by subsequent Unicode patches). Signed-off-by: Karsten Blees Signed-off-by: Stepan Kasal Acked-by: Sebastian Schuberth Acked-by: Marat Radchenko Signed-off-by: Junio C Hamano --- config.mak.uname | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index 23a880365616c3..4a68c24eb2ad27 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -358,16 +358,16 @@ ifeq ($(uname_S),Windows) compat/win32/pthread.o compat/win32/syslog.o \ compat/win32/dirent.o COMPAT_CFLAGS = -D__USE_MINGW_ACCESS -DNOGDI -DHAVE_STRING_H -DHAVE_ALLOCA_H -Icompat -Icompat/regex -Icompat/win32 -DSTRIP_EXTENSION=\".exe\" - BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE -NODEFAULTLIB:MSVCRT.lib + BASIC_LDFLAGS = -IGNORE:4217 -IGNORE:4049 -NOLOGO -SUBSYSTEM:CONSOLE EXTLIBS = user32.lib advapi32.lib shell32.lib wininet.lib ws2_32.lib invalidcontinue.obj PTHREAD_LIBS = lib = ifndef DEBUG - BASIC_CFLAGS += -GL -Os -MT + BASIC_CFLAGS += -GL -Os -MD BASIC_LDFLAGS += -LTCG AR += -LTCG else - BASIC_CFLAGS += -Zi -MTd + BASIC_CFLAGS += -Zi -MDd endif X = .exe endif From 3330311c91124ff0f42996b02335d45bf7c75a31 Mon Sep 17 00:00:00 2001 From: James Denholm Date: Tue, 6 May 2014 22:41:45 +1000 Subject: [PATCH 157/760] contrib/subtree/Makefile: scrap unused $(gitdir) In 7ff8463dba0d74fc07a766bed457ae7afcc902b5, the references to gitdir were removed but the assignment itself wasn't. Hence, drop the gitdir assignment. Reviewed-by: Jeff King Signed-off-by: James Denholm Signed-off-by: Junio C Hamano --- contrib/subtree/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index 4030a168986d29..87797edeb30309 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -4,7 +4,6 @@ prefix ?= /usr/local mandir ?= $(prefix)/share/man libexecdir ?= $(prefix)/libexec/git-core -gitdir ?= $(shell git --exec-path) man1dir ?= $(mandir)/man1 gitver ?= $(word 3,$(shell git --version)) From daa22c6f8da466bd7a438f1bc27375fd737ffcf3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 6 May 2014 00:17:14 +0000 Subject: [PATCH 158/760] config: preserve config file permissions on edits Users may already store sensitive data such as imap.pass in .git/config; making the file world-readable when "git config" is called to edit means their password would be compromised on a shared system. [v2: updated for section renames, as noted by Junio] Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- config.c | 16 ++++++++++++++++ t/t1300-repo-config.sh | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/config.c b/config.c index 314d8ee740bea4..62de69e148be7e 100644 --- a/config.c +++ b/config.c @@ -1634,6 +1634,13 @@ int git_config_set_multivar_in_file(const char *config_filename, MAP_PRIVATE, in_fd, 0); close(in_fd); + if (fchmod(fd, st.st_mode & 07777) < 0) { + error("fchmod on %s failed: %s", + lock->filename, strerror(errno)); + ret = CONFIG_NO_WRITE; + goto out_free; + } + if (store.seen == 0) store.seen = 1; @@ -1782,6 +1789,7 @@ int git_config_rename_section_in_file(const char *config_filename, int out_fd; char buf[1024]; FILE *config_file; + struct stat st; if (new_name && !section_name_is_ok(new_name)) { ret = error("invalid section name: %s", new_name); @@ -1803,6 +1811,14 @@ int git_config_rename_section_in_file(const char *config_filename, goto unlock_and_out; } + fstat(fileno(config_file), &st); + + if (fchmod(out_fd, st.st_mode & 07777) < 0) { + ret = error("fchmod on %s failed: %s", + lock->filename, strerror(errno)); + goto out; + } + while (fgets(buf, sizeof(buf), config_file)) { int i; int length; diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 967359344dab81..ba41bc93ee5633 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -1154,4 +1154,14 @@ test_expect_failure 'adding a key into an empty section reuses header' ' test_cmp expect .git/config ' +test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' + chmod 0600 .git/config && + git config imap.pass Hunter2 && + perl -e \ + "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && + git config --rename-section imap pop && + perl -e \ + "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" +' + test_done From 87fe5df3653cf20b6bf9854bea42e4016c7d4688 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 6 May 2014 11:14:42 -0400 Subject: [PATCH 159/760] inline constant return from error() function Commit e208f9c introduced a macro to turn error() calls into: (error(), -1) to make the constant return value more visible to the calling code (and thus let the compiler make better decisions about the code). This works well for code like: return error(...); but the "-1" is superfluous in code that just calls error() without caring about the return value. In older versions of gcc, that was fine, but gcc 4.9 complains with -Wunused-value. We can work around this by encapsulating the constant return value in a static inline function, as gcc specifically avoids complaining about unused function returns unless the function has been specifically marked with the warn_unused_result attribute. We also use the same trick for config_error_nonbool and opterror, which learned the same error technique in a469a10. Reported-by: Felipe Contreras Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 +- git-compat-util.h | 6 +++++- parse-options.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index ebe9a405d811b2..001b63f5cd0f31 100644 --- a/cache.h +++ b/cache.h @@ -1184,7 +1184,7 @@ extern int git_env_bool(const char *, int); extern int git_config_system(void); extern int config_error_nonbool(const char *); #if defined(__GNUC__) && ! defined(__clang__) -#define config_error_nonbool(s) (config_error_nonbool(s), -1) +#define config_error_nonbool(s) (config_error_nonbool(s), const_error()) #endif extern const char *get_log_output_encoding(void); extern const char *get_commit_output_encoding(void); diff --git a/git-compat-util.h b/git-compat-util.h index d493a8c67ac1a9..90b988a5c191ed 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -343,7 +343,11 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))) * using the function as usual. */ #if defined(__GNUC__) && ! defined(__clang__) -#define error(...) (error(__VA_ARGS__), -1) +static inline int const_error(void) +{ + return -1; +} +#define error(...) (error(__VA_ARGS__), const_error()) #endif extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); diff --git a/parse-options.h b/parse-options.h index d670cb9669f213..1ef8da1f3e2b20 100644 --- a/parse-options.h +++ b/parse-options.h @@ -180,7 +180,7 @@ extern NORETURN void usage_msg_opt(const char *msg, extern int optbug(const struct option *opt, const char *reason); extern int opterror(const struct option *opt, const char *reason, int flags); #if defined(__GNUC__) && ! defined(__clang__) -#define opterror(o,r,f) (opterror((o),(r),(f)), -1) +#define opterror(o,r,f) (opterror((o),(r),(f)), const_error()) #endif /*----- incremental advanced APIs -----*/ From ff0a80af724e81dbad6a269847523e39c2e7e479 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 6 May 2014 11:17:50 -0400 Subject: [PATCH 160/760] let clang use the constant-return error() macro Commit e208f9c converted error() into a macro to make its constant return value more apparent to calling code. Commit 5ded807 prevents us using this macro with clang, since clang's -Wunused-value is smart enough to realize that the constant "-1" is useless in some contexts. However, since the last commit puts the constant behind an inline function call, this is enough to prevent the -Wunused-value warning on both modern gcc and clang. So we can now re-enable the macro when compiling with clang. Tested with clang 3.3, 3.4, and 3.5. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- cache.h | 2 +- git-compat-util.h | 2 +- parse-options.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index 001b63f5cd0f31..86be95e6d9c850 100644 --- a/cache.h +++ b/cache.h @@ -1183,7 +1183,7 @@ extern int check_repository_format_version(const char *var, const char *value, v extern int git_env_bool(const char *, int); extern int git_config_system(void); extern int config_error_nonbool(const char *); -#if defined(__GNUC__) && ! defined(__clang__) +#if defined(__GNUC__) #define config_error_nonbool(s) (config_error_nonbool(s), const_error()) #endif extern const char *get_log_output_encoding(void); diff --git a/git-compat-util.h b/git-compat-util.h index 90b988a5c191ed..38ff8030700466 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -342,7 +342,7 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))) * trying to help gcc, anyway, it's OK; other compilers will fall back to * using the function as usual. */ -#if defined(__GNUC__) && ! defined(__clang__) +#if defined(__GNUC__) static inline int const_error(void) { return -1; diff --git a/parse-options.h b/parse-options.h index 1ef8da1f3e2b20..0a2b2e19a5019b 100644 --- a/parse-options.h +++ b/parse-options.h @@ -179,7 +179,7 @@ extern NORETURN void usage_msg_opt(const char *msg, extern int optbug(const struct option *opt, const char *reason); extern int opterror(const struct option *opt, const char *reason, int flags); -#if defined(__GNUC__) && ! defined(__clang__) +#if defined(__GNUC__) #define opterror(o,r,f) (opterror((o),(r),(f)), const_error()) #endif From 4874f544f1574a55d787339a6455f524768c1b5d Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 4 May 2014 19:13:57 +0200 Subject: [PATCH 161/760] Bump core.deltaBaseCacheLimit to 96m The default of 16m causes serious thrashing for large delta chains combined with large files. Here are some benchmarks (pu variant of git blame): time git blame -C src/xdisp.c >/dev/null for a repository of Emacs repacked with git gc --aggressive (v1.9, resulting in a window size of 250) located on an SSD drive. The file in question has about 30000 lines, 1Mb of size, and a history with about 2500 commits. 16m (previous default): real 3m33.936s user 2m15.396s sys 1m17.352s 32m: real 3m1.319s user 2m8.660s sys 0m51.904s 64m: real 2m20.636s user 1m55.780s sys 0m23.964s 96m: real 2m5.668s user 1m50.784s sys 0m14.288s 128m: real 2m4.337s user 1m50.764s sys 0m12.832s 192m: real 2m3.567s user 1m49.508s sys 0m13.312s Signed-off-by: David Kastrup Acked-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/config.txt | 2 +- environment.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 1932e9b9a2be54..21a3c86fa005c3 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -489,7 +489,7 @@ core.deltaBaseCacheLimit:: to avoid unpacking and decompressing frequently used base objects multiple times. + -Default is 16 MiB on all platforms. This should be reasonable +Default is 96 MiB on all platforms. This should be reasonable for all users/operating systems, except on the largest projects. You probably do not need to adjust this value. + diff --git a/environment.c b/environment.c index 5c4815dbe132fc..37354c8d056efc 100644 --- a/environment.c +++ b/environment.c @@ -37,7 +37,7 @@ int core_compression_seen; int fsync_object_files; size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; -size_t delta_base_cache_limit = 16 * 1024 * 1024; +size_t delta_base_cache_limit = 96 * 1024 * 1024; unsigned long big_file_threshold = 512 * 1024 * 1024; const char *pager_program; int pager_use_color = 1; From 3bb55e8aa86f054c081c372b227f723e3aad14c7 Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Wed, 30 Apr 2014 17:58:06 +0900 Subject: [PATCH 162/760] strbuf: use _rtrim and _ltrim in strbuf_trim strbuf_trim() strips whitespace from the end, then the beginning of a strbuf. Those operations are duplicated in strbuf_rtrim() and strbuf_ltrim(). Replace strbuf_trim() implementation with calls to strbuf_rtrim(), then strbuf_ltrim(). Signed-off-by: Brian Gesiak Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- strbuf.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/strbuf.c b/strbuf.c index ee96dcfb816625..4d31567a1a6a67 100644 --- a/strbuf.c +++ b/strbuf.c @@ -78,15 +78,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra) void strbuf_trim(struct strbuf *sb) { - char *b = sb->buf; - while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1])) - sb->len--; - while (sb->len > 0 && isspace(*b)) { - b++; - sb->len--; - } - memmove(sb->buf, b, sb->len); - sb->buf[sb->len] = '\0'; + strbuf_rtrim(sb); + strbuf_ltrim(sb); } void strbuf_rtrim(struct strbuf *sb) { From 10f5b034b6aaff706c4776b3cc0ee993c33e8f43 Mon Sep 17 00:00:00 2001 From: Brian Gesiak Date: Wed, 30 Apr 2014 17:58:07 +0900 Subject: [PATCH 163/760] api-strbuf.txt: add docs for _trim and _ltrim API documentation for strbuf does not document strbuf_trim() or strbuf_ltrim(). Add documentation for these two functions. Signed-off-by: Brian Gesiak Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/technical/api-strbuf.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt index 3350d97dda2408..4396be9dda07df 100644 --- a/Documentation/technical/api-strbuf.txt +++ b/Documentation/technical/api-strbuf.txt @@ -121,10 +121,19 @@ Functions * Related to the contents of the buffer +`strbuf_trim`:: + + Strip whitespace from the beginning and end of a string. + Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`. + `strbuf_rtrim`:: Strip whitespace from the end of a string. +`strbuf_ltrim`:: + + Strip whitespace from the beginning of a string. + `strbuf_cmp`:: Compare two buffers. Returns an integer less than, equal to, or greater From 8e2a5ccad11bc21eb72499133bc884024e299983 Mon Sep 17 00:00:00 2001 From: James Denholm Date: Tue, 6 May 2014 22:41:46 +1000 Subject: [PATCH 164/760] contrib/subtree/Makefile: use GIT-VERSION-FILE GVF is already being used in most/all other makefiles in the project, and has been for _quite_ a while. Hence, drop file-unique gitver and replace with GIT_VERSION. Reviewed-by: Jeff King Signed-off-by: James Denholm Signed-off-by: Junio C Hamano --- contrib/subtree/Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index 87797edeb30309..f63334bd6525b3 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -6,7 +6,10 @@ mandir ?= $(prefix)/share/man libexecdir ?= $(prefix)/libexec/git-core man1dir ?= $(mandir)/man1 -gitver ?= $(word 3,$(shell git --version)) +../../GIT-VERSION-FILE: FORCE + $(MAKE) -C ../../ GIT-VERSION-FILE + +-include ../../GIT-VERSION-FILE # this should be set to a 'standard' bsd-type install program INSTALL ?= install @@ -44,11 +47,11 @@ $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML) $(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT) asciidoc -b docbook -d manpage -f $(ASCIIDOC_CONF) \ - -agit_version=$(gitver) $^ + -agit_version=$(GIT_VERSION) $^ $(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT) asciidoc -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \ - -agit_version=$(gitver) $^ + -agit_version=$(GIT_VERSION) $^ test: $(MAKE) -C t/ test @@ -56,3 +59,5 @@ test: clean: rm -f *~ *.xml *.html *.1 rm -rf subproj mainline + +.PHONY: FORCE From 2c45009b734beed92414fd7249faa0b009432a1b Mon Sep 17 00:00:00 2001 From: James Denholm Date: Tue, 6 May 2014 22:41:47 +1000 Subject: [PATCH 165/760] contrib/subtree/Makefile: s/libexecdir/gitexecdir/ $(libexecdir) isn't used anywhere else in the project, while $(gitexecdir) is the standard in the other appropriate makefiles. Hence, replace the former with the latter. Reviewed-by: Jeff King Signed-off-by: James Denholm Signed-off-by: Junio C Hamano --- contrib/subtree/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index f63334bd6525b3..579bb51bf04fc3 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -3,7 +3,7 @@ prefix ?= /usr/local mandir ?= $(prefix)/share/man -libexecdir ?= $(prefix)/libexec/git-core +gitexecdir ?= $(prefix)/libexec/git-core man1dir ?= $(mandir)/man1 ../../GIT-VERSION-FILE: FORCE @@ -33,8 +33,8 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH) doc: $(GIT_SUBTREE_DOC) $(GIT_SUBTREE_HTML) install: $(GIT_SUBTREE) - $(INSTALL) -d -m 755 $(DESTDIR)$(libexecdir) - $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir) + $(INSTALL) -d -m 755 $(DESTDIR)$(gitexecdir) + $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(gitexecdir) install-doc: install-man From c7abbb986387470512080b162574c99cd7991aa7 Mon Sep 17 00:00:00 2001 From: James Denholm Date: Tue, 6 May 2014 22:41:48 +1000 Subject: [PATCH 166/760] contrib/subtree/Makefile: clean up rules to generate documentation git:Documentation/Makefile establishes asciidoc/xmlto calls as being handled through their appropriate variables, Hence, change to bring into congruency with. Similarly, MANPAGE_XSL exists in git:Documentation/Makefile, while MANPAGE_NORMAL_XSL does not outside contrib/subtree. Hence, replace MANPAGE_NORMAL_XSL with MANPAGE_XSL. Reviewed-by: Jeff King Signed-off-by: James Denholm Signed-off-by: Junio C Hamano --- contrib/subtree/Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index 579bb51bf04fc3..f3834b5bd6ebb9 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -14,8 +14,11 @@ man1dir ?= $(mandir)/man1 # this should be set to a 'standard' bsd-type install program INSTALL ?= install -ASCIIDOC_CONF = ../../Documentation/asciidoc.conf -MANPAGE_NORMAL_XSL = ../../Documentation/manpage-normal.xsl +ASCIIDOC = asciidoc +XMLTO = xmlto + +ASCIIDOC_CONF = ../../Documentation/asciidoc.conf +MANPAGE_XSL = ../../Documentation/manpage-normal.xsl GIT_SUBTREE_SH := git-subtree.sh GIT_SUBTREE := git-subtree @@ -43,14 +46,14 @@ install-man: $(GIT_SUBTREE_DOC) $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir) $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML) - xmlto -m $(MANPAGE_NORMAL_XSL) man $^ + $(XMLTO) -m $(MANPAGE_XSL) man $^ $(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT) - asciidoc -b docbook -d manpage -f $(ASCIIDOC_CONF) \ + $(ASCIIDOC) -b docbook -d manpage -f $(ASCIIDOC_CONF) \ -agit_version=$(GIT_VERSION) $^ $(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT) - asciidoc -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \ + $(ASCIIDOC) -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \ -agit_version=$(GIT_VERSION) $^ test: From 602efc4f90295369763cc58b47c3c6532a070fe9 Mon Sep 17 00:00:00 2001 From: James Denholm Date: Tue, 6 May 2014 22:41:49 +1000 Subject: [PATCH 167/760] contrib/subtree/Makefile: clean up rule for "clean" git:Documentation/Makefile and others establish "RM ?= rm -f" as a convention for rm calls in clean rules, hence follow this convention instead of simply forcing clean to use rm. subproj and mainline no longer need to be removed in clean, as they are no longer created in git:contrib/subtree by "make test". Hence, remove the rm call for those folders. Other makefiles don't remove "*~" files, remove the rm call to prevent unexpected behaviour in the future. Similarly, clean doesn't remove the installable file, so rectify this. Reviewed-by: Jeff King Signed-off-by: James Denholm Signed-off-by: Junio C Hamano --- contrib/subtree/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index f3834b5bd6ebb9..d888d4516114c7 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -12,7 +12,8 @@ man1dir ?= $(mandir)/man1 -include ../../GIT-VERSION-FILE # this should be set to a 'standard' bsd-type install program -INSTALL ?= install +INSTALL ?= install +RM ?= rm -f ASCIIDOC = asciidoc XMLTO = xmlto @@ -60,7 +61,7 @@ test: $(MAKE) -C t/ test clean: - rm -f *~ *.xml *.html *.1 - rm -rf subproj mainline + $(RM) $(GIT_SUBTREE) + $(RM) *.xml *.html *.1 .PHONY: FORCE From 26ecfe3e2041fe651c9682ebb73911777290ac62 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 6 May 2014 23:00:37 -0400 Subject: [PATCH 168/760] grep: use run-command's "dir" option for --open-files-in-pager Git generally changes directory to the repository root on startup. When running "grep --open-files-in-pager" from a subdirectory, we chdir back to the original directory before running the pager, so that we can feed the relative pathnames to the pager. We currently do this chdir manually, but we can ask run_command to do it for us. This is fewer lines of code, and as a bonus, the chdir is limited to the child process, which avoids any unexpected surprises for code running after the pager (there isn't any currently, but this is future-proofing). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/grep.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 69ac2d8797ec32..43af5b744fcbee 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix) argv[i] = path_list->items[i].string; argv[path_list->nr] = NULL; - if (prefix && chdir(prefix)) - die(_("Failed to chdir: %s"), prefix); - status = run_command_v_opt(argv, RUN_USING_SHELL); + status = run_command_v_opt_cd_env(argv, RUN_USING_SHELL, prefix, NULL); if (status) exit(status); free(argv); From 7d7d680221e6aac4210cf3c0be9ab237bc45b781 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 4 May 2014 01:12:55 -0500 Subject: [PATCH 169/760] silence a bunch of format-zero-length warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can be observed in many versions of gcc and still exists with 4.9.0: wt-status.c: In function ‘wt_status_print_unmerged_header’: wt-status.c:191:2: warning: zero-length gnu_printf format string [-Wformat-zero-length] status_printf_ln(s, c, ""); ^ The user have long been told to pass -Wno-format-zero-length, but a patch that avoids warning altogether is not too noisy, so let's do so. Signed-off-by: Felipe Contreras Acked-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/commit.c | 2 +- wt-status.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index fedb45af8c65d2..377d8418d2496b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -805,7 +805,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, committer_ident.buf); if (ident_shown) - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); saved_color_setting = s->use_color; s->use_color = 0; diff --git a/wt-status.c b/wt-status.c index 85390b813f12e2..598f9e34e7cb9a 100644 --- a/wt-status.c +++ b/wt-status.c @@ -187,7 +187,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s) } else { status_printf_ln(s, c, _(" (use \"git add/rm ...\" as appropriate to mark resolution)")); } - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_cached_header(struct wt_status *s) @@ -203,7 +203,7 @@ static void wt_status_print_cached_header(struct wt_status *s) status_printf_ln(s, c, _(" (use \"git reset %s ...\" to unstage)"), s->reference); else status_printf_ln(s, c, _(" (use \"git rm --cached ...\" to unstage)")); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_dirty_header(struct wt_status *s, @@ -222,7 +222,7 @@ static void wt_status_print_dirty_header(struct wt_status *s, status_printf_ln(s, c, _(" (use \"git checkout -- ...\" to discard changes in working directory)")); if (has_dirty_submodules) status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)")); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_other_header(struct wt_status *s, @@ -234,12 +234,12 @@ static void wt_status_print_other_header(struct wt_status *s, if (!s->hints) return; status_printf_ln(s, c, _(" (use \"git %s ...\" to include in what will be committed)"), how); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_trailer(struct wt_status *s) { - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } #define quote_path quote_path_relative @@ -767,7 +767,7 @@ static void wt_status_print_other(struct wt_status *s, string_list_clear(&output, 0); strbuf_release(&buf); conclude: - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); } void wt_status_truncate_message_at_cut_line(struct strbuf *buf) @@ -849,7 +849,7 @@ static void wt_status_print_tracking(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c", comment_line_char); else - fprintf_ln(s->fp, ""); + fputs("", s->fp); } static int has_unmerged(struct wt_status *s) @@ -1265,7 +1265,7 @@ void wt_status_print(struct wt_status *s) on_what = _("Not currently on any branch."); } } - status_printf(s, color(WT_STATUS_HEADER, s), ""); + status_printf(s, color(WT_STATUS_HEADER, s), "%s", ""); status_printf_more(s, branch_status_color, "%s", on_what); status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) @@ -1278,9 +1278,9 @@ void wt_status_print(struct wt_status *s) free(state.detached_from); if (s->is_initial) { - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit")); - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } wt_status_print_updated(s); @@ -1297,7 +1297,7 @@ void wt_status_print(struct wt_status *s) if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f"); if (advice_status_u_option && 2000 < s->untracked_in_ms) { - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); status_printf_ln(s, GIT_COLOR_NORMAL, _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n" "may speed it up, but you have to be careful not to forget to add\n" From b3275838d969b7ecb91aae584226fccbeb046aca Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 30 Apr 2014 09:35:25 +0200 Subject: [PATCH 170/760] pager: remove 'S' from $LESS by default By default, Git used to set $LESS to -FRSX if $LESS was not set by the user. The FRX flags actually make sense for Git (F and X because sometimes the output Git pipes to less is short, and R because Git pipes colored output). The S flag (chop long lines), on the other hand, is not related to Git and is a matter of user preference. Git should not decide for the user to change LESS's default. More specifically, the S flag harms users who review untrusted code within a pager, since a patch looking like: -old code; +new good code; [... lots of tabs ...] malicious code; would appear identical to: -old code; +new good code; Users who prefer the old behavior can still set the $LESS environment variable to -FRSX explicitly, or set core.pager to 'less -S'. The documentation in config.txt is made a bit longer to keep both an example setting the 'S' flag (needed to recover the old behavior) and an example showing how to unset a flag set by Git. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- Documentation/config.txt | 15 ++++++++++----- git-sh-setup.sh | 2 +- pager.c | 2 +- perl/Git/SVN/Log.pm | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index d8b6cc9654e24c..f57b0e2fcf13ce 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -558,14 +558,19 @@ core.pager:: configuration, then `$PAGER`, and then the default chosen at compile time (usually 'less'). + -When the `LESS` environment variable is unset, Git sets it to `FRSX` +When the `LESS` environment variable is unset, Git sets it to `FRX` (if `LESS` environment variable is set, Git does not change it at all). If you want to selectively override Git's default setting -for `LESS`, you can set `core.pager` to e.g. `less -+S`. This will +for `LESS`, you can set `core.pager` to e.g. `less -S`. This will be passed to the shell by Git, which will translate the final -command to `LESS=FRSX less -+S`. The environment tells the command -to set the `S` option to chop long lines but the command line -resets it to the default to fold long lines. +command to `LESS=FRX less -S`. The environment does not set the +`S` option but the command line does, instructing less to truncate +long lines. Similarly, setting `core.pager` to `less -+F` will +deactivate the `F` option specified by the environment from the +command-line, deactivating the "quit if one screen" behavior of +`less`. One can specifically activate some flags for particular +commands: for example, setting `pager.blame` to `less -S` enables +line truncation only for `git blame`. + Likewise, when the `LV` environment variable is unset, Git sets it to `-c`. You can override this setting by exporting `LV` with diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 5f28b32dc7ff75..9447980330ce78 100644 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -160,7 +160,7 @@ git_pager() { else GIT_PAGER=cat fi - : ${LESS=-FRSX} + : ${LESS=-FRX} : ${LV=-c} export LESS LV diff --git a/pager.c b/pager.c index 0cc75a8eee32a0..f75e8aece0d427 100644 --- a/pager.c +++ b/pager.c @@ -85,7 +85,7 @@ void setup_pager(void) int i = 0; if (!getenv("LESS")) - env[i++] = "LESS=FRSX"; + env[i++] = "LESS=FRX"; if (!getenv("LV")) env[i++] = "LV=-c"; env[i] = NULL; diff --git a/perl/Git/SVN/Log.pm b/perl/Git/SVN/Log.pm index 34f2869ab5995e..664105357c0031 100644 --- a/perl/Git/SVN/Log.pm +++ b/perl/Git/SVN/Log.pm @@ -116,7 +116,7 @@ sub run_pager { return; } open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!"; - $ENV{LESS} ||= 'FRSX'; + $ENV{LESS} ||= 'FRX'; $ENV{LV} ||= '-c'; exec $pager or fatal "Can't run pager: $! ($pager)"; } From ae352c7f37ef2098e03ee86bc7fd75b210b17683 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 1 May 2014 20:21:09 -0400 Subject: [PATCH 171/760] merge-recursive.c: fix case-changing merge bug On a case-insensitive filesystem, when merging, a file would be wrongly deleted from the working tree if an incoming commit had renamed it changing only its case. When merging a rename, the file with the old name would be deleted -- but since the filesystem considers the old name to be the same as the new name, the new file would in fact be deleted. We avoid this by not deleting files that have a case-clone in the index at stage 0. Signed-off-by: David Turner Signed-off-by: Junio C Hamano --- merge-recursive.c | 6 +++++ t/t6039-merge-ignorecase.sh | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 t/t6039-merge-ignorecase.sh diff --git a/merge-recursive.c b/merge-recursive.c index 41770929420da4..cab16fafb5c2b7 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -589,6 +589,12 @@ static int remove_file(struct merge_options *o, int clean, return -1; } if (update_working_directory) { + if (ignore_case) { + struct cache_entry *ce; + ce = cache_file_exists(path, strlen(path), ignore_case); + if (ce && ce_stage(ce) == 0) + return 0; + } if (remove_path(path)) return -1; } diff --git a/t/t6039-merge-ignorecase.sh b/t/t6039-merge-ignorecase.sh new file mode 100755 index 00000000000000..dfc9f17a2d6f80 --- /dev/null +++ b/t/t6039-merge-ignorecase.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='git-merge with case-changing rename on case-insensitive file system' + +. ./test-lib.sh + +if ! test_have_prereq CASE_INSENSITIVE_FS +then + skip_all='skipping case insensitive tests - case sensitive file system' + test_done +fi + +test_expect_success 'merge with case-changing rename' ' + test $(git config core.ignorecase) = true && + >TestCase && + git add TestCase && + git commit -m "add TestCase" && + git tag baseline + git checkout -b with-camel && + >foo && + git add foo && + git commit -m "intervening commit" && + git checkout master && + git rm TestCase && + >testcase && + git add testcase && + git commit -m "rename to testcase" && + git checkout with-camel && + git merge master -m "merge" && + test_path_is_file testcase +' + +test_expect_success 'merge with case-changing rename on both sides' ' + git checkout master && + git reset --hard baseline && + git branch -D with-camel && + git checkout -b with-camel && + git mv --force TestCase testcase && + git commit -m "recase on branch" && + >foo && + git add foo && + git commit -m "intervening commit" && + git checkout master && + git rm TestCase && + >testcase && + git add testcase && + git commit -m "rename to testcase" && + git checkout with-camel && + git merge master -m "merge" && + test_path_is_file testcase +' + +test_done From d78f340ed6250dfe8de6e039acc56a013bcf3637 Mon Sep 17 00:00:00 2001 From: Thorsten Glaser Date: Fri, 30 Aug 2013 00:03:10 +0200 Subject: [PATCH 172/760] builtin/tag.c: show tag name to hint in the message editor Display the tag name about to be added to the user during interactive editing. Signed-off-by: Thorsten Glaser Signed-off-by: Richard Hartmann Signed-off-by: Junio C Hamano --- builtin/tag.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index 74d3780b77548f..8f1a0c170c092b 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -246,11 +246,11 @@ static int do_sign(struct strbuf *buffer) } static const char tag_template[] = - N_("\nWrite a tag message\n" + N_("\nWrite a message for tag:\n %s\n" "Lines starting with '%c' will be ignored.\n"); static const char tag_template_nocleanup[] = - N_("\nWrite a tag message\n" + N_("\nWrite a message for tag:\n %s\n" "Lines starting with '%c' will be kept; you may remove them" " yourself if you want to.\n"); @@ -346,9 +346,9 @@ static void create_tag(const unsigned char *object, const char *tag, struct strbuf buf = STRBUF_INIT; strbuf_addch(&buf, '\n'); if (opt->cleanup_mode == CLEANUP_ALL) - strbuf_commented_addf(&buf, _(tag_template), comment_line_char); + strbuf_commented_addf(&buf, _(tag_template), tag, comment_line_char); else - strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char); + strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char); write_or_die(fd, buf.buf, buf.len); strbuf_release(&buf); } From 0170a3c6ee7eba128d44dd50d0bf7a86d295c19e Mon Sep 17 00:00:00 2001 From: Stepan Kasal Date: Thu, 8 May 2014 22:36:57 +0200 Subject: [PATCH 173/760] Revert "submodules: fix ambiguous absolute paths under Windows" This reverts commit 4dce7d9b408b2935b85721b54a2010eda7ec1be9, which was originally done to help Windows but was almost immediately reverted in msysGit, and the codebase kept this unnecessary divergence for almost two years. Signed-off-by: Stepan Kasal Signed-off-by: Junio C Hamano --- git-submodule.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 66f5f752c5fb67..821e6d47cf3b97 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -285,9 +285,6 @@ module_clone() # resolve any symlinks that might be present in $PWD a=$(cd_to_toplevel && cd "$gitdir" && pwd)/ b=$(cd_to_toplevel && cd "$sm_path" && pwd)/ - # normalize Windows-style absolute paths to POSIX-style absolute paths - case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac - case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac # Remove all common leading directories after a sanity check if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")" From 4da588357a4a8b73f6a8d9c24435dabee74d0a7e Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 6 May 2014 15:45:52 -0700 Subject: [PATCH 174/760] refs.c: add new functions reflog_exists and delete_reflog Add two new functions, reflog_exists and delete_reflog, to hide the internal reflog implementation (that they are files under .git/logs/...) from callers. Update checkout.c to use these functions in update_refs_for_switch instead of building pathnames and calling out to file access functions. Update reflog.c to use these to check if the reflog exists. Now there are still many places in reflog.c where we are still leaking the reflog storage implementation but this at least reduces the number of such dependencies by one. Finally change two places in refs.c itself to use the new function to check if a ref exists or not isntead of build-path-and-stat(). Now, this is strictly not all that important since these are in parts of refs that are implementing the actual file storage backend but on the other hand it will not hurt either. Signed-off-by: Ronnie Sahlberg Acked-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/checkout.c | 7 +++---- builtin/reflog.c | 2 +- refs.c | 21 +++++++++++++++------ refs.h | 6 ++++++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 07cf55530918e8..d3fc3a8532078f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -651,12 +651,11 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } } if (old->path && old->name) { - char log_file[PATH_MAX], ref_file[PATH_MAX]; + char ref_file[PATH_MAX]; - git_snpath(log_file, sizeof(log_file), "logs/%s", old->path); git_snpath(ref_file, sizeof(ref_file), "%s", old->path); - if (!file_exists(ref_file) && file_exists(log_file)) - remove_path(log_file); + if (!file_exists(ref_file) && reflog_exists(old->path)) + delete_reflog(old->path); } } remove_branch_state(); diff --git a/builtin/reflog.c b/builtin/reflog.c index c12a9784e6b45d..e8a8fb13b9ffc8 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -369,7 +369,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, if (!lock) return error("cannot lock ref '%s'", ref); log_file = git_pathdup("logs/%s", ref); - if (!file_exists(log_file)) + if (!reflog_exists(ref)) goto finish; if (!cmd->dry_run) { newlog_path = git_pathdup("logs/%s.lock", ref); diff --git a/refs.c b/refs.c index 28d5eca8eaff7b..2c6509d5afdcc8 100644 --- a/refs.c +++ b/refs.c @@ -1999,7 +1999,6 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log) *log = NULL; for (p = ref_rev_parse_rules; *p; p++) { - struct stat st; unsigned char hash[20]; char path[PATH_MAX]; const char *ref, *it; @@ -2008,12 +2007,9 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log) ref = resolve_ref_unsafe(path, hash, 1, NULL); if (!ref) continue; - if (!stat(git_path("logs/%s", path), &st) && - S_ISREG(st.st_mode)) + if (reflog_exists(path)) it = path; - else if (strcmp(ref, path) && - !stat(git_path("logs/%s", ref), &st) && - S_ISREG(st.st_mode)) + else if (strcmp(ref, path) && reflog_exists(ref)) it = ref; else continue; @@ -3046,6 +3042,19 @@ int read_ref_at(const char *refname, unsigned long at_time, int cnt, return 1; } +int reflog_exists(const char *refname) +{ + struct stat st; + + return !lstat(git_path("logs/%s", refname), &st) && + S_ISREG(st.st_mode); +} + +int delete_reflog(const char *refname) +{ + return remove_path(git_path("logs/%s", refname)); +} + static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data) { unsigned char osha1[20], nsha1[20]; diff --git a/refs.h b/refs.h index 87a1a79ad659f3..c9dab1b2f76f3f 100644 --- a/refs.h +++ b/refs.h @@ -173,6 +173,12 @@ extern int read_ref_at(const char *refname, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt); +/** Check if a particular reflog exists */ +extern int reflog_exists(const char *refname); + +/** Delete a reflog */ +extern int delete_reflog(const char *refname); + /* iterate over reflog entries */ typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *); int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data); From 482b8f3208e797f00db58edd7ff0d67275e898f5 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 6 May 2014 15:45:53 -0700 Subject: [PATCH 175/760] checkout.c: use ref_exists instead of file_exist Change checkout.c to check if a ref exists instead of checking if a loose ref file exists when deciding if to delete an orphaned log file. Otherwise, if a ref only exists as a packed ref without a corresponding loose ref for the currently checked out branch, we risk that the reflog will be deleted when we switch to a different branch. Update the reflog tests to check for this bug. The following reproduces the bug: $ git init-db $ git config core.logallrefupdates true $ git commit -m Initial --allow-empty [master (root-commit) bb11abe] Initial $ git reflog master [8561dcb master@{0}: commit (initial): Initial] $ find .git/{refs,logs} -type f | grep master [.git/refs/heads/master] [.git/logs/refs/heads/master] $ git branch foo $ git pack-refs --all $ find .git/{refs,logs} -type f | grep master [.git/logs/refs/heads/master] $ git checkout foo $ find .git/{refs,logs} -type f | grep master ... reflog file is missing ... $ git reflog master ... nothing ... Signed-off-by: Ronnie Sahlberg Acked-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/checkout.c | 5 +---- t/t1410-reflog.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index d3fc3a8532078f..c4db4ca9310b13 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -651,10 +651,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } } if (old->path && old->name) { - char ref_file[PATH_MAX]; - - git_snpath(ref_file, sizeof(ref_file), "%s", old->path); - if (!file_exists(ref_file) && reflog_exists(old->path)) + if (!ref_exists(old->path) && reflog_exists(old->path)) delete_reflog(old->path); } } diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 236b13a3ab27f5..8cab06f90a52b8 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -245,4 +245,12 @@ test_expect_success 'gc.reflogexpire=false' ' ' +test_expect_success 'checkout should not delete log for packed ref' ' + test $(git reflog master | wc -l) = 4 && + git branch foo && + git pack-refs --all && + git checkout foo && + test $(git reflog master | wc -l) = 4 +' + test_done From baa37bff9a845471754d3f47957d58a6ccc30058 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 8 May 2014 10:23:34 -0700 Subject: [PATCH 176/760] mv: allow renaming to fix case on case insensitive filesystems "git mv hello.txt Hello.txt" on a case insensitive filesystem always triggers "destination already exists" error, because these two names refer to the same path from the filesystem's point of view, and requires the user to give "--force" when correcting the case of the path recorded in the index and in the next commit. Detect this case and allow it without requiring "--force". Signed-off-by: David Turner Signed-off-by: Junio C Hamano --- builtin/mv.c | 3 ++- t/t6039-merge-ignorecase.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 45e57f307b7994..f4d89d06408be1 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -202,7 +202,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } } else if (cache_name_pos(src, length) < 0) bad = _("not under version control"); - else if (lstat(dst, &st) == 0) { + else if (lstat(dst, &st) == 0 && + (!ignore_case || strcasecmp(src, dst))) { bad = _("destination exists"); if (force) { /* diff --git a/t/t6039-merge-ignorecase.sh b/t/t6039-merge-ignorecase.sh index dfc9f17a2d6f80..a97765314739be 100755 --- a/t/t6039-merge-ignorecase.sh +++ b/t/t6039-merge-ignorecase.sh @@ -35,7 +35,7 @@ test_expect_success 'merge with case-changing rename on both sides' ' git reset --hard baseline && git branch -D with-camel && git checkout -b with-camel && - git mv --force TestCase testcase && + git mv TestCase testcase && git commit -m "recase on branch" && >foo && git add foo && From 4d4813a52f3722854a54bab046f4abfec13ef6ae Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 26 Apr 2014 23:10:40 +0000 Subject: [PATCH 177/760] blame: correctly handle files regardless of autocrlf If a file contained CRLF line endings in a repository with core.autocrlf=input, then blame always marked lines as "Not Committed Yet", even if they were unmodified. Don't attempt to convert the line endings when creating the fake commit so that blame works correctly regardless of the autocrlf setting. Reported-by: Ephrim Khong Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/blame.c | 1 - t/t8003-blame-corner-cases.sh | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/blame.c b/builtin/blame.c index e44a6bb30a5a52..7468df4a41651a 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2095,7 +2095,6 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, if (strbuf_read(&buf, 0, 0) < 0) die_errno("failed to read from stdin"); } - convert_to_git(path, buf.buf, buf.len, &buf, 0); origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1); diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh index e7cac1db551131..2a3469bcbea39e 100755 --- a/t/t8003-blame-corner-cases.sh +++ b/t/t8003-blame-corner-cases.sh @@ -191,4 +191,13 @@ test_expect_success 'indent of line numbers, ten lines' ' test $(grep -c " " actual) = 9 ' +test_expect_success 'blaming files with CRLF newlines' ' + git config core.autocrlf false && + printf "testcase\r\n" >crlffile && + git add crlffile && + git commit -m testcase && + git -c core.autocrlf=input blame crlffile >actual && + grep "A U Thor" actual +' + test_done From 7d445f518ef3b38a26166d1ee5a4074f15bc7cd1 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 8 May 2014 19:23:50 -0700 Subject: [PATCH 178/760] contrib: remove vim support instructions The git support scripts started shipping in upstream vim in version 7.2 (2008-08-09). Clean up contrib/ a little by removing the instructions for people on older versions of vim. RHEL 6 already has vim 7.2.something, so anyone on a reasonably modern operating system should not be affected. Users on RHEL 5 presumably know that means sometimes missing out on niceties like syntax highlighting, so this should be safe. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- contrib/vim/README | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 contrib/vim/README diff --git a/contrib/vim/README b/contrib/vim/README deleted file mode 100644 index 8f16d069721c5b..00000000000000 --- a/contrib/vim/README +++ /dev/null @@ -1,22 +0,0 @@ -Syntax highlighting for git commit messages, config files, etc. is -included with the vim distribution as of vim 7.2, and should work -automatically. - -If you have an older version of vim, you can get the latest syntax -files from the vim project: - - http://ftp.vim.org/pub/vim/runtime/syntax/git.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitcommit.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitconfig.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitrebase.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitsendemail.vim - -These files are also available via FTP at the same location. - -To install: - - 1. Copy these files to vim's syntax directory $HOME/.vim/syntax - 2. To auto-detect the editing of various git-related filetypes: - - $ curl http://ftp.vim.org/pub/vim/runtime/filetype.vim | - sed -ne '/^" Git$/, /^$/ p' >>$HOME/.vim/filetype.vim From 502b0a1ad145a7d77733008946c833ba7d3d100d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 9 May 2014 13:12:46 -0700 Subject: [PATCH 179/760] contrib: remove git-diffall The functionality of the "git diffall" script in contrib/ was incorporated into "git difftool" when the --dir-diff option was added in v1.7.11 (ca. June, 2012). Once difftool learned those features, the diffall script became obsolete. The only difference in behavior is that when comparing to the working tree, difftool copies any files modified by the user back to the working tree when the diff tool exits. "git diffall" required the --copy-back option to do the same. All other diffall options have the same meaning in difftool. Make life easier for people choosing a tool to use by removing the old diffall script. A pointer in the release notes should be enough to help current users migrate. Helped-by: Tim Henigan Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- contrib/diffall/README | 31 ----- contrib/diffall/git-diffall | 257 ------------------------------------ 2 files changed, 288 deletions(-) delete mode 100644 contrib/diffall/README delete mode 100755 contrib/diffall/git-diffall diff --git a/contrib/diffall/README b/contrib/diffall/README deleted file mode 100644 index 507f17dcd6fa64..00000000000000 --- a/contrib/diffall/README +++ /dev/null @@ -1,31 +0,0 @@ -The git-diffall script provides a directory based diff mechanism -for git. - -To determine what diff viewer is used, the script requires either -the 'diff.tool' or 'merge.tool' configuration option to be set. - -This script is compatible with most common forms used to specify a -range of revisions to diff: - - 1. git diffall: shows diff between working tree and staged changes - 2. git diffall --cached []: shows diff between staged - changes and HEAD (or other named commit) - 3. git diffall : shows diff between working tree and named - commit - 4. git diffall : show diff between two named commits - 5. git diffall ..: same as above - 6. git diffall ...: show the changes on the branch - containing and up to the second, starting at a common ancestor - of both - -Note: all forms take an optional path limiter [-- *] - -The '--extcmd=' option allows the user to specify a custom -command for viewing diffs. When given, configured defaults are -ignored and the script runs $command $LOCAL $REMOTE. Additionally, -$BASE is set in the environment. - -This script is based on an example provided by Thomas Rast on the -Git list [1]: - -[1] http://thread.gmane.org/gmane.comp.version-control.git/124807 diff --git a/contrib/diffall/git-diffall b/contrib/diffall/git-diffall deleted file mode 100755 index 84f2b654d755cf..00000000000000 --- a/contrib/diffall/git-diffall +++ /dev/null @@ -1,257 +0,0 @@ -#!/bin/sh -# Copyright 2010 - 2012, Tim Henigan -# -# Perform a directory diff between commits in the repository using -# the external diff or merge tool specified in the user's config. - -USAGE='[--cached] [--copy-back] [-x|--extcmd=] {0,2} [-- *] - - --cached Compare to the index rather than the working tree. - - --copy-back Copy files back to the working tree when the diff - tool exits (in case they were modified by the - user). This option is only valid if the diff - compared with the working tree. - - -x= - --extcmd= Specify a custom command for viewing diffs. - git-diffall ignores the configured defaults and - runs $command $LOCAL $REMOTE when this option is - specified. Additionally, $BASE is set in the - environment. -' - -SUBDIRECTORY_OK=1 -. "$(git --exec-path)/git-sh-setup" - -TOOL_MODE=diff -. "$(git --exec-path)/git-mergetool--lib" - -merge_tool="$(get_merge_tool)" -if test -z "$merge_tool" -then - echo "Error: Either the 'diff.tool' or 'merge.tool' option must be set." - usage -fi - -start_dir=$(pwd) - -# All the file paths returned by the diff command are relative to the root -# of the working copy. So if the script is called from a subdirectory, it -# must switch to the root of working copy before trying to use those paths. -cdup=$(git rev-parse --show-cdup) && -cd "$cdup" || { - echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree" - exit 1 -} - -# set up temp dir -tmp=$(perl -e 'use File::Temp qw(tempdir); - $t=tempdir("/tmp/git-diffall.XXXXX") or exit(1); - print $t') || exit 1 -trap 'rm -rf "$tmp"' EXIT - -left= -right= -paths= -dashdash_seen= -compare_staged= -merge_base= -left_dir= -right_dir= -diff_tool= -copy_back= - -while test $# != 0 -do - case "$1" in - -h|--h|--he|--hel|--help) - usage - ;; - --cached) - compare_staged=1 - ;; - --copy-back) - copy_back=1 - ;; - -x|--e|--ex|--ext|--extc|--extcm|--extcmd) - if test $# = 1 - then - echo You must specify the tool for use with --extcmd - usage - else - diff_tool=$2 - shift - fi - ;; - --) - dashdash_seen=1 - ;; - -*) - echo Invalid option: "$1" - usage - ;; - *) - # could be commit, commit range or path limiter - case "$1" in - *...*) - left=${1%...*} - right=${1#*...} - merge_base=1 - ;; - *..*) - left=${1%..*} - right=${1#*..} - ;; - *) - if test -n "$dashdash_seen" - then - paths="$paths$1 " - elif test -z "$left" - then - left=$1 - elif test -z "$right" - then - right=$1 - else - paths="$paths$1 " - fi - ;; - esac - ;; - esac - shift -done - -# Determine the set of files which changed -if test -n "$left" && test -n "$right" -then - left_dir="cmt-$(git rev-parse --short $left)" - right_dir="cmt-$(git rev-parse --short $right)" - - if test -n "$compare_staged" - then - usage - elif test -n "$merge_base" - then - git diff --name-only "$left"..."$right" -- $paths >"$tmp/filelist" - else - git diff --name-only "$left" "$right" -- $paths >"$tmp/filelist" - fi -elif test -n "$left" -then - left_dir="cmt-$(git rev-parse --short $left)" - - if test -n "$compare_staged" - then - right_dir="staged" - git diff --name-only --cached "$left" -- $paths >"$tmp/filelist" - else - right_dir="working_tree" - git diff --name-only "$left" -- $paths >"$tmp/filelist" - fi -else - left_dir="HEAD" - - if test -n "$compare_staged" - then - right_dir="staged" - git diff --name-only --cached -- $paths >"$tmp/filelist" - else - right_dir="working_tree" - git diff --name-only -- $paths >"$tmp/filelist" - fi -fi - -# Exit immediately if there are no diffs -if test ! -s "$tmp/filelist" -then - exit 0 -fi - -if test -n "$copy_back" && test "$right_dir" != "working_tree" -then - echo "--copy-back is only valid when diff includes the working tree." - exit 1 -fi - -# Create the named tmp directories that will hold the files to be compared -mkdir -p "$tmp/$left_dir" "$tmp/$right_dir" - -# Populate the tmp/right_dir directory with the files to be compared -while read name -do - if test -n "$right" - then - ls_list=$(git ls-tree $right "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$right_dir/$(dirname "$name")" - git show "$right":"$name" >"$tmp/$right_dir/$name" || true - fi - elif test -n "$compare_staged" - then - ls_list=$(git ls-files -- "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$right_dir/$(dirname "$name")" - git show :"$name" >"$tmp/$right_dir/$name" - fi - else - if test -e "$name" - then - mkdir -p "$tmp/$right_dir/$(dirname "$name")" - cp "$name" "$tmp/$right_dir/$name" - fi - fi -done < "$tmp/filelist" - -# Populate the tmp/left_dir directory with the files to be compared -while read name -do - if test -n "$left" - then - ls_list=$(git ls-tree $left "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$left_dir/$(dirname "$name")" - git show "$left":"$name" >"$tmp/$left_dir/$name" || true - fi - else - if test -n "$compare_staged" - then - ls_list=$(git ls-tree HEAD "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$left_dir/$(dirname "$name")" - git show HEAD:"$name" >"$tmp/$left_dir/$name" - fi - else - mkdir -p "$tmp/$left_dir/$(dirname "$name")" - git show :"$name" >"$tmp/$left_dir/$name" - fi - fi -done < "$tmp/filelist" - -LOCAL="$tmp/$left_dir" -REMOTE="$tmp/$right_dir" - -if test -n "$diff_tool" -then - export BASE - eval $diff_tool '"$LOCAL"' '"$REMOTE"' -else - run_merge_tool "$merge_tool" false -fi - -# Copy files back to the working dir, if requested -if test -n "$copy_back" && test "$right_dir" = "working_tree" -then - cd "$start_dir" - git_top_dir=$(git rev-parse --show-toplevel) - find "$tmp/$right_dir" -type f | - while read file - do - cp "$file" "$git_top_dir/${file#$tmp/$right_dir/}" - done -fi From a1a301114e0ba3f60474d857c93d02890d00e65b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 10 May 2014 10:02:59 -0400 Subject: [PATCH 180/760] t/lib-httpd: require SANITY prereq Our test httpd setup will not generally run as root, because Apache will want to setuid, and we do not set up the "User" config directive. On some systems, like current Debian unstable, Apache fails to start, and we skip the tests: $ sudo ./t5539-fetch-http-shallow.sh --debug 1..0 # SKIP web server setup failed $ cat trash*t5539*/httpd/error.log [...] (22)Invalid argument: AH00024: Couldn't set permissions on the rewrite-map mutex; check User and Group directives AH00016: Configuration Failed However, on other systems (reportedly Ubuntu 11.04), Apache seems to start, and then bails during our tests with: getpwuid: couldn't determine user name from uid 4294967295, you probably need to modify the User directive Child 12037 returned a Fatal error... Apache is exiting! This may be related to the pre-fork/threading model in use (note that the second one complains of the child dying). However, it's not even worth investigating; in either case we just want to skip the tests, and we already recommend against running the test suite as root. Let's just explicitly check this condition and skip the tests rather than expecting Apache to do the right thing. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/lib-httpd.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index b43162ea2a932d..d8918821e6e19a 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -36,6 +36,11 @@ then test_done fi +if ! test_have_prereq SANITY; then + test_skip_or_die $GIT_TEST_HTTPD \ + "Cannot run httpd tests as root" +fi + HTTPD_PARA="" for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2' From 08460345b5a221c0076a48c6be875d64b78b6015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Fri, 9 May 2014 23:51:38 +0200 Subject: [PATCH 181/760] utf8.c: use a table for double_width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor git_wcwidth() and replace the if-else-if chain. Use the table double_width which is scanned by the bisearch() function, which is already used to find combining code points. Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- utf8.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/utf8.c b/utf8.c index 536a9c83e1bbde..5134552a967b02 100644 --- a/utf8.c +++ b/utf8.c @@ -126,6 +126,19 @@ static int git_wcwidth(ucs_char_t ch) { 0x1D1AA, 0x1D1AD }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF } }; + static const struct interval double_width[] = { + { 0x1100, 0x115F }, + { 0x2329, 0x232A }, + { 0x2E80, 0x303E }, + { 0x3040, 0xA4CF }, + { 0xAC00, 0xD7A3 }, + { 0xF900, 0xFAFF }, + { 0xFE30, 0xFE6F }, + { 0xFF00, 0xFF60 }, + { 0xFFE0, 0xFFE6 }, + { 0x20000, 0x2FFFD }, + { 0x30000, 0x3FFFD } + }; /* test for 8-bit control characters */ if (ch == 0) @@ -138,30 +151,12 @@ static int git_wcwidth(ucs_char_t ch) / sizeof(struct interval) - 1)) return 0; - /* - * If we arrive here, ch is neither a combining nor a C0/C1 - * control character. - */ + /* binary search in table of double width characters */ + if (bisearch(ch, double_width, sizeof(double_width) + / sizeof(struct interval) - 1)) + return 2; - return 1 + - (ch >= 0x1100 && - /* Hangul Jamo init. consonants */ - (ch <= 0x115f || - ch == 0x2329 || ch == 0x232a || - /* CJK ... Yi */ - (ch >= 0x2e80 && ch <= 0xa4cf && - ch != 0x303f) || - /* Hangul Syllables */ - (ch >= 0xac00 && ch <= 0xd7a3) || - /* CJK Compatibility Ideographs */ - (ch >= 0xf900 && ch <= 0xfaff) || - /* CJK Compatibility Forms */ - (ch >= 0xfe30 && ch <= 0xfe6f) || - /* Fullwidth Forms */ - (ch >= 0xff00 && ch <= 0xff60) || - (ch >= 0xffe0 && ch <= 0xffe6) || - (ch >= 0x20000 && ch <= 0x2fffd) || - (ch >= 0x30000 && ch <= 0x3fffd))); + return 1; } /* From 9c94389c3ee02df891100b894c1790a524268d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20B=C3=B6gershausen?= Date: Fri, 9 May 2014 23:51:44 +0200 Subject: [PATCH 182/760] utf8: make it easier to auto-update git_wcwidth() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function git_wcwidth() returns for a given unicode code point the width on the display: -1 for control characters, 0 for combining or other non-visible code points 1 for e.g. ASCII 2 for double-width code points. This table had been originally been extracted for one Unicode version, probably 3.2. We now use two tables these days, one for zero-width and another for double-width. Make it easier to update these tables to a later version of Unicode by factoring out the table from utf8.c into unicode_width.h and add the script update_unicode.sh to update the table based on the latest Unicode specification files. Thanks to Peter Krefting and Kevin Bracey for helping with their Unicode knowledge. Signed-off-by: Torsten Bögershausen Signed-off-by: Junio C Hamano --- .gitignore | 1 + Makefile | 1 + unicode_width.h | 288 ++++++++++++++++++++++++++++++++++++++++++++++ update_unicode.sh | 37 ++++++ utf8.c | 61 +--------- 5 files changed, 329 insertions(+), 59 deletions(-) create mode 100644 unicode_width.h create mode 100755 update_unicode.sh diff --git a/.gitignore b/.gitignore index b5f9defed37c43..252792a11a4bd4 100644 --- a/.gitignore +++ b/.gitignore @@ -225,6 +225,7 @@ /config.mak.autogen /config.mak.append /configure +/unicode /tags /TAGS /cscope* diff --git a/Makefile b/Makefile index dddaf4f287cf5c..a7c1f4a46d7ca4 100644 --- a/Makefile +++ b/Makefile @@ -726,6 +726,7 @@ LIB_H += transport.h LIB_H += tree-walk.h LIB_H += tree.h LIB_H += unpack-trees.h +LIB_H += unicode_width.h LIB_H += url.h LIB_H += urlmatch.h LIB_H += userdiff.h diff --git a/unicode_width.h b/unicode_width.h new file mode 100644 index 00000000000000..4db78038e43ada --- /dev/null +++ b/unicode_width.h @@ -0,0 +1,288 @@ +static const struct interval zero_width[] = { +{ 0x0300, 0x036F }, +{ 0x0483, 0x0489 }, +{ 0x0591, 0x05BD }, +{ 0x05BF, 0x05BF }, +{ 0x05C1, 0x05C2 }, +{ 0x05C4, 0x05C5 }, +{ 0x05C7, 0x05C7 }, +{ 0x0600, 0x0604 }, +{ 0x0610, 0x061A }, +{ 0x061C, 0x061C }, +{ 0x064B, 0x065F }, +{ 0x0670, 0x0670 }, +{ 0x06D6, 0x06DD }, +{ 0x06DF, 0x06E4 }, +{ 0x06E7, 0x06E8 }, +{ 0x06EA, 0x06ED }, +{ 0x070F, 0x070F }, +{ 0x0711, 0x0711 }, +{ 0x0730, 0x074A }, +{ 0x07A6, 0x07B0 }, +{ 0x07EB, 0x07F3 }, +{ 0x0816, 0x0819 }, +{ 0x081B, 0x0823 }, +{ 0x0825, 0x0827 }, +{ 0x0829, 0x082D }, +{ 0x0859, 0x085B }, +{ 0x08E4, 0x08FE }, +{ 0x0900, 0x0902 }, +{ 0x093A, 0x093A }, +{ 0x093C, 0x093C }, +{ 0x0941, 0x0948 }, +{ 0x094D, 0x094D }, +{ 0x0951, 0x0957 }, +{ 0x0962, 0x0963 }, +{ 0x0981, 0x0981 }, +{ 0x09BC, 0x09BC }, +{ 0x09C1, 0x09C4 }, +{ 0x09CD, 0x09CD }, +{ 0x09E2, 0x09E3 }, +{ 0x0A01, 0x0A02 }, +{ 0x0A3C, 0x0A3C }, +{ 0x0A41, 0x0A42 }, +{ 0x0A47, 0x0A48 }, +{ 0x0A4B, 0x0A4D }, +{ 0x0A51, 0x0A51 }, +{ 0x0A70, 0x0A71 }, +{ 0x0A75, 0x0A75 }, +{ 0x0A81, 0x0A82 }, +{ 0x0ABC, 0x0ABC }, +{ 0x0AC1, 0x0AC5 }, +{ 0x0AC7, 0x0AC8 }, +{ 0x0ACD, 0x0ACD }, +{ 0x0AE2, 0x0AE3 }, +{ 0x0B01, 0x0B01 }, +{ 0x0B3C, 0x0B3C }, +{ 0x0B3F, 0x0B3F }, +{ 0x0B41, 0x0B44 }, +{ 0x0B4D, 0x0B4D }, +{ 0x0B56, 0x0B56 }, +{ 0x0B62, 0x0B63 }, +{ 0x0B82, 0x0B82 }, +{ 0x0BC0, 0x0BC0 }, +{ 0x0BCD, 0x0BCD }, +{ 0x0C3E, 0x0C40 }, +{ 0x0C46, 0x0C48 }, +{ 0x0C4A, 0x0C4D }, +{ 0x0C55, 0x0C56 }, +{ 0x0C62, 0x0C63 }, +{ 0x0CBC, 0x0CBC }, +{ 0x0CBF, 0x0CBF }, +{ 0x0CC6, 0x0CC6 }, +{ 0x0CCC, 0x0CCD }, +{ 0x0CE2, 0x0CE3 }, +{ 0x0D41, 0x0D44 }, +{ 0x0D4D, 0x0D4D }, +{ 0x0D62, 0x0D63 }, +{ 0x0DCA, 0x0DCA }, +{ 0x0DD2, 0x0DD4 }, +{ 0x0DD6, 0x0DD6 }, +{ 0x0E31, 0x0E31 }, +{ 0x0E34, 0x0E3A }, +{ 0x0E47, 0x0E4E }, +{ 0x0EB1, 0x0EB1 }, +{ 0x0EB4, 0x0EB9 }, +{ 0x0EBB, 0x0EBC }, +{ 0x0EC8, 0x0ECD }, +{ 0x0F18, 0x0F19 }, +{ 0x0F35, 0x0F35 }, +{ 0x0F37, 0x0F37 }, +{ 0x0F39, 0x0F39 }, +{ 0x0F71, 0x0F7E }, +{ 0x0F80, 0x0F84 }, +{ 0x0F86, 0x0F87 }, +{ 0x0F8D, 0x0F97 }, +{ 0x0F99, 0x0FBC }, +{ 0x0FC6, 0x0FC6 }, +{ 0x102D, 0x1030 }, +{ 0x1032, 0x1037 }, +{ 0x1039, 0x103A }, +{ 0x103D, 0x103E }, +{ 0x1058, 0x1059 }, +{ 0x105E, 0x1060 }, +{ 0x1071, 0x1074 }, +{ 0x1082, 0x1082 }, +{ 0x1085, 0x1086 }, +{ 0x108D, 0x108D }, +{ 0x109D, 0x109D }, +{ 0x1160, 0x11FF }, +{ 0x135D, 0x135F }, +{ 0x1712, 0x1714 }, +{ 0x1732, 0x1734 }, +{ 0x1752, 0x1753 }, +{ 0x1772, 0x1773 }, +{ 0x17B4, 0x17B5 }, +{ 0x17B7, 0x17BD }, +{ 0x17C6, 0x17C6 }, +{ 0x17C9, 0x17D3 }, +{ 0x17DD, 0x17DD }, +{ 0x180B, 0x180E }, +{ 0x18A9, 0x18A9 }, +{ 0x1920, 0x1922 }, +{ 0x1927, 0x1928 }, +{ 0x1932, 0x1932 }, +{ 0x1939, 0x193B }, +{ 0x1A17, 0x1A18 }, +{ 0x1A1B, 0x1A1B }, +{ 0x1A56, 0x1A56 }, +{ 0x1A58, 0x1A5E }, +{ 0x1A60, 0x1A60 }, +{ 0x1A62, 0x1A62 }, +{ 0x1A65, 0x1A6C }, +{ 0x1A73, 0x1A7C }, +{ 0x1A7F, 0x1A7F }, +{ 0x1B00, 0x1B03 }, +{ 0x1B34, 0x1B34 }, +{ 0x1B36, 0x1B3A }, +{ 0x1B3C, 0x1B3C }, +{ 0x1B42, 0x1B42 }, +{ 0x1B6B, 0x1B73 }, +{ 0x1B80, 0x1B81 }, +{ 0x1BA2, 0x1BA5 }, +{ 0x1BA8, 0x1BA9 }, +{ 0x1BAB, 0x1BAB }, +{ 0x1BE6, 0x1BE6 }, +{ 0x1BE8, 0x1BE9 }, +{ 0x1BED, 0x1BED }, +{ 0x1BEF, 0x1BF1 }, +{ 0x1C2C, 0x1C33 }, +{ 0x1C36, 0x1C37 }, +{ 0x1CD0, 0x1CD2 }, +{ 0x1CD4, 0x1CE0 }, +{ 0x1CE2, 0x1CE8 }, +{ 0x1CED, 0x1CED }, +{ 0x1CF4, 0x1CF4 }, +{ 0x1DC0, 0x1DE6 }, +{ 0x1DFC, 0x1DFF }, +{ 0x200B, 0x200F }, +{ 0x202A, 0x202E }, +{ 0x2060, 0x2064 }, +{ 0x2066, 0x206F }, +{ 0x20D0, 0x20F0 }, +{ 0x2CEF, 0x2CF1 }, +{ 0x2D7F, 0x2D7F }, +{ 0x2DE0, 0x2DFF }, +{ 0x302A, 0x302D }, +{ 0x3099, 0x309A }, +{ 0xA66F, 0xA672 }, +{ 0xA674, 0xA67D }, +{ 0xA69F, 0xA69F }, +{ 0xA6F0, 0xA6F1 }, +{ 0xA802, 0xA802 }, +{ 0xA806, 0xA806 }, +{ 0xA80B, 0xA80B }, +{ 0xA825, 0xA826 }, +{ 0xA8C4, 0xA8C4 }, +{ 0xA8E0, 0xA8F1 }, +{ 0xA926, 0xA92D }, +{ 0xA947, 0xA951 }, +{ 0xA980, 0xA982 }, +{ 0xA9B3, 0xA9B3 }, +{ 0xA9B6, 0xA9B9 }, +{ 0xA9BC, 0xA9BC }, +{ 0xAA29, 0xAA2E }, +{ 0xAA31, 0xAA32 }, +{ 0xAA35, 0xAA36 }, +{ 0xAA43, 0xAA43 }, +{ 0xAA4C, 0xAA4C }, +{ 0xAAB0, 0xAAB0 }, +{ 0xAAB2, 0xAAB4 }, +{ 0xAAB7, 0xAAB8 }, +{ 0xAABE, 0xAABF }, +{ 0xAAC1, 0xAAC1 }, +{ 0xAAEC, 0xAAED }, +{ 0xAAF6, 0xAAF6 }, +{ 0xABE5, 0xABE5 }, +{ 0xABE8, 0xABE8 }, +{ 0xABED, 0xABED }, +{ 0xFB1E, 0xFB1E }, +{ 0xFE00, 0xFE0F }, +{ 0xFE20, 0xFE26 }, +{ 0xFEFF, 0xFEFF }, +{ 0xFFF9, 0xFFFB }, +{ 0x101FD, 0x101FD }, +{ 0x10A01, 0x10A03 }, +{ 0x10A05, 0x10A06 }, +{ 0x10A0C, 0x10A0F }, +{ 0x10A38, 0x10A3A }, +{ 0x10A3F, 0x10A3F }, +{ 0x11001, 0x11001 }, +{ 0x11038, 0x11046 }, +{ 0x11080, 0x11081 }, +{ 0x110B3, 0x110B6 }, +{ 0x110B9, 0x110BA }, +{ 0x110BD, 0x110BD }, +{ 0x11100, 0x11102 }, +{ 0x11127, 0x1112B }, +{ 0x1112D, 0x11134 }, +{ 0x11180, 0x11181 }, +{ 0x111B6, 0x111BE }, +{ 0x116AB, 0x116AB }, +{ 0x116AD, 0x116AD }, +{ 0x116B0, 0x116B5 }, +{ 0x116B7, 0x116B7 }, +{ 0x16F8F, 0x16F92 }, +{ 0x1D167, 0x1D169 }, +{ 0x1D173, 0x1D182 }, +{ 0x1D185, 0x1D18B }, +{ 0x1D1AA, 0x1D1AD }, +{ 0x1D242, 0x1D244 }, +{ 0xE0001, 0xE0001 }, +{ 0xE0020, 0xE007F }, +{ 0xE0100, 0xE01EF } +}; +static const struct interval double_width[] = { +{ /* plane */ 0x0, 0x1C }, +{ /* plane */ 0x1C, 0x21 }, +{ /* plane */ 0x21, 0x22 }, +{ /* plane */ 0x22, 0x23 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ 0x1100, 0x115F }, +{ 0x2329, 0x232A }, +{ 0x2E80, 0x2E99 }, +{ 0x2E9B, 0x2EF3 }, +{ 0x2F00, 0x2FD5 }, +{ 0x2FF0, 0x2FFB }, +{ 0x3000, 0x303E }, +{ 0x3041, 0x3096 }, +{ 0x3099, 0x30FF }, +{ 0x3105, 0x312D }, +{ 0x3131, 0x318E }, +{ 0x3190, 0x31BA }, +{ 0x31C0, 0x31E3 }, +{ 0x31F0, 0x321E }, +{ 0x3220, 0x3247 }, +{ 0x3250, 0x32FE }, +{ 0x3300, 0x4DBF }, +{ 0x4E00, 0xA48C }, +{ 0xA490, 0xA4C6 }, +{ 0xA960, 0xA97C }, +{ 0xAC00, 0xD7A3 }, +{ 0xF900, 0xFAFF }, +{ 0xFE10, 0xFE19 }, +{ 0xFE30, 0xFE52 }, +{ 0xFE54, 0xFE66 }, +{ 0xFE68, 0xFE6B }, +{ 0xFF01, 0xFF60 }, +{ 0xFFE0, 0xFFE6 }, +{ 0x1B000, 0x1B001 }, +{ 0x1F200, 0x1F202 }, +{ 0x1F210, 0x1F23A }, +{ 0x1F240, 0x1F248 }, +{ 0x1F250, 0x1F251 }, +{ 0x20000, 0x2FFFD }, +{ 0x30000, 0x3FFFD } +}; diff --git a/update_unicode.sh b/update_unicode.sh new file mode 100755 index 00000000000000..000b937e6828d3 --- /dev/null +++ b/update_unicode.sh @@ -0,0 +1,37 @@ +#!/bin/sh +#See http://www.unicode.org/reports/tr44/ +# +#Me Enclosing_Mark an enclosing combining mark +#Mn Nonspacing_Mark a nonspacing combining mark (zero advance width) +#Cf Format a format control character +# +UNICODEWIDTH_H=../unicode_width.h +if ! test -d unicode; then + mkdir unicode +fi && +( cd unicode && + if ! test -f UnicodeData.txt; then + wget http://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt + fi && + if ! test -f EastAsianWidth.txt; then + wget http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt + fi && + if ! test -d uniset; then + git clone https://github.com/depp/uniset.git + fi && + ( + cd uniset && + if ! test -x uniset; then + autoreconf -i && + ./configure --enable-warnings=-Werror CFLAGS='-O0 -ggdb' + fi && + make + ) && + echo "static const struct interval zero_width[] = {" >$UNICODEWIDTH_H && + UNICODE_DIR=. ./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD | + grep -v plane >>$UNICODEWIDTH_H && + echo "};" >>$UNICODEWIDTH_H && + echo "static const struct interval double_width[] = {" >>$UNICODEWIDTH_H && + UNICODE_DIR=. ./uniset/uniset --32 eaw:F,W >>$UNICODEWIDTH_H && + echo "};" >>$UNICODEWIDTH_H +) diff --git a/utf8.c b/utf8.c index 5134552a967b02..db7ef3c10a420e 100644 --- a/utf8.c +++ b/utf8.c @@ -80,65 +80,8 @@ static int git_wcwidth(ucs_char_t ch) { /* * Sorted list of non-overlapping intervals of non-spacing characters, - * generated by - * "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c". */ - static const struct interval combining[] = { - { 0x0300, 0x036F }, { 0x0483, 0x0489 }, { 0x0591, 0x05BD }, - { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, { 0x05C4, 0x05C5 }, - { 0x05C7, 0x05C7 }, { 0x0600, 0x0604 }, { 0x0610, 0x061A }, - { 0x064B, 0x065F }, { 0x0670, 0x0670 }, { 0x06D6, 0x06E4 }, - { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, { 0x070F, 0x070F }, - { 0x0711, 0x0711 }, { 0x0730, 0x074A }, { 0x07A6, 0x07B0 }, - { 0x0901, 0x0902 }, { 0x093C, 0x093C }, { 0x0941, 0x0948 }, - { 0x094D, 0x094D }, { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, - { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, - { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, - { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, - { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, - { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, - { 0x0ACD, 0x0ACD }, { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, - { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, - { 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, - { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, - { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, - { 0x0CBC, 0x0CBC }, { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, - { 0x0CCC, 0x0CCD }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, - { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, - { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, - { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, - { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, - { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, - { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, - { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, - { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, - { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x1712, 0x1714 }, - { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, { 0x1772, 0x1773 }, - { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 }, - { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, { 0x180B, 0x180D }, - { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, { 0x1927, 0x1928 }, - { 0x1932, 0x1932 }, { 0x1939, 0x193B }, { 0x200B, 0x200F }, - { 0x202A, 0x202E }, { 0x2060, 0x2063 }, { 0x206A, 0x206F }, - { 0x20D0, 0x20EA }, { 0x302A, 0x302F }, { 0x3099, 0x309A }, - { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, { 0xFE20, 0xFE23 }, - { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, { 0x1D167, 0x1D169 }, - { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, - { 0x1D1AA, 0x1D1AD }, { 0xE0001, 0xE0001 }, - { 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF } - }; - static const struct interval double_width[] = { - { 0x1100, 0x115F }, - { 0x2329, 0x232A }, - { 0x2E80, 0x303E }, - { 0x3040, 0xA4CF }, - { 0xAC00, 0xD7A3 }, - { 0xF900, 0xFAFF }, - { 0xFE30, 0xFE6F }, - { 0xFF00, 0xFF60 }, - { 0xFFE0, 0xFFE6 }, - { 0x20000, 0x2FFFD }, - { 0x30000, 0x3FFFD } - }; +#include "unicode_width.h" /* test for 8-bit control characters */ if (ch == 0) @@ -147,7 +90,7 @@ static int git_wcwidth(ucs_char_t ch) return -1; /* binary search in table of non-spacing characters */ - if (bisearch(ch, combining, sizeof(combining) + if (bisearch(ch, zero_width, sizeof(zero_width) / sizeof(struct interval) - 1)) return 0; From 77583e7739c76f623f49681c9ee4d10a313fe786 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 12 May 2014 00:38:39 -0400 Subject: [PATCH 183/760] index-pack: distinguish missing objects from type errors When we fetch a pack that does not contain an object we expected to receive, we get an error like: $ git init --bare tmp.git && cd tmp.git $ git fetch ../parent.git [...] error: Could not read 964953ec7bcc0245cb1d0db4095455edd21a2f2e fatal: Failed to traverse parents of commit b8247b40caf6704fe52736cdece6d6aae87471aa error: ../parent.git did not send all necessary objects This comes from the check_everything_connected rev-list. If we try cloning the same repo (rather than a fetch), we end up using index-pack's --check-self-contained-and-connected option instead, which produces output like: $ git clone --no-local --bare parent.git tmp.git [...] fatal: object of unexpected type fatal: index-pack failed Not only is the sha1 missing, but it's a misleading message. There's no type problem, but rather a missing object problem; we don't notice the difference because we simply compare OBJ_BAD != OBJ_BLOB. Let's provide a different message for this case: $ git clone --no-local --bare parent.git tmp.git fatal: did not receive expected object 6b00a8c61ed379d5f925a72c1987c9c52129d364 fatal: index-pack failed While we're at it, let's also improve a true type mismatch error to look like fatal: object 6b00a8c61ed379d5f925a72c1987c9c52129d364: expected type blob, got tree Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index fa74972886cc8e..7878836eb45cef 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -200,8 +200,13 @@ static unsigned check_object(struct object *obj) if (!(obj->flags & FLAG_CHECKED)) { unsigned long size; int type = sha1_object_info(obj->sha1, &size); - if (type != obj->type || type <= 0) - die(_("object of unexpected type")); + if (type <= 0) + die(_("did not receive expected object %s"), + sha1_to_hex(obj->sha1)); + if (type != obj->type) + die(_("object %s: expected type %s, found %s"), + sha1_to_hex(obj->sha1), + typename(obj->type), typename(type)); obj->flags |= FLAG_CHECKED; return 1; } From 20c4fbf97de63262a1a8fa7757134d625b9d7a26 Mon Sep 17 00:00:00 2001 From: William Giokas <1007380@gmail.com> Date: Thu, 8 May 2014 21:36:50 -0500 Subject: [PATCH 184/760] svn-fe: conform to pep8 Quite a large change, most of this was whitespace changes, though there were a few places where I removed a comma or added a few characters. Should pass through pep8 and pass every test. Signed-off-by: William Giokas <1007380@gmail.com> Acked-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- contrib/svn-fe/svnrdump_sim.py | 93 +++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/contrib/svn-fe/svnrdump_sim.py b/contrib/svn-fe/svnrdump_sim.py index 4e78a1c3cda156..11ac6f692733fb 100755 --- a/contrib/svn-fe/svnrdump_sim.py +++ b/contrib/svn-fe/svnrdump_sim.py @@ -5,53 +5,64 @@ To simulate incremental imports the environment variable SVNRMAX can be set to the highest revision that should be available. """ -import sys, os +import sys +import os if sys.hexversion < 0x02040000: - # The limiter is the ValueError() calls. This may be too conservative - sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n") - sys.exit(1) + # The limiter is the ValueError() calls. This may be too conservative + sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n") + sys.exit(1) + def getrevlimit(): - var = 'SVNRMAX' - if var in os.environ: - return os.environ[var] - return None + var = 'SVNRMAX' + if var in os.environ: + return os.environ[var] + return None + def writedump(url, lower, upper): - if url.startswith('sim://'): - filename = url[6:] - if filename[-1] == '/': filename = filename[:-1] #remove terminating slash - else: - raise ValueError('sim:// url required') - f = open(filename, 'r'); - state = 'header' - wroterev = False - while(True): - l = f.readline() - if l == '': break - if state == 'header' and l.startswith('Revision-number: '): - state = 'prefix' - if state == 'prefix' and l == 'Revision-number: %s\n' % lower: - state = 'selection' - if not upper == 'HEAD' and state == 'selection' and l == 'Revision-number: %s\n' % upper: - break; + if url.startswith('sim://'): + filename = url[6:] + if filename[-1] == '/': + filename = filename[:-1] # remove terminating slash + else: + raise ValueError('sim:// url required') + f = open(filename, 'r') + state = 'header' + wroterev = False + while(True): + l = f.readline() + if l == '': + break + if state == 'header' and l.startswith('Revision-number: '): + state = 'prefix' + if state == 'prefix' and l == 'Revision-number: %s\n' % lower: + state = 'selection' + if not upper == 'HEAD' and state == 'selection' and \ + l == 'Revision-number: %s\n' % upper: + break - if state == 'header' or state == 'selection': - if state == 'selection': wroterev = True - sys.stdout.write(l) - return wroterev + if state == 'header' or state == 'selection': + if state == 'selection': + wroterev = True + sys.stdout.write(l) + return wroterev if __name__ == "__main__": - if not (len(sys.argv) in (3, 4, 5)): - print("usage: %s dump URL -rLOWER:UPPER") - sys.exit(1) - if not sys.argv[1] == 'dump': raise NotImplementedError('only "dump" is suppported.') - url = sys.argv[2] - r = ('0', 'HEAD') - if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r': - r = sys.argv[3][2:].lstrip().split(':') - if not getrevlimit() is None: r[1] = getrevlimit() - if writedump(url, r[0], r[1]): ret = 0 - else: ret = 1 - sys.exit(ret) + if not (len(sys.argv) in (3, 4, 5)): + print("usage: %s dump URL -rLOWER:UPPER") + sys.exit(1) + if not sys.argv[1] == 'dump': + raise NotImplementedError('only "dump" is suppported.') + url = sys.argv[2] + r = ('0', 'HEAD') + if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r': + r = sys.argv[3][2:].lstrip().split(':') + if not getrevlimit() is None: + r[1] = getrevlimit() + if writedump(url, r[0], r[1]): + ret = 0 + else: + ret = 1 + sys.exit(ret) From 6f1871fe0f7d9bddfbe199cceeb255cf8edbaab3 Mon Sep 17 00:00:00 2001 From: James Denholm Date: Tue, 13 May 2014 14:08:58 +1000 Subject: [PATCH 185/760] contrib/subtree: allow adding an annotated tag cmd_add_commit() is passed FETCH_HEAD by cmd_add_repository, which is then rev-parsed into an object name. However, if the user is fetching a tag rather than a branch HEAD, such as by executing: $ git subtree add -P oldGit https://github.com/git/git.git tags/v1.8.0 the object name refers to a tag and is never peeled, and the git commit-tree call (line 561) slaps us in the face because it doesn't peel tags to commits. Because peeling a committish doesn't do anything if it's already a commit, fix by peeling the object name before assigning it to $rev using peel_committish() from git:git-sh-setup.sh, a pre-existing dependency of git-subtree. Reported-by: Kevin Cagle Helped-by: Junio C Hamano Signed-off-by: James Denholm Signed-off-by: Junio C Hamano --- contrib/subtree/git-subtree.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index db925ca76991c6..fa1a5839af2d0c 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -558,8 +558,9 @@ cmd_add_commit() commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else + revp=$(peel_committish "$rev") && commit=$(add_msg "$dir" "$headrev" "$rev" | - git commit-tree $tree $headp -p "$rev") || exit $? + git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $? From 670a7297c2afe4de387cb208fddc90f0f59df6aa Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 13 May 2014 11:46:57 -0700 Subject: [PATCH 186/760] Documentation: mention config sources for @{upstream} The earlier documentation made vague references to "is set to build on". Flesh that out with references to the config settings, so folks can use git-config(1) to get more detail on what @{upstream} means. For example, @{upstream} does not care about remote.pushdefault or branch..pushremote. Signed-off-by: W. Trevor King Signed-off-by: Junio C Hamano --- Documentation/revisions.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index 5a286d0d61ffc5..07961185fe0cdd 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -94,7 +94,9 @@ some output processing may assume ref names in UTF-8. '@\{upstream\}', e.g. 'master@\{upstream\}', '@\{u\}':: The suffix '@\{upstream\}' to a branchname (short form '@\{u\}') refers to the branch that the branch specified by branchname is set to build on - top of. A missing branchname defaults to the current one. + top of (configured with `branch..remote` and + `branch..merge`). A missing branchname defaults to the + current one. '{caret}', e.g. 'HEAD{caret}, v1.5.1{caret}0':: A suffix '{caret}' to a revision parameter means the first parent of From ccfb5bdad957387cc6b36c9115aaa9615a55a893 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Wed, 24 Oct 2012 00:15:29 +0100 Subject: [PATCH 187/760] wincred: add install target Signed-off-by: Pat Thoyts Signed-off-by: Stepan Kasal Acked-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- contrib/credential/wincred/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/credential/wincred/Makefile b/contrib/credential/wincred/Makefile index bad45ca47a2379..39fa5e0c592112 100644 --- a/contrib/credential/wincred/Makefile +++ b/contrib/credential/wincred/Makefile @@ -7,8 +7,16 @@ CFLAGS = -O2 -Wall -include ../../../config.mak.autogen -include ../../../config.mak +prefix ?= /usr/local +libexecdir ?= $(prefix)/libexec/git-core + +INSTALL ?= install + git-credential-wincred.exe : git-credential-wincred.c $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ +install: git-credential-wincred.exe + $(INSTALL) -m 755 $^ $(libexecdir) + clean: $(RM) git-credential-wincred.exe From 248b68f3f29e63fca83db8421350184d20481610 Mon Sep 17 00:00:00 2001 From: Pat Thoyts Date: Wed, 24 Oct 2012 00:15:29 +0100 Subject: [PATCH 188/760] wincred: avoid overwriting configured variables Signed-off-by: Pat Thoyts Signed-off-by: Stepan Kasal Acked-by: Erik Faye-Lund Signed-off-by: Junio C Hamano --- contrib/credential/wincred/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/credential/wincred/Makefile b/contrib/credential/wincred/Makefile index 39fa5e0c592112..6e992c08667d0b 100644 --- a/contrib/credential/wincred/Makefile +++ b/contrib/credential/wincred/Makefile @@ -1,12 +1,12 @@ all: git-credential-wincred.exe -CC = gcc -RM = rm -f -CFLAGS = -O2 -Wall - -include ../../../config.mak.autogen -include ../../../config.mak +CC ?= gcc +RM ?= rm -f +CFLAGS ?= -O2 -Wall + prefix ?= /usr/local libexecdir ?= $(prefix)/libexec/git-core From ad2f7255b3e93dacd0982a946d30f6595dd8a805 Mon Sep 17 00:00:00 2001 From: Max Kirillov Date: Thu, 15 May 2014 01:12:45 +0300 Subject: [PATCH 189/760] git-show: fix 'git show -s' to not add extra terminator after merge commit When git show -s is called for merge commit it prints extra newline after any merge commit. This differs from output for commits with one parent. Fix it by more thorough checking that diff output is disabled. The code in question exists since commit 3969cf7db1. The additional newline is really needed for cases when patch is requested, test t4013-diff-various.sh contains cases which can demonstrate behavior when the condition is restricted further. Tests: Added merge commit to 'set up a bit of history' case in t7007-show.sh to cover the fix. Existing tests are updated to demonstrate the new behaviour. Earlier, the tests that used "git show -s --pretty=format:%s", even though "--pretty=format:%s" calls for item separator semantics and does not ask for the terminating newline after the last item, expected the output to end with such a newline. They were relying on the buggy behaviour. Use of "--format=%s", which is equivalent to "--pretty=tformat:%s" that asks for a terminating newline after each item, is a more realistic way to use the command. In the test 'merge log messages' the expected data is changed, because it was explicitly listing the extra newline. Also the msg.nologff and msg.nolognoff expected files are replaced by one msg.nolog, because they were diffing because of the bug, and now there should be no difference. Signed-off-by: Max Kirillov Signed-off-by: Junio C Hamano --- combine-diff.c | 3 ++- t/t1507-rev-parse-upstream.sh | 2 +- t/t7007-show.sh | 10 +++++++--- t/t7600-merge.sh | 11 +++++------ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 3b92c44880228a..ff6ceafe61736c 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1331,7 +1331,8 @@ void diff_tree_combined(const unsigned char *sha1, if (show_log_first && i == 0) { show_log(rev); - if (rev->verbose_header && opt->output_format) + if (rev->verbose_header && opt->output_format && + opt->output_format != DIFF_FORMAT_NO_OUTPUT) printf("%s%c", diff_line_prefix(opt), opt->line_termination); } diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 178694ee63937a..1978947c4196fb 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -121,7 +121,7 @@ test_expect_success 'merge my-side@{u} records the correct name' ' git branch -D new ;# can fail but is ok git branch -t new my-side@{u} && git merge -s ours new@{u} && - git show -s --pretty=format:%s >actual && + git show -s --pretty=tformat:%s >actual && echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && test_cmp expect actual ) diff --git a/t/t7007-show.sh b/t/t7007-show.sh index e41fa00b80e9b3..1b824fe5ede3b9 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -24,7 +24,8 @@ test_expect_success 'set up a bit of history' ' git tag -m "annotated tag" annotated && git checkout -b side HEAD^^ && test_commit side2 && - test_commit side3 + test_commit side3 && + test_merge merge main3 ' test_expect_success 'showing two commits' ' @@ -109,8 +110,11 @@ test_expect_success 'showing range' ' ' test_expect_success '-s suppresses diff' ' - echo main3 >expect && - git show -s --format=%s main3 >actual && + cat >expect <<-\EOF && + merge + main3 + EOF + git show -s --format=%s merge main3 >actual && test_cmp expect actual ' diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 10aa0280178334..b16462132fd01f 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -57,11 +57,10 @@ create_merge_msgs () { git log --no-merges ^HEAD c2 c3 } >squash.1-5-9 && : >msg.nologff && - echo >msg.nolognoff && + : >msg.nolognoff && { echo "* tag 'c3':" && - echo " commit 3" && - echo + echo " commit 3" } >msg.log } @@ -71,7 +70,7 @@ verify_merge () { git diff --exit-code && if test -n "$3" then - git show -s --pretty=format:%s HEAD >msg.act && + git show -s --pretty=tformat:%s HEAD >msg.act && test_cmp "$3" msg.act fi } @@ -620,10 +619,10 @@ test_expect_success 'merge early part of c2' ' git tag c6 && git branch -f c5-branch c5 && git merge c5-branch~1 && - git show -s --pretty=format:%s HEAD >actual.branch && + git show -s --pretty=tformat:%s HEAD >actual.branch && git reset --keep HEAD^ && git merge c5~1 && - git show -s --pretty=format:%s HEAD >actual.tag && + git show -s --pretty=tformat:%s HEAD >actual.tag && test_cmp expected.branch actual.branch && test_cmp expected.tag actual.tag ' From 530481004443a00fbf5ab477b36b90508b4dc59d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 14 May 2014 18:13:06 -0400 Subject: [PATCH 190/760] run_diff_files: do not look at uninitialized stat data If we try to diff an index entry marked CE_VALID (because it was marked with --assume-unchanged), we do not bother even running stat() on the file to see if it was removed. This started long ago with 540e694 (Prevent diff machinery from examining assume-unchanged entries on worktree, 2009-08-11). However, the subsequent code may look at our "struct stat" and expect to find actual data; currently it will find whatever cruft was left on the stack. This can cause problems in two situations: 1. We call match_stat_with_submodule with the stat data, so a submodule may be erroneously marked as changed. 2. If --find-copies-harder is in effect, we pass all entries, even unchanged ones, to diff_change, so it can list them as rename/copy sources. Since we found no change, we assume that function will realize it and not actually display any diff output. However, we end up feeding it a bogus mode, leading it to sometimes claim there was a mode change. We can fix both by splitting the CE_VALID and regular code paths, and making sure only to look at the stat information in the latter. Furthermore, we push the declaration of our "struct stat" down into the code paths that actually set it, so we cannot accidentally access it uninitialized in future code. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff-lib.c | 33 ++++++++++++++++++++------------ t/t4039-diff-assume-unchanged.sh | 11 +++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 346cac651da725..73eedca9c8f874 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -99,7 +99,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option) diff_unmerged_stage = 2; entries = active_nr; for (i = 0; i < entries; i++) { - struct stat st; unsigned int oldmode, newmode; struct cache_entry *ce = active_cache[i]; int changed; @@ -117,6 +116,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) unsigned int wt_mode = 0; int num_compare_stages = 0; size_t path_len; + struct stat st; path_len = ce_namelen(ce); @@ -198,26 +198,35 @@ int run_diff_files(struct rev_info *revs, unsigned int option) continue; /* If CE_VALID is set, don't look at workdir for file removal */ - changed = (ce->ce_flags & CE_VALID) ? 0 : check_removed(ce, &st); - if (changed) { - if (changed < 0) { - perror(ce->name); + if (ce->ce_flags & CE_VALID) { + changed = 0; + newmode = ce->ce_mode; + } else { + struct stat st; + + changed = check_removed(ce, &st); + if (changed) { + if (changed < 0) { + perror(ce->name); + continue; + } + diff_addremove(&revs->diffopt, '-', ce->ce_mode, + ce->sha1, !is_null_sha1(ce->sha1), + ce->name, 0); continue; } - diff_addremove(&revs->diffopt, '-', ce->ce_mode, - ce->sha1, !is_null_sha1(ce->sha1), - ce->name, 0); - continue; + + changed = match_stat_with_submodule(&revs->diffopt, ce, &st, + ce_option, &dirty_submodule); + newmode = ce_mode_from_stat(ce, st.st_mode); } - changed = match_stat_with_submodule(&revs->diffopt, ce, &st, - ce_option, &dirty_submodule); + if (!changed && !dirty_submodule) { ce_mark_uptodate(ce); if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)) continue; } oldmode = ce->ce_mode; - newmode = ce_mode_from_stat(ce, st.st_mode); diff_change(&revs->diffopt, oldmode, newmode, ce->sha1, (changed ? null_sha1 : ce->sha1), !is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)), diff --git a/t/t4039-diff-assume-unchanged.sh b/t/t4039-diff-assume-unchanged.sh index 9d9498bd95c525..23c0e357a765f0 100755 --- a/t/t4039-diff-assume-unchanged.sh +++ b/t/t4039-diff-assume-unchanged.sh @@ -28,4 +28,15 @@ test_expect_success 'diff-files does not examine assume-unchanged entries' ' test -z "$(git diff-files -- one)" ' +test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits' ' + echo content >exec && + chmod +x exec && + git add exec && + git commit -m exec && + git update-index --assume-unchanged exec && + >expect && + git diff-files --find-copies-harder -- exec >actual && + test_cmp expect actual +' + test_done From c460c0ecdca46be85f6d9c845f9df7ce0e45c3c2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:33:26 -0400 Subject: [PATCH 191/760] run-command: store an optional argv_array All child_process structs need to point to an argv. For flexibility, we do not mandate the use of a dynamic argv_array. However, because the child_process does not own the memory, this can make memory management with a separate argv_array difficult. For example, if a function calls start_command but not finish_command, the argv memory must persist. The code needs to arrange to clean up the argv_array separately after finish_command runs. As a result, some of our code in this situation just leaks the memory. To help such cases, this patch adds a built-in argv_array to the child_process, which gets cleaned up automatically (both in finish_command and when start_command fails). Callers may use it if they choose, but can continue to use the raw argv if they wish. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/technical/api-run-command.txt | 7 +++++++ run-command.c | 9 ++++++++- run-command.h | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/technical/api-run-command.txt b/Documentation/technical/api-run-command.txt index 5d7d7f2d32f58f..69510ae57afced 100644 --- a/Documentation/technical/api-run-command.txt +++ b/Documentation/technical/api-run-command.txt @@ -109,6 +109,13 @@ terminated), of which .argv[0] is the program name to run (usually without a path). If the command to run is a git command, set argv[0] to the command name without the 'git-' prefix and set .git_cmd = 1. +Note that the ownership of the memory pointed to by .argv stays with the +caller, but it should survive until `finish_command` completes. If the +.argv member is NULL, `start_command` will point it at the .args +`argv_array` (so you may use one or the other, but you must use exactly +one). The memory in .args will be cleaned up automatically during +`finish_command` (or during `start_command` when it is unsuccessful). + The members .in, .out, .err are used to redirect stdin, stdout, stderr as follows: diff --git a/run-command.c b/run-command.c index 75abc478c6da75..be07d4ad335ba6 100644 --- a/run-command.c +++ b/run-command.c @@ -279,6 +279,9 @@ int start_command(struct child_process *cmd) int failed_errno; char *str; + if (!cmd->argv) + cmd->argv = cmd->args.argv; + /* * In case of errors we must keep the promise to close FDs * that have been passed in via ->in and ->out. @@ -328,6 +331,7 @@ int start_command(struct child_process *cmd) fail_pipe: error("cannot create %s pipe for %s: %s", str, cmd->argv[0], strerror(failed_errno)); + argv_array_clear(&cmd->args); errno = failed_errno; return -1; } @@ -519,6 +523,7 @@ int start_command(struct child_process *cmd) close_pair(fderr); else if (cmd->err) close(cmd->err); + argv_array_clear(&cmd->args); errno = failed_errno; return -1; } @@ -543,7 +548,9 @@ int start_command(struct child_process *cmd) int finish_command(struct child_process *cmd) { - return wait_or_whine(cmd->pid, cmd->argv[0]); + int ret = wait_or_whine(cmd->pid, cmd->argv[0]); + argv_array_clear(&cmd->args); + return ret; } int run_command(struct child_process *cmd) diff --git a/run-command.h b/run-command.h index 3653bfa6e123ca..ea73de309bc65c 100644 --- a/run-command.h +++ b/run-command.h @@ -5,8 +5,11 @@ #include #endif +#include "argv-array.h" + struct child_process { const char **argv; + struct argv_array args; pid_t pid; /* * Using .in, .out, .err: From 5eb7f7ead8537420fde3eb344640096fc330bc16 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:33:40 -0400 Subject: [PATCH 192/760] run_column_filter: use argv_array We currently set up the argv array by hand in a fixed-size stack-local array. Using an argv array is more readable, as it handles buffer allocation us (not to mention makes it obvious we do not overflow the array). However, there's a more subtle benefit, too. We leave the function having run start_command (with the child_process in a static global), and then later run finish_command from another function. That means when we run finish_command, neither column_process.argv nor the memory it points to is valid any longer. Most of the time finish_command does not bother looking at argv, but it may if it encounters an error (e.g., waitpid failure or signal death). This is unusual, which is why nobody has noticed. But by using run-command's built-in argv_array, the memory ownership is handled for us automatically. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- column.c | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/column.c b/column.c index 8d1ce88d1493cf..1a468debb4abdd 100644 --- a/column.c +++ b/column.c @@ -370,46 +370,29 @@ static struct child_process column_process; int run_column_filter(int colopts, const struct column_options *opts) { - const char *av[10]; - int ret, ac = 0; - struct strbuf sb_colopt = STRBUF_INIT; - struct strbuf sb_width = STRBUF_INIT; - struct strbuf sb_padding = STRBUF_INIT; + struct argv_array *argv; if (fd_out != -1) return -1; - av[ac++] = "column"; - strbuf_addf(&sb_colopt, "--raw-mode=%d", colopts); - av[ac++] = sb_colopt.buf; - if (opts && opts->width) { - strbuf_addf(&sb_width, "--width=%d", opts->width); - av[ac++] = sb_width.buf; - } - if (opts && opts->indent) { - av[ac++] = "--indent"; - av[ac++] = opts->indent; - } - if (opts && opts->padding) { - strbuf_addf(&sb_padding, "--padding=%d", opts->padding); - av[ac++] = sb_padding.buf; - } - av[ac] = NULL; + memset(&column_process, 0, sizeof(column_process)); + argv = &column_process.args; + + argv_array_push(argv, "column"); + argv_array_pushf(argv, "--raw-mode=%d", colopts); + if (opts && opts->width) + argv_array_pushf(argv, "--width=%d", opts->width); + if (opts && opts->indent) + argv_array_pushf(argv, "--indent=%s", opts->indent); + if (opts && opts->padding) + argv_array_pushf(argv, "--padding=%d", opts->padding); fflush(stdout); - memset(&column_process, 0, sizeof(column_process)); column_process.in = -1; column_process.out = dup(1); column_process.git_cmd = 1; - column_process.argv = av; - - ret = start_command(&column_process); - - strbuf_release(&sb_colopt); - strbuf_release(&sb_width); - strbuf_release(&sb_padding); - if (ret) + if (start_command(&column_process)) return -2; fd_out = dup(1); From 1823bea10fceb371c7876e598d2413c85890cafc Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:34:09 -0400 Subject: [PATCH 193/760] git_connect: use argv_array This avoids magic numbers when we allocate fixed-size argv arrays, and makes it more obvious that we are not overflowing. It is also the first step to fixing a memory leak. When git_connect returns a child_process struct, the argv array in the struct is dynamically allocated, but the individual strings are not (they are either owned elsewhere, or are freed). Later, in finish_connect, we free the array but leave the strings alone. This works for the child_process created by git_connect, but if we use transport_take_over, we may also end up with a child_process created by transport-helper's get_helper. In that case, the strings are freshly allocated, and we would want to free them. However, we have no idea in finish_connect which type we have. By consistently using run-command's internal argv-array, we do not have to worry about this issue at all; finish_command takes care of it for us, and we can drop our manual free entirely. Note that this actually makes the get_helper leak slightly worse; now we are leaking both the strings and the array. But when we adjust it in a future patch, that leak will go away entirely. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- connect.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/connect.c b/connect.c index a983d061a90f0b..94a66502464400 100644 --- a/connect.c +++ b/connect.c @@ -534,22 +534,18 @@ static int git_use_proxy(const char *host) static struct child_process *git_proxy_connect(int fd[2], char *host) { const char *port = STR(DEFAULT_GIT_PORT); - const char **argv; struct child_process *proxy; get_host_and_port(&host, &port); - argv = xmalloc(sizeof(*argv) * 4); - argv[0] = git_proxy_command; - argv[1] = host; - argv[2] = port; - argv[3] = NULL; proxy = xcalloc(1, sizeof(*proxy)); - proxy->argv = argv; + argv_array_push(&proxy->args, git_proxy_command); + argv_array_push(&proxy->args, host); + argv_array_push(&proxy->args, port); proxy->in = -1; proxy->out = -1; if (start_command(proxy)) - die("cannot start proxy %s", argv[0]); + die("cannot start proxy %s", git_proxy_command); fd[0] = proxy->out; /* read from proxy stdout */ fd[1] = proxy->in; /* write to proxy stdin */ return proxy; @@ -663,7 +659,6 @@ struct child_process *git_connect(int fd[2], const char *url, char *hostandport, *path; struct child_process *conn = &no_fork; enum protocol protocol; - const char **arg; struct strbuf cmd = STRBUF_INIT; /* Without this we cannot rely on waitpid() to tell @@ -707,7 +702,6 @@ struct child_process *git_connect(int fd[2], const char *url, sq_quote_buf(&cmd, path); conn->in = conn->out = -1; - conn->argv = arg = xcalloc(7, sizeof(*arg)); if (protocol == PROTO_SSH) { const char *ssh = getenv("GIT_SSH"); int putty = ssh && strcasestr(ssh, "plink"); @@ -718,22 +712,21 @@ struct child_process *git_connect(int fd[2], const char *url, if (!ssh) ssh = "ssh"; - *arg++ = ssh; + argv_array_push(&conn->args, ssh); if (putty && !strcasestr(ssh, "tortoiseplink")) - *arg++ = "-batch"; + argv_array_push(&conn->args, "-batch"); if (port) { /* P is for PuTTY, p is for OpenSSH */ - *arg++ = putty ? "-P" : "-p"; - *arg++ = port; + argv_array_push(&conn->args, putty ? "-P" : "-p"); + argv_array_push(&conn->args, port); } - *arg++ = ssh_host; + argv_array_push(&conn->args, ssh_host); } else { /* remove repo-local variables from the environment */ conn->env = local_repo_env; conn->use_shell = 1; } - *arg++ = cmd.buf; - *arg = NULL; + argv_array_push(&conn->args, cmd.buf); if (start_command(conn)) die("unable to fork"); @@ -759,7 +752,6 @@ int finish_connect(struct child_process *conn) return 0; code = finish_command(conn); - free(conn->argv); free(conn); return code; } From e0ab2ac6c553cbba5d0275cfd35beb3351cae034 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:34:18 -0400 Subject: [PATCH 194/760] get_helper: use run-command's internal argv_array The get_helper functions dynamically allocates an argv_array, feeds it to start_command, and then returns. We then have to later clean up the memory manually after calling finish_command. We can make this simpler by just using run-command's internal argv_array, which handles cleanup for us. This also prevents a memory leak in the case that transport_take_over is used, in which case we free the child in finish_connect, which does not manually free the array. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- transport-helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index b468e4f88e730f..fefd34f134a3f3 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -101,7 +101,6 @@ static void do_take_over(struct transport *transport) static struct child_process *get_helper(struct transport *transport) { struct helper_data *data = transport->data; - struct argv_array argv = ARGV_ARRAY_INIT; struct strbuf buf = STRBUF_INIT; struct child_process *helper; const char **refspecs = NULL; @@ -123,10 +122,9 @@ static struct child_process *get_helper(struct transport *transport) helper->in = -1; helper->out = -1; helper->err = 0; - argv_array_pushf(&argv, "git-remote-%s", data->name); - argv_array_push(&argv, transport->remote->name); - argv_array_push(&argv, remove_ext_force(transport->url)); - helper->argv = argv_array_detach(&argv, NULL); + argv_array_pushf(&helper->args, "git-remote-%s", data->name); + argv_array_push(&helper->args, transport->remote->name); + argv_array_push(&helper->args, remove_ext_force(transport->url)); helper->git_cmd = 0; helper->silent_exec_failure = 1; @@ -245,7 +243,6 @@ static int disconnect_helper(struct transport *transport) close(data->helper->out); fclose(data->out); res = finish_command(data->helper); - argv_array_free_detached(data->helper->argv); free(data->helper); data->helper = NULL; } From 2aeae40a754ed8296df95df263e694ad4eab3a49 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:34:44 -0400 Subject: [PATCH 195/760] get_exporter: use argv_array This simplifies the code and avoids a fixed array size that we might accidentally overflow. It also prevents a leak after finish_command is run, by using the argv_array that run-command manages for us. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- transport-helper.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index fefd34f134a3f3..9f8f3b12643102 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -418,30 +418,24 @@ static int get_exporter(struct transport *transport, { struct helper_data *data = transport->data; struct child_process *helper = get_helper(transport); - int argc = 0, i; - struct strbuf tmp = STRBUF_INIT; + int i; memset(fastexport, 0, sizeof(*fastexport)); /* we need to duplicate helper->in because we want to use it after * fastexport is done with it. */ fastexport->out = dup(helper->in); - fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv)); - fastexport->argv[argc++] = "fast-export"; - fastexport->argv[argc++] = "--use-done-feature"; - fastexport->argv[argc++] = data->signed_tags ? - "--signed-tags=verbatim" : "--signed-tags=warn-strip"; - if (data->export_marks) { - strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks); - fastexport->argv[argc++] = strbuf_detach(&tmp, NULL); - } - if (data->import_marks) { - strbuf_addf(&tmp, "--import-marks=%s", data->import_marks); - fastexport->argv[argc++] = strbuf_detach(&tmp, NULL); - } + argv_array_push(&fastexport->args, "fast-export"); + argv_array_push(&fastexport->args, "--use-done-feature"); + argv_array_push(&fastexport->args, data->signed_tags ? + "--signed-tags=verbatim" : "--signed-tags=warn-strip"); + if (data->export_marks) + argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks); + if (data->import_marks) + argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks); for (i = 0; i < revlist_args->nr; i++) - fastexport->argv[argc++] = revlist_args->items[i].string; + argv_array_push(&fastexport->args, revlist_args->items[i].string); fastexport->git_cmd = 1; return start_command(fastexport); From 173fd1a1a44b89a204eb1289e4ff1f9d733e0cf1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:35:06 -0400 Subject: [PATCH 196/760] get_importer: use run-command's internal argv_array This saves a few lines and lets us avoid having to clean up the memory manually when the command finishes. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- transport-helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index 9f8f3b12643102..d9063d714591ba 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -394,18 +394,16 @@ static int get_importer(struct transport *transport, struct child_process *fasti { struct child_process *helper = get_helper(transport); struct helper_data *data = transport->data; - struct argv_array argv = ARGV_ARRAY_INIT; int cat_blob_fd, code; memset(fastimport, 0, sizeof(*fastimport)); fastimport->in = helper->out; - argv_array_push(&argv, "fast-import"); - argv_array_push(&argv, debug ? "--stats" : "--quiet"); + argv_array_push(&fastimport->args, "fast-import"); + argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet"); if (data->bidi_import) { cat_blob_fd = xdup(helper->in); - argv_array_pushf(&argv, "--cat-blob-fd=%d", cat_blob_fd); + argv_array_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd); } - fastimport->argv = argv.argv; fastimport->git_cmd = 1; code = start_command(fastimport); @@ -476,7 +474,6 @@ static int fetch_with_import(struct transport *transport, if (finish_command(&fastimport)) die("Error while running fast-import"); - argv_array_free_detached(fastimport.argv); /* * The fast-import stream of a remote helper that advertises From ff857e4ee8680af3988aff3383b1158f396a6fb2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:41:03 -0400 Subject: [PATCH 197/760] argv-array: drop "detach" code The argv_array_detach function (and associated free() function) was really only useful for transferring ownership of the memory to a "struct child_process". Now that we have an internal argv_array in that struct, there are no callers left. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/technical/api-argv-array.txt | 8 -------- argv-array.c | 20 -------------------- argv-array.h | 2 -- 3 files changed, 30 deletions(-) diff --git a/Documentation/technical/api-argv-array.txt b/Documentation/technical/api-argv-array.txt index a6b7d83a8eb050..1a797812fb4261 100644 --- a/Documentation/technical/api-argv-array.txt +++ b/Documentation/technical/api-argv-array.txt @@ -53,11 +53,3 @@ Functions `argv_array_clear`:: Free all memory associated with the array and return it to the initial, empty state. - -`argv_array_detach`:: - Detach the argv array from the `struct argv_array`, transferring - ownership of the allocated array and strings. - -`argv_array_free_detached`:: - Free the memory allocated by a `struct argv_array` that was later - detached and is now no longer needed. diff --git a/argv-array.c b/argv-array.c index 9e960d549c158a..256741d2262b23 100644 --- a/argv-array.c +++ b/argv-array.c @@ -68,23 +68,3 @@ void argv_array_clear(struct argv_array *array) } argv_array_init(array); } - -const char **argv_array_detach(struct argv_array *array, int *argc) -{ - const char **argv = - array->argv == empty_argv || array->argc == 0 ? NULL : array->argv; - if (argc) - *argc = array->argc; - argv_array_init(array); - return argv; -} - -void argv_array_free_detached(const char **argv) -{ - if (argv) { - int i; - for (i = 0; argv[i]; i++) - free((char **)argv[i]); - free(argv); - } -} diff --git a/argv-array.h b/argv-array.h index 85ba438ac1e877..c65e6e825a96ef 100644 --- a/argv-array.h +++ b/argv-array.h @@ -19,7 +19,5 @@ LAST_ARG_MUST_BE_NULL void argv_array_pushl(struct argv_array *, ...); void argv_array_pop(struct argv_array *); void argv_array_clear(struct argv_array *); -const char **argv_array_detach(struct argv_array *array, int *argc); -void argv_array_free_detached(const char **argv); #endif /* ARGV_ARRAY_H */ From d6c8a05bd58be82165be54f01c861c0fae28b8c4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 15 May 2014 04:54:06 -0400 Subject: [PATCH 198/760] open_sha1_file: report "most interesting" errno When we try to open a loose object file, we first attempt to open in the local object database, and then try any alternates. This means that the errno value when we return will be from the last place we looked (and due to the way the code is structured, simply ENOENT if we do not have have any alternates). This can cause confusing error messages, as read_sha1_file checks for ENOENT when reporting a missing object. If errno is something else, we report that. If it is ENOENT, but has_loose_object reports that we have it, then we claim the object is corrupted. For example: $ chmod 0 .git/objects/??/* $ git rev-list --all fatal: loose object b2d6fab18b92d49eac46dc3c5a0bcafabda20131 (stored in .git/objects/b2/d6fab18b92d49eac46dc3c5a0bcafabda20131) is corrupt This patch instead keeps track of the "most interesting" errno we receive during our search. We consider ENOENT to be the least interesting of all, and otherwise report the first error found (so problems in the object database take precedence over ones in alternates). Here it is with this patch: $ git rev-list --all fatal: failed to read object b2d6fab18b92d49eac46dc3c5a0bcafabda20131: Permission denied Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- sha1_file.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sha1_file.c b/sha1_file.c index 06c809aeeb3a60..1e1edf4b25d746 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1424,20 +1424,24 @@ static int open_sha1_file(const unsigned char *sha1) int fd; char *name = sha1_file_name(sha1); struct alternate_object_database *alt; + int most_interesting_errno; fd = git_open_noatime(name); if (fd >= 0) return fd; + most_interesting_errno = errno; prepare_alt_odb(); - errno = ENOENT; for (alt = alt_odb_list; alt; alt = alt->next) { name = alt->name; fill_sha1_path(name, sha1); fd = git_open_noatime(alt->base); if (fd >= 0) return fd; + if (most_interesting_errno == ENOENT) + most_interesting_errno = errno; } + errno = most_interesting_errno; return -1; } From f7febbea07cf6d65f85b0cdb6684d2e3666c557e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 8 Feb 2011 00:17:24 -0600 Subject: [PATCH 199/760] git grep -O -i: if the pager is 'less', pass the '-I' option When happens to be the magic string "less", today git grep -O -e helpfully passes +/ to less so you can navigate through the results within a file using the n and shift+n keystrokes. Alas, that doesn't do the right thing for a case-insensitive match, i.e. git grep -i -O -e For that case we should pass --IGNORE-CASE to "less" so that n and shift+n can move between results ignoring case in the pattern. The original patch came from msysgit and used "-i", but that was not due to lack of support for "-I" but it merely overlooked that it ought to work even when the pattern contains capital letters. Signed-off-by: Johannes Schindelin Signed-off-by: Stepan Kasal Helped-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/grep.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/grep.c b/builtin/grep.c index 63f86032d91f00..1892335c060552 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -876,6 +876,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) if (len > 4 && is_dir_sep(pager[len - 5])) pager += len - 4; + if (opt.ignore_case && !strcmp("less", pager)) + string_list_append(&path_list, "-I"); + if (!strcmp("less", pager) || !strcmp("vi", pager)) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "+/%s%s", From 496a69802bc4035d5dc26c8d97144d8ae30e52c4 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Mon, 19 May 2014 19:28:16 +0400 Subject: [PATCH 200/760] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs The expected SHA-1 digests are always available in variables. Use them instead of hardcoding. That was introduced in a742f2a (t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs, 2013-06-26) but unfortunately was not followed in 5e1361c (log: properly handle decorations with chained tags, 2013-12-17) Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 2a6278bb333d28..f9f33aeab98662 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -296,6 +296,10 @@ EOF test_cmp expected actual ' +# save HEAD's SHA-1 digest (with no abbreviations) to use it below +# as far as the next test amends HEAD +old_head1=$(git rev-parse --verify HEAD~0) + test_expect_success 'left/right alignment formatting with stealing' ' git commit --amend -m short --author "long long long " && git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && @@ -310,6 +314,10 @@ EOF test_cmp expected actual ' +# get new digests (with no abbreviations) +head1=$(git rev-parse --verify HEAD~0) && +head2=$(git rev-parse --verify HEAD~1) && + test_expect_success 'log decoration properly follows tag chain' ' git tag -a tag1 -m tag1 && git tag -a tag2 -m tag2 tag1 && @@ -317,9 +325,9 @@ test_expect_success 'log decoration properly follows tag chain' ' git commit --amend -m shorter && git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && cat <expected && -6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2) -9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one) -b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two) +$head1 (tag: refs/tags/tag2) +$head2 (tag: refs/tags/message-one) +$old_head1 (tag: refs/tags/message-two) EOF sort actual >actual1 && test_cmp expected actual1 From 50b54fd72a8776d628365c7760bc922902d29d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 17 May 2014 08:52:22 +0700 Subject: [PATCH 201/760] config: be strict on core.commentChar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't support comment _strings_ (at least not yet). And multi-byte character encoding could also be misinterpreted. The test with two commas is updated because it violates this. It's added with the patch that introduces core.commentChar in eff80a9 (Allow custom "comment char" - 2013-01-16). It's not clear to me _why_ that behavior is wanted. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- config.c | 8 ++++++-- t/t7508-status.sh | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index a30cb5c07db18a..491a9050aebdef 100644 --- a/config.c +++ b/config.c @@ -826,9 +826,13 @@ static int git_default_core_config(const char *var, const char *value) if (!strcmp(var, "core.commentchar")) { const char *comment; int ret = git_config_string(&comment, var, value); - if (!ret) + if (ret) + return ret; + else if (comment[0] && !comment[1]) { comment_line_char = comment[0]; - return ret; + } else + return error("core.commentChar should only be one character"); + return 0; } if (!strcmp(var, "core.askpass")) diff --git a/t/t7508-status.sh b/t/t7508-status.sh index c987b5ed652b97..148ab9ebc2fe24 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1350,8 +1350,7 @@ test_expect_success "status (core.commentchar with submodule summary)" ' test_expect_success "status (core.commentchar with two chars with submodule summary)" ' test_config core.commentchar ";;" && - git -c status.displayCommentPrefix=true status >output && - test_i18ncmp expect output + test_must_fail git -c status.displayCommentPrefix=true status ' test_expect_success "--ignore-submodules=all suppresses submodule summary" ' From 84c9dc2c5a2d34351a06554af32501d4f99990e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 17 May 2014 08:52:23 +0700 Subject: [PATCH 202/760] commit: allow core.commentChar=auto for character auto selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When core.commentChar is "auto", the comment char starts with '#' as in default but if it's already in the prepared message, find another char in a small subset. This should stop surprises because git strips some lines unexpectedly. Note that git is not smart enough to recognize '#' as the comment char in custom templates and convert it if the final comment char is different. It thinks '#' lines in custom templates as part of the commit message. So don't use this with custom templates. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- Documentation/config.txt | 3 +++ builtin/commit.c | 32 ++++++++++++++++++++++++++++++++ cache.h | 1 + config.c | 3 +++ environment.c | 1 + t/t7502-commit.sh | 26 ++++++++++++++++++++++++++ 6 files changed, 66 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 1932e9b9a2be54..9f3ce06c8734d2 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -544,6 +544,9 @@ core.commentchar:: messages consider a line that begins with this character commented, and removes them after the editor returns (default '#'). ++ +If set to "auto", `git-commit` would select a character that is not +the beginning character of any line in existing commit messages. sequence.editor:: Text editor used by `git rebase -i` for editing the rebase instruction file. diff --git a/builtin/commit.c b/builtin/commit.c index 9cfef6c6cca619..515c4c4c0553c0 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -594,6 +594,36 @@ static char *cut_ident_timestamp_part(char *string) return ket; } +static void adjust_comment_line_char(const struct strbuf *sb) +{ + char candidates[] = "#;@!$%^&|:"; + char *candidate; + const char *p; + + comment_line_char = candidates[0]; + if (!memchr(sb->buf, comment_line_char, sb->len)) + return; + + p = sb->buf; + candidate = strchr(candidates, *p); + if (candidate) + *candidate = ' '; + for (p = sb->buf; *p; p++) { + if ((p[0] == '\n' || p[0] == '\r') && p[1]) { + candidate = strchr(candidates, p[1]); + if (candidate) + *candidate = ' '; + } + } + + for (p = candidates; *p == ' '; p++) + ; + if (!*p) + die(_("unable to select a comment character that is not used\n" + "in the current commit message")); + comment_line_char = *p; +} + static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, @@ -748,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) die_errno(_("could not write commit template")); + if (auto_comment_line_char) + adjust_comment_line_char(&sb); strbuf_release(&sb); /* This checks if committer ident is explicitly given */ diff --git a/cache.h b/cache.h index 107ac61b68f15b..646fb810bb38f5 100644 --- a/cache.h +++ b/cache.h @@ -602,6 +602,7 @@ extern int precomposed_unicode; * that is subject to stripspace. */ extern char comment_line_char; +extern int auto_comment_line_char; enum branch_track { BRANCH_TRACK_UNSPECIFIED = -1, diff --git a/config.c b/config.c index 491a9050aebdef..d29c7334198292 100644 --- a/config.c +++ b/config.c @@ -828,8 +828,11 @@ static int git_default_core_config(const char *var, const char *value) int ret = git_config_string(&comment, var, value); if (ret) return ret; + else if (!strcasecmp(comment, "auto")) + auto_comment_line_char = 1; else if (comment[0] && !comment[1]) { comment_line_char = comment[0]; + auto_comment_line_char = 0; } else return error("core.commentChar should only be one character"); return 0; diff --git a/environment.c b/environment.c index 5c4815dbe132fc..f2de1ee9ada0c1 100644 --- a/environment.c +++ b/environment.c @@ -69,6 +69,7 @@ unsigned long pack_size_limit_cfg; * that is subject to stripspace. */ char comment_line_char = '#'; +int auto_comment_line_char; /* Parallel index stat data preload? */ int core_preload_index = 0; diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 9a3f3a1b4151eb..30e46884f29722 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -563,4 +563,30 @@ test_expect_success 'commit --status with custom comment character' ' test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG ' +test_expect_success 'switch core.commentchar' ' + test_commit "#foo" foo && + GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend && + test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG +' + +test_expect_success 'switch core.commentchar but out of options' ' + cat >text <<\EOF && +# 1 +; 2 +@ 3 +! 4 +$ 5 +% 6 +^ 7 +& 8 +| 9 +: 10 +EOF + git commit --amend -F text && + ( + test_set_editor .git/FAKE_EDITOR && + test_must_fail git -c core.commentChar=auto commit --amend + ) +' + test_done From f22166b5fee7dc3deaf44dda31d1b5d7ac1fdfd8 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 May 2014 14:16:34 +0200 Subject: [PATCH 203/760] replace: make sure --edit results in a different object It's a bad idea to create a replace ref for an object that points to the original object itself. That's why we have to check if the result from editing the original object is a different object and error out if it isn't. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/replace.c b/builtin/replace.c index 3da1bae0a60942..07518040395139 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -275,6 +275,9 @@ static int edit_and_replace(const char *object_ref, int force) free(tmpfile); + if (!hashcmp(old, new)) + return error("new object is the same as the old one: '%s'", sha1_to_hex(old)); + return replace_object_sha1(object_ref, old, "replacement", new, force); } From b6e38840921ac4a0fe07e10e632f66736745da10 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 May 2014 14:16:35 +0200 Subject: [PATCH 204/760] replace: refactor checking ref validity This will be useful in a following commit when we will want to check if the ref already exists before we let the user edit an object. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 07518040395139..3d6edaf7c7787c 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -124,6 +124,25 @@ static int delete_replace_ref(const char *name, const char *ref, return 0; } +static void check_ref_valid(unsigned char object[20], + unsigned char prev[20], + char *ref, + int ref_size, + int force) +{ + if (snprintf(ref, ref_size, + "refs/replace/%s", + sha1_to_hex(object)) > ref_size - 1) + die("replace ref name too long: %.*s...", 50, ref); + if (check_refname_format(ref, 0)) + die("'%s' is not a valid ref name.", ref); + + if (read_ref(ref, prev)) + hashclr(prev); + else if (!force) + die("replace ref '%s' already exists", ref); +} + static int replace_object_sha1(const char *object_ref, unsigned char object[20], const char *replace_ref, @@ -135,13 +154,6 @@ static int replace_object_sha1(const char *object_ref, char ref[PATH_MAX]; struct ref_lock *lock; - if (snprintf(ref, sizeof(ref), - "refs/replace/%s", - sha1_to_hex(object)) > sizeof(ref) - 1) - die("replace ref name too long: %.*s...", 50, ref); - if (check_refname_format(ref, 0)) - die("'%s' is not a valid ref name.", ref); - obj_type = sha1_object_info(object, NULL); repl_type = sha1_object_info(repl, NULL); if (!force && obj_type != repl_type) @@ -151,10 +163,7 @@ static int replace_object_sha1(const char *object_ref, object_ref, typename(obj_type), replace_ref, typename(repl_type)); - if (read_ref(ref, prev)) - hashclr(prev); - else if (!force) - die("replace ref '%s' already exists", ref); + check_ref_valid(object, prev, ref, sizeof(ref), force); lock = lock_any_ref_for_update(ref, prev, 0, NULL); if (!lock) From 24790835738dc098fa6becedc44aac0341b7d5af Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 May 2014 14:16:36 +0200 Subject: [PATCH 205/760] replace: die early if replace ref already exists If a replace ref already exists for an object, it is much better for the user if we error out before we let the user edit the object, rather than after. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/replace.c b/builtin/replace.c index 3d6edaf7c7787c..4ee3d929fafe64 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -268,7 +268,8 @@ static int edit_and_replace(const char *object_ref, int force) { char *tmpfile = git_pathdup("REPLACE_EDITOBJ"); enum object_type type; - unsigned char old[20], new[20]; + unsigned char old[20], new[20], prev[20]; + char ref[PATH_MAX]; if (get_sha1(object_ref, old) < 0) die("Not a valid object name: '%s'", object_ref); @@ -277,6 +278,8 @@ static int edit_and_replace(const char *object_ref, int force) if (type < 0) die("unable to get object type for %s", sha1_to_hex(old)); + check_ref_valid(old, prev, ref, sizeof(ref), force); + export_object(old, tmpfile); if (launch_editor(tmpfile, NULL, NULL) < 0) die("editing object file failed"); From 85f98fc037ae026596c5d3b5d71fbfaa9144f210 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 May 2014 14:16:37 +0200 Subject: [PATCH 206/760] replace: add tests for --edit Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- t/t6050-replace.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 719a11673bfc93..68b3cb26d90c5b 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -318,6 +318,33 @@ test_expect_success 'test --format long' ' test_cmp expected actual ' +test_expect_success 'setup a fake editor' ' + write_script fakeeditor <<-\EOF + sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new" + mv "$1.new" "$1" + EOF +' + +test_expect_success '--edit with and without already replaced object' ' + test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" && + git replace -d "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" +' + +test_expect_success '--edit and change nothing or command failed' ' + git replace -d "$PARA3" && + test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" && + test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" +' + test_expect_success 'replace ref cleanup' ' test -n "$(git replace)" && git replace -d $(git replace) && From ab77c309b633ab3afc16e91cbff307c39599d048 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 May 2014 14:16:38 +0200 Subject: [PATCH 207/760] replace: add --edit to usage string Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin/replace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/replace.c b/builtin/replace.c index 4ee3d929fafe64..1bb491d3c4f282 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -16,6 +16,7 @@ static const char * const git_replace_usage[] = { N_("git replace [-f] "), + N_("git replace [-f] --edit "), N_("git replace -d ..."), N_("git replace [--format=] [-l []]"), NULL From 4e4b125c239a78f3a8fe82e47d1f89fef510980c Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 May 2014 14:16:39 +0200 Subject: [PATCH 208/760] Documentation: replace: describe new --edit option Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-replace.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt index 0a02f70657776b..61461b9f3399bd 100644 --- a/Documentation/git-replace.txt +++ b/Documentation/git-replace.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] 'git replace' [-f] +'git replace' [-f] --edit 'git replace' -d ... 'git replace' [--format=] [-l []] @@ -63,6 +64,15 @@ OPTIONS --delete:: Delete existing replace refs for the given objects. +--edit :: + Edit an object's content interactively. The existing content + for is pretty-printed into a temporary file, an + editor is launched on the file, and the result is parsed to + create a new object of the same type as . A + replacement ref is then created to replace with the + newly created object. See linkgit:git-var[1] for details about + how the editor will be chosen. + -l :: --list :: List replace refs for objects that match the given pattern (or @@ -92,7 +102,9 @@ CREATING REPLACEMENT OBJECTS linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and linkgit:git-rebase[1], among other git commands, can be used to create -replacement objects from existing objects. +replacement objects from existing objects. The `--edit` option can +also be used with 'git replace' to create a replacement object by +editing an existing object. If you want to replace many blobs, trees or commits that are part of a string of commits, you may just want to create a replacement string of @@ -117,6 +129,8 @@ linkgit:git-filter-branch[1] linkgit:git-rebase[1] linkgit:git-tag[1] linkgit:git-branch[1] +linkgit:git-commit[1] +linkgit:git-var[1] linkgit:git[1] GIT From bd46cfae8224ec2240e58302e8ddd16b701cbe6a Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Sun, 18 May 2014 23:28:39 +0300 Subject: [PATCH 209/760] rebase --keep-empty -i: add test There's some special code in rebase -i to deal with --keep-empty. Add test for this combination. Signed-off-by: Michael S. Tsirkin Acked-by: Neil Horman Signed-off-by: Junio C Hamano --- t/t3404-rebase-interactive.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 50e22b1cadff42..9848524aeea034 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -67,6 +67,14 @@ test_expect_success 'setup' ' SHELL= export SHELL +test_expect_success 'rebase --keep-empty' ' + git checkout -b emptybranch master && + git commit --allow-empty -m "empty" && + git rebase --keep-empty -i HEAD~2 && + git log --oneline >actual && + test_line_count = 6 actual +' + test_expect_success 'rebase -i with the exec command' ' git checkout master && ( From e4244eb3957d478ca05b42d8b56aadb9ab2bc7ae Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Mon, 19 May 2014 18:05:20 -0400 Subject: [PATCH 210/760] rebase -i: handle "Nothing to do" case with autostash When a user invokes $ git rebase -i @~3 with dirty files and rebase.autostash turned on, and exits the $EDITOR with an empty buffer, the autostash fails to apply. Although the primary focus of rr/rebase-autostash was to get the git-rebase--backend.sh scripts to return control to git-rebase.sh, it missed this case in git-rebase--interactive.sh. Since this case is unlike the other cases which return control for housekeeping, assign it a special return status and handle that return value explicitly in git-rebase.sh. Reported-by: Karen Etheridge Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 4 ++-- git-rebase.sh | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index f953d8d22499b9..85f0e93eee1400 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -970,14 +970,14 @@ fi has_action "$todo" || - die_abort "Nothing to do" + return 2 cp "$todo" "$todo".backup git_sequence_editor "$todo" || die_abort "Could not execute editor" has_action "$todo" || - die_abort "Nothing to do" + return 2 test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks diff --git a/git-rebase.sh b/git-rebase.sh index a28209daba69d0..9eb276ba203ae5 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -147,7 +147,7 @@ move_to_original_branch () { esac } -finish_rebase () { +apply_autostash () { if test -f "$state_dir/autostash" then stash_sha1=$(cat "$state_dir/autostash") @@ -166,6 +166,10 @@ You can run "git stash pop" or "git stash drop" at any time. ' fi fi +} + +finish_rebase () { + apply_autostash && git gc --auto && rm -rf "$state_dir" } @@ -181,6 +185,11 @@ run_specific_rebase () { if test $ret -eq 0 then finish_rebase + elif test $ret -eq 2 # special exit status for rebase -i + then + apply_autostash && + rm -rf "$state_dir" && + die "Nothing to do" fi exit $ret } From dd63f169d9381a77db469325688a2bef1a79a9e1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 20 May 2014 02:49:20 -0400 Subject: [PATCH 211/760] move "--follow needs one pathspec" rule to diff_setup_done Because of the way "--follow" is implemented, we must have exactly one pathspec. "git log" enforces this restriction, but other users of the revision traversal code do not. For example, "git format-patch --follow" will segfault during try_to_follow_renames, as we have no pathspecs at all. We can push this check down into diff_setup_done, which is probably a better place anyway. It is the diff code that introduces this restriction, so other parts of the code should not need to care themselves. Reported-by: "Michael S. Tsirkin" Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/log.c | 8 ++------ diff.c | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index b708517a350651..00a4ce602cc3f6 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -158,13 +158,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, if (rev->show_notes) init_display_notes(&rev->notes_opt); - if (rev->diffopt.pickaxe || rev->diffopt.filter) + if (rev->diffopt.pickaxe || rev->diffopt.filter || + DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) rev->always_show_header = 0; - if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) { - rev->always_show_header = 0; - if (rev->diffopt.pathspec.nr != 1) - usage("git logs can only follow renames on one pathname at a time"); - } if (source) rev->show_source = 1; diff --git a/diff.c b/diff.c index e34bf971207f77..a99b925ac74bc4 100644 --- a/diff.c +++ b/diff.c @@ -3317,6 +3317,9 @@ void diff_setup_done(struct diff_options *options) options->output_format = DIFF_FORMAT_NO_OUTPUT; DIFF_OPT_SET(options, EXIT_WITH_STATUS); } + + if (DIFF_OPT_TST(options, FOLLOW_RENAMES) && options->pathspec.nr != 1) + die(_("--follow requires exactly one pathspec")); } static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val) From 897f964c0dce8e7cc2cc53bb19b83cadce106773 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 20 May 2014 11:12:02 -0700 Subject: [PATCH 212/760] CodingGuidelines: avoid "test -a/-o " The construct is error-prone; "test" being built-in in most modern shells, the reason to avoid "test && test " spawning one extra process by using a single "test -a " no longer exists. Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 3d08671ad3fee3..4d90c77c7bd643 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -151,6 +151,19 @@ For shell scripts specifically (not exhaustive): interface translatable. See "Marking strings for translation" in po/README. + - We do not write our "test" command with "-a" and "-o" and use "&&" + or "||" to concatenate multiple "test" commands instead, because + the use of "-a/-o" is often error-prone. E.g. + + test -n "$x" -a "$a" = "$b" + + is buggy and breaks when $x is "=", but + + test -n "$x" && test "$a" = "$b" + + does not have such a problem. + + For C programs: - We use tabs to indent, and interpret tabs as taking up to From ddb5432d2390e1957e473618009ba3d2fbbf29a7 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 20 May 2014 09:49:31 +0200 Subject: [PATCH 213/760] rebase -i: test "Nothing to do" case with autostash Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t3420-rebase-autostash.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh index 90eb26493cd309..d783f03d3fc581 100755 --- a/t/t3420-rebase-autostash.sh +++ b/t/t3420-rebase-autostash.sh @@ -167,4 +167,19 @@ testrebase "" .git/rebase-apply testrebase " --merge" .git/rebase-merge testrebase " --interactive" .git/rebase-merge +test_expect_success 'abort rebase -i with --autostash' ' + test_when_finished "git reset --hard" && + echo uncommited-content >file0 && + ( + write_script abort-editor.sh <<-\EOF && + echo >"$1" + EOF + test_set_editor "$(pwd)/abort-editor.sh" && + test_must_fail git rebase -i --autostash HEAD^ && + rm -f abort-editor.sh + ) && + echo uncommited-content >expected && + test_cmp expected file0 +' + test_done From ee3efaf66c7599340a5deb030ee6969b6d7d39aa Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 21 May 2014 17:20:04 +0400 Subject: [PATCH 214/760] t4041, t4205, t6006, t7102: don't hardcode tested encoding value The tested encoding is always available in a variable. Use it instead of hardcoding. Also, to be in line with other tests use ISO8859-1 (uppercase) rather then iso8859-1. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t4041-diff-submodule-option.sh | 7 +++++-- t/t4205-log-pretty-formats.sh | 11 ++++++---- t/t6006-rev-list-format.sh | 35 +++++++++++++++++--------------- t/t7102-reset.sh | 13 +++++++----- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 1751c8330709c5..463d63bde0f72b 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -11,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff. . ./test-lib.sh +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + # String "added" in German (translated with Google Translate), encoded in UTF-8, # used in sample commit log messages in add_file() function below. added=$(printf "hinzugef\303\274gt") @@ -23,8 +26,8 @@ add_file () { echo "$name" >"$name" && git add "$name" && test_tick && - msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) && - git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591" + msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) && + git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591" done >/dev/null && git rev-parse --short --verify HEAD ) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index f9f33aeab98662..f5ea3f89324cbd 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -7,6 +7,9 @@ test_description='Test pretty formats' . ./test-lib.sh +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + sample_utf8_part=$(printf "f\303\244ng") commit_msg () { @@ -27,8 +30,8 @@ test_expect_success 'set up basic repos' ' >bar && git add foo && test_tick && - git config i18n.commitEncoding iso8859-1 && - git commit -m "$(commit_msg iso8859-1)" && + git config i18n.commitEncoding $test_encoding && + git commit -m "$(commit_msg $test_encoding)" && git add bar && test_tick && git commit -m "add bar" && @@ -56,8 +59,8 @@ test_expect_success 'alias user-defined format' ' test_cmp expected actual ' -test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' ' - git config i18n.logOutputEncoding iso8859-1 && +test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' + git config i18n.logOutputEncoding $test_encoding && git log --oneline >expected-s && git log --pretty="tformat:%h %s" >actual-s && git config --unset i18n.logOutputEncoding && diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 9d9d9de08e1926..692b0e5d72169a 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -9,19 +9,22 @@ test_description='git rev-list --pretty=format test' . "$TEST_DIRECTORY"/lib-terminal.sh test_tick +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + # String "added" in German # (translated with Google Translate), # encoded in UTF-8, used as a commit log message below. added=$(printf "added (hinzugef\303\274gt) foo") -added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1) +added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) # same but "changed" changed=$(printf "changed (ge\303\244ndert) foo") -changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1) +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) test_expect_success 'setup' ' : >foo && git add foo && - git config i18n.commitEncoding iso8859-1 && + git config i18n.commitEncoding $test_encoding && git commit -m "$added_iso88591" && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && @@ -124,9 +127,9 @@ EOF test_format encoding %e < commit-msg < commit-msg <foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && head3_short=$(git rev-parse --short $head3) @@ -220,11 +223,11 @@ test_expect_success 'setup complex body' ' test_format complex-encoding %e <expected.utf-8 && commit $head3 This commit message is much longer than the others, - and it will be encoded in iso8859-1. We should therefore - include an iso8859 character: ¡bueno! + and it will be encoded in $test_encoding. We should therefore + include an ISO8859 character: ¡bueno! commit $head2 commit $head1 EOF - iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1 + iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1 ' -test_format complex-body %b first && @@ -41,7 +44,7 @@ test_expect_success 'creating initial files and commits' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && + git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" && head5=$(git rev-parse --verify HEAD) ' # git log --pretty=oneline # to see those SHA1 involved @@ -64,10 +67,10 @@ test_expect_success 'reset --hard message' ' test_cmp .expected .actual ' -test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' ' +test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' hex=$(git log -1 --format="%h") && - git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected && + git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && test_cmp .expected .actual ' @@ -331,7 +334,7 @@ test_expect_success 'redoing the last two commits should succeed' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && + git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" && check_changes $head5 ' From c82134a9f39427139a26cd67b7c2fd13b2e8c357 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 21 May 2014 17:20:05 +0400 Subject: [PATCH 215/760] t4205 (log-pretty-format): use `tformat` rather than `format` Use `tformat` to avoid using of `echo` to complete end of line. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 52 +++++++++-------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index f5ea3f89324cbd..c03a65e15132d9 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -144,9 +144,7 @@ test_expect_success 'setup more commits' ' ' test_expect_success 'left alignment formatting' ' - git log --pretty="format:%<(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(40)%s" >actual && qz_to_tab_space <expected && message two Z message one Z @@ -157,9 +155,7 @@ EOF ' test_expect_success 'left alignment formatting at the nth column' ' - git log --pretty="format:%h %<|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %<|(40)%s" >actual && qz_to_tab_space <expected && $head1 message two Z $head2 message one Z @@ -170,9 +166,7 @@ EOF ' test_expect_success 'left alignment formatting with no padding' ' - git log --pretty="format:%<(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(1)%s" >actual && cat <expected && message two message one @@ -183,9 +177,7 @@ EOF ' test_expect_success 'left alignment formatting with trunc' ' - git log --pretty="format:%<(10,trunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,trunc)%s" >actual && qz_to_tab_space <expected && message .. message .. @@ -196,9 +188,7 @@ EOF ' test_expect_success 'left alignment formatting with ltrunc' ' - git log --pretty="format:%<(10,ltrunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,ltrunc)%s" >actual && qz_to_tab_space <expected && ..sage two ..sage one @@ -209,9 +199,7 @@ EOF ' test_expect_success 'left alignment formatting with mtrunc' ' - git log --pretty="format:%<(10,mtrunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,mtrunc)%s" >actual && qz_to_tab_space <expected && mess.. two mess.. one @@ -222,9 +210,7 @@ EOF ' test_expect_success 'right alignment formatting' ' - git log --pretty="format:%>(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%>(40)%s" >actual && qz_to_tab_space <expected && Z message two Z message one @@ -235,9 +221,7 @@ EOF ' test_expect_success 'right alignment formatting at the nth column' ' - git log --pretty="format:%h %>|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %>|(40)%s" >actual && qz_to_tab_space <expected && $head1 message two $head2 message one @@ -248,9 +232,7 @@ EOF ' test_expect_success 'right alignment formatting with no padding' ' - git log --pretty="format:%>(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%>(1)%s" >actual && cat <expected && message two message one @@ -261,9 +243,7 @@ EOF ' test_expect_success 'center alignment formatting' ' - git log --pretty="format:%><(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%><(40)%s" >actual && qz_to_tab_space <expected && Z message two Z Z message one Z @@ -274,9 +254,7 @@ EOF ' test_expect_success 'center alignment formatting at the nth column' ' - git log --pretty="format:%h %><|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %><|(40)%s" >actual && qz_to_tab_space <expected && $head1 message two Z $head2 message one Z @@ -287,9 +265,7 @@ EOF ' test_expect_success 'center alignment formatting with no padding' ' - git log --pretty="format:%><(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%><(1)%s" >actual && cat <expected && message two message one @@ -305,9 +281,7 @@ old_head1=$(git rev-parse --verify HEAD~0) test_expect_success 'left/right alignment formatting with stealing' ' git commit --amend -m short --author "long long long " && - git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && cat <expected && short long long long message .. A U Thor From d928d81051fc8475c7845526b255cb8e80b39f12 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 21 May 2014 17:20:06 +0400 Subject: [PATCH 216/760] t4205, t6006: add tests that fail with i18n.logOutputEncoding set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8. There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8. Add failing tests for that which will be fixed in the next patch. Signed-off-by: Alexey Shumkin Helped-by: Nguyễn Thái Ngọc Duy Helped-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 140 ++++++++++++++++++++++++++++++++++ t/t6006-rev-list-format.sh | 75 +++++++++++++++++- 2 files changed, 213 insertions(+), 2 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index c03a65e15132d9..74babced70df78 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -154,6 +154,17 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && + qz_to_tab_space <expected && +message two Z +message one Z +add bar Z +$(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting at the nth column' ' git log --pretty="tformat:%h %<|(40)%s" >actual && qz_to_tab_space <expected && @@ -165,6 +176,17 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && + qz_to_tab_space <expected && +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 $(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with no padding' ' git log --pretty="tformat:%<(1)%s" >actual && cat <expected && @@ -176,6 +198,17 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && + cat <expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with trunc' ' git log --pretty="tformat:%<(10,trunc)%s" >actual && qz_to_tab_space <expected && @@ -187,6 +220,17 @@ EOF test_cmp expected actual ' +test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && + qz_to_tab_space <expected && +message .. +message .. +add bar Z +initial... +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with ltrunc' ' git log --pretty="tformat:%<(10,ltrunc)%s" >actual && qz_to_tab_space <expected && @@ -198,6 +242,17 @@ EOF test_cmp expected actual ' +test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && + qz_to_tab_space <expected && +..sage two +..sage one +add bar Z +..${sample_utf8_part}lich +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with mtrunc' ' git log --pretty="tformat:%<(10,mtrunc)%s" >actual && qz_to_tab_space <expected && @@ -209,6 +264,17 @@ EOF test_cmp expected actual ' +test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && + qz_to_tab_space <expected && +mess.. two +mess.. one +add bar Z +init..lich +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting' ' git log --pretty="tformat:%>(40)%s" >actual && qz_to_tab_space <expected && @@ -220,6 +286,17 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && + qz_to_tab_space <expected && +Z message two +Z message one +Z add bar +Z $(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting at the nth column' ' git log --pretty="tformat:%h %>|(40)%s" >actual && qz_to_tab_space <expected && @@ -231,6 +308,17 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && + qz_to_tab_space <expected && +$head1 message two +$head2 message one +$head3 add bar +$head4 $(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting with no padding' ' git log --pretty="tformat:%>(1)%s" >actual && cat <expected && @@ -242,6 +330,17 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && + cat <expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'center alignment formatting' ' git log --pretty="tformat:%><(40)%s" >actual && qz_to_tab_space <expected && @@ -253,6 +352,16 @@ EOF test_cmp expected actual ' +test_expect_success 'center alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && + qz_to_tab_space <expected && +Z message two Z +Z message one Z +Z add bar Z +Z $(commit_msg) Z +EOF + test_cmp expected actual +' test_expect_success 'center alignment formatting at the nth column' ' git log --pretty="tformat:%h %><|(40)%s" >actual && qz_to_tab_space <expected && @@ -264,6 +373,17 @@ EOF test_cmp expected actual ' +test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && + qz_to_tab_space <expected && +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 $(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'center alignment formatting with no padding' ' git log --pretty="tformat:%><(1)%s" >actual && cat <expected && @@ -278,6 +398,16 @@ EOF # save HEAD's SHA-1 digest (with no abbreviations) to use it below # as far as the next test amends HEAD old_head1=$(git rev-parse --verify HEAD~0) +test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && + cat <expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' test_expect_success 'left/right alignment formatting with stealing' ' git commit --amend -m short --author "long long long " && @@ -290,6 +420,16 @@ initial... A U Thor EOF test_cmp expected actual ' +test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && + cat <expected && +short long long long +message .. A U Thor +add bar A U Thor +initial... A U Thor +EOF + test_cmp expected actual +' # get new digests (with no abbreviations) head1=$(git rev-parse --verify HEAD~0) && diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 692b0e5d72169a..680b9601525e1b 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -15,12 +15,22 @@ test_encoding="ISO8859-1" # String "added" in German # (translated with Google Translate), # encoded in UTF-8, used as a commit log message below. -added=$(printf "added (hinzugef\303\274gt) foo") +added_utf8_part=$(printf "\303\274") +added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) +added=$(printf "added (hinzugef${added_utf8_part}gt) foo") added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) # same but "changed" -changed=$(printf "changed (ge\303\244ndert) foo") +changed_utf8_part=$(printf "\303\244") +changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) +changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) +# Count of char to truncate +# Number is chosen so, that non-ACSII characters +# (see $added_utf8_part and $changed_utf8_part) +# fall into truncated parts of appropriate words both from left and right +truncate_count=20 + test_expect_success 'setup' ' : >foo && git add foo && @@ -139,6 +149,13 @@ commit $head1 $added EOF +test_format subject-truncated "%<($truncate_count,trunc)%s" <expected.utf-8 && commit $head3 @@ -267,6 +311,33 @@ commit $head1 $added EOF +test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" < Date: Wed, 21 May 2014 17:20:07 +0400 Subject: [PATCH 217/760] pretty.c: format string with truncate respects logOutputEncoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8. In 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19) 'format_commit_item' function assumes commit message to be in UTF-8. And that was so until ecaee80 (pretty: --format output should honor logOutputEncoding, 2013-06-26) where conversion to logOutputEncoding was added before calling 'format_commit_message'. Correct this by converting a commit message to UTF-8 first (as it assumed in 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19)). Only after that convert a commit message to an actual logOutputEncoding. Signed-off-by: Alexey Shumkin Reviewed-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- pretty.c | 7 ++++++- t/t4205-log-pretty-formats.sh | 8 ++++---- t/t6006-rev-list-format.sh | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pretty.c b/pretty.c index 3c43db558aee43..c9cf67ea7c8501 100644 --- a/pretty.c +++ b/pretty.c @@ -1506,13 +1506,18 @@ void format_commit_message(const struct commit *commit, context.commit = commit; context.pretty_ctx = pretty_ctx; context.wrap_start = sb->len; + /* + * convert a commit message to UTF-8 first + * as far as 'format_commit_item' assumes it in UTF-8 + */ context.message = logmsg_reencode(commit, &context.commit_encoding, - output_enc); + utf8); strbuf_expand(sb, format, format_commit_item, &context); rewrap_message_tail(sb, &context, 0, 0, 0); + /* then convert a commit message to an actual output encoding */ if (output_enc) { if (same_encoding(utf8, output_enc)) output_enc = NULL; diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 74babced70df78..c84ec9ae6139be 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -220,7 +220,7 @@ EOF test_cmp expected actual ' -test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' ' +test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' ' git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && qz_to_tab_space <expected && message .. @@ -242,7 +242,7 @@ EOF test_cmp expected actual ' -test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' +test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && qz_to_tab_space <expected && ..sage two @@ -264,7 +264,7 @@ EOF test_cmp expected actual ' -test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' +test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && qz_to_tab_space <expected && mess.. two @@ -420,7 +420,7 @@ initial... A U Thor EOF test_cmp expected actual ' -test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' +test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && cat <expected && short long long long diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 680b9601525e1b..c277db64f75ac9 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -256,7 +256,7 @@ commit $head1 $added_iso88591 EOF -test_format complex-subject-trunc "%<($truncate_count,trunc)%s" failure < Date: Wed, 21 May 2014 14:52:26 -0400 Subject: [PATCH 218/760] Documentation: use "command-line" when used as a compound adjective, and fix other minor grammatical issues Signed-off-by: Jason St. John Signed-off-by: Junio C Hamano --- Documentation/config.txt | 10 +++++----- Documentation/diff-config.txt | 2 +- Documentation/git-bisect.txt | 2 +- Documentation/git-config.txt | 2 +- Documentation/git-daemon.txt | 6 +++--- Documentation/git-fast-import.txt | 10 +++++----- Documentation/git-help.txt | 12 ++++++------ Documentation/git-ls-files.txt | 6 +++--- Documentation/git-read-tree.txt | 2 +- Documentation/git-send-email.txt | 6 +++--- Documentation/git-svn.txt | 4 ++-- Documentation/git-web--browse.txt | 4 ++-- Documentation/git.txt | 8 ++++---- Documentation/gitcli.txt | 8 ++++---- Documentation/gitk.txt | 2 +- Documentation/gitweb.conf.txt | 2 +- Documentation/howto/setup-git-server-over-http.txt | 2 +- Documentation/technical/http-protocol.txt | 2 +- Documentation/user-manual.txt | 4 ++-- 19 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 1932e9b9a2be54..553b3006c5f1b1 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -381,7 +381,7 @@ false), while all other repositories are assumed to be bare (bare core.worktree:: Set the path to the root of the working tree. This can be overridden by the GIT_WORK_TREE environment - variable and the '--work-tree' command line option. + variable and the '--work-tree' command-line option. The value can be an absolute path or relative to the path to the .git directory, which is either specified by --git-dir or GIT_DIR, or automatically discovered. @@ -523,7 +523,7 @@ core.askpass:: environment variable. If not set, fall back to the value of the 'SSH_ASKPASS' environment variable or, failing that, a simple password prompt. The external program shall be given a suitable prompt as - command line argument and write the password on its STDOUT. + command-line argument and write the password on its STDOUT. core.attributesfile:: In addition to '.gitattributes' (per-directory) and @@ -1324,7 +1324,7 @@ grep.extendedRegexp:: gpg.program:: Use this custom program instead of "gpg" found on $PATH when making or verifying a PGP signature. The program must support the - same command line interface as GPG, namely, to verify a detached + same command-line interface as GPG, namely, to verify a detached signature, "gpg --verify $file - <$signature" is run, and the program is expected to signal a good signature by exiting with code 0, and to generate an ascii-armored detached signature, the @@ -2295,7 +2295,7 @@ status.submodulesummary:: submodules when `diff.ignoreSubmodules` is set to 'all' or only for those submodules where `submodule..ignore=all`. To also view the summary for ignored submodules you can either use - the --ignore-submodules=dirty command line option or the 'git + the --ignore-submodules=dirty command-line option or the 'git submodule summary' command, which shows a similar output but does not honor these settings. @@ -2317,7 +2317,7 @@ submodule..branch:: submodule..fetchRecurseSubmodules:: This option can be used to control recursive fetching of this submodule. It can be overridden by using the --[no-]recurse-submodules - command line option to "git fetch" and "git pull". + command-line option to "git fetch" and "git pull". This setting will override that from in the linkgit:gitmodules[5] file. diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt index f07b4513ed7697..b0017795208d97 100644 --- a/Documentation/diff-config.txt +++ b/Documentation/diff-config.txt @@ -76,7 +76,7 @@ diff.ignoreSubmodules:: this setting when reporting uncommitted changes. Setting it to 'all' disables the submodule summary normally shown by 'git commit' and 'git status' when 'status.submodulesummary' is set unless it is - overridden by using the --ignore-submodules command line option. + overridden by using the --ignore-submodules command-line option. The 'git submodule' commands are not affected by this setting. diff.mnemonicprefix:: diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt index f986c5cb3a0998..4cb52a7302077e 100644 --- a/Documentation/git-bisect.txt +++ b/Documentation/git-bisect.txt @@ -117,7 +117,7 @@ $ git bisect visualize `view` may also be used as a synonym for `visualize`. If the 'DISPLAY' environment variable is not set, 'git log' is used -instead. You can also give command line options such as `-p` and +instead. You can also give command-line options such as `-p` and `--stat`. ------------ diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index e9917b89a91b36..9dfa1a5ce265ea 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -256,7 +256,7 @@ All writing options will per default write to the repository specific configuration file. Note that this also affects options like '--replace-all' and '--unset'. *'git config' will only ever change one file at a time*. -You can override these rules either by command line options or by environment +You can override these rules either by command-line options or by environment variables. The '--global' and the '--system' options will limit the file used to the global or system-wide file respectively. The GIT_CONFIG environment variable has a similar effect, but you can specify any filename you want. diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt index 223f7315236be8..a69b3616ec3bdc 100644 --- a/Documentation/git-daemon.txt +++ b/Documentation/git-daemon.txt @@ -169,7 +169,7 @@ Git configuration files in that directory are readable by ``. --forbid-override=:: Allow/forbid overriding the site-wide default with per repository configuration. By default, all the services - are overridable. + may be overridden. --[no-]informative-errors:: When informative errors are turned on, git-daemon will report @@ -184,7 +184,7 @@ Git configuration files in that directory are readable by ``. Every time a client connects, first run an external command specified by the with service name (e.g. "upload-pack"), path to the repository, hostname (%H), canonical hostname - (%CH), ip address (%IP), and tcp port (%P) as its command line + (%CH), IP address (%IP), and TCP port (%P) as its command-line arguments. The external command can decide to decline the service by exiting with a non-zero status (or to allow it by exiting with a zero status). It can also look at the $REMOTE_ADDR @@ -204,7 +204,7 @@ SERVICES -------- These services can be globally enabled/disabled using the -command line options of this command. If a finer-grained +command-line options of this command. If finer-grained control is desired (e.g. to allow 'git archive' to be run against only in a few selected repositories the daemon serves), the per-repository configuration file can be used to enable or diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index fd22a9a0c13123..3ffa2fa2c8b38d 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -231,7 +231,7 @@ Date Formats ~~~~~~~~~~~~ The following date formats are supported. A frontend should select the format it will use for this import by passing the format name -in the \--date-format= command line option. +in the \--date-format= command-line option. `raw`:: This is the Git native format and is `