@matheusbsbs / matheus-bagliano / commits / 7a31cc0f96
Fork 0

config: Fix --unset for continuation lines

find_beginning_of_line didn't take into account that the previous line might have ended with \ in which case it shouldn't stop but continue its search. Signed-off-by: Frank Lichtenheld <frank@lichtenheld.de> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Frank Lichtenheld committed Feb 11, 2008 at 01:23 UTC 7a31cc0f96681d6cba54b38bb87daa2440bef448
2 files changed +24
config.c
+5
@@ -701,12 +701,17 @@ static ssize_t find_beginning_of_line(const char* contents, size_t size,
701 size_t equal_offset = size, bracket_offset = size;
702 ssize_t offset;
703
704 +contline:
705 for (offset = offset_-2; offset > 0
706 && contents[offset] != '\n'; offset--)
707 switch (contents[offset]) {
708 case '=': equal_offset = offset; break;
709 case ']': bracket_offset = offset; break;
710 }
711 + if (offset > 0 && contents[offset-1] == '\\') {
712 + offset_ = offset;
713 + goto contline;
714 + }
715 if (bracket_offset < equal_offset) {
716 *found_bracket = 1;
717 offset = bracket_offset+1;
t/t1300-repo-config.sh
+19
@@ -71,6 +71,25 @@ EOF
71
72 test_expect_success 'non-match result' 'cmp .git/config expect'
73
74 +cat > .git/config <<\EOF
75 +[alpha]
76 +bar = foo
77 +[beta]
78 +baz = multiple \
79 +lines
80 +EOF
81 +
82 +test_expect_success 'unset with cont. lines' \
83 + 'git config --unset beta.baz'
84 +
85 +cat > expect <<\EOF
86 +[alpha]
87 +bar = foo
88 +[beta]
89 +EOF
90 +
91 +test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
92 +
93 cat > .git/config << EOF
94 [beta] ; silly comment # another comment
95 noIndent= sillyValue ; 'nother silly comment