Show More
@@ -2654,19 +2654,28 b' def diffstatdata(lines):' | |||||
2654 | if filename: |
|
2654 | if filename: | |
2655 | results.append((filename, adds, removes, isbinary)) |
|
2655 | results.append((filename, adds, removes, isbinary)) | |
2656 |
|
2656 | |||
|
2657 | # inheader is used to track if a line is in the | |||
|
2658 | # header portion of the diff. This helps properly account | |||
|
2659 | # for lines that start with '--' or '++' | |||
|
2660 | inheader = False | |||
|
2661 | ||||
2657 | for line in lines: |
|
2662 | for line in lines: | |
2658 | if line.startswith('diff'): |
|
2663 | if line.startswith('diff'): | |
2659 | addresult() |
|
2664 | addresult() | |
2660 |
# s |
|
2665 | # starting a new file diff | |
|
2666 | # set numbers to 0 and reset inheader | |||
|
2667 | inheader = True | |||
2661 | adds, removes, isbinary = 0, 0, False |
|
2668 | adds, removes, isbinary = 0, 0, False | |
2662 | if line.startswith('diff --git a/'): |
|
2669 | if line.startswith('diff --git a/'): | |
2663 | filename = gitre.search(line).group(2) |
|
2670 | filename = gitre.search(line).group(2) | |
2664 | elif line.startswith('diff -r'): |
|
2671 | elif line.startswith('diff -r'): | |
2665 | # format: "diff -r ... -r ... filename" |
|
2672 | # format: "diff -r ... -r ... filename" | |
2666 | filename = diffre.search(line).group(1) |
|
2673 | filename = diffre.search(line).group(1) | |
2667 |
elif line.startswith(' |
|
2674 | elif line.startswith('@@'): | |
|
2675 | inheader = False | |||
|
2676 | elif line.startswith('+') and not inheader: | |||
2668 | adds += 1 |
|
2677 | adds += 1 | |
2669 |
elif line.startswith('-') and not |
|
2678 | elif line.startswith('-') and not inheader: | |
2670 | removes += 1 |
|
2679 | removes += 1 | |
2671 | elif (line.startswith('GIT binary patch') or |
|
2680 | elif (line.startswith('GIT binary patch') or | |
2672 | line.startswith('Binary file')): |
|
2681 | line.startswith('Binary file')): |
@@ -105,3 +105,83 b' diffstat within directories:' | |||||
105 | $ hg diff --stat --root . -I old |
|
105 | $ hg diff --stat --root . -I old | |
106 |
|
106 | |||
107 | $ cd .. |
|
107 | $ cd .. | |
|
108 | ||||
|
109 | Files with lines beginning with '--' or '++' should be properly counted in diffstat | |||
|
110 | ||||
|
111 | $ hg up -Cr tip | |||
|
112 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
113 | $ rm dir1/new | |||
|
114 | $ rm dir2/new | |||
|
115 | $ rm "file with spaces" | |||
|
116 | $ cat > file << EOF | |||
|
117 | > line 1 | |||
|
118 | > line 2 | |||
|
119 | > line 3 | |||
|
120 | > EOF | |||
|
121 | $ hg commit -Am file | |||
|
122 | adding file | |||
|
123 | ||||
|
124 | Lines added starting with '--' should count as additions | |||
|
125 | $ cat > file << EOF | |||
|
126 | > line 1 | |||
|
127 | > -- line 2, with dashes | |||
|
128 | > line 3 | |||
|
129 | > EOF | |||
|
130 | ||||
|
131 | $ hg diff --root . | |||
|
132 | diff -r be1569354b24 file | |||
|
133 | --- a/file Thu Jan 01 00:00:00 1970 +0000 | |||
|
134 | +++ b/file * (glob) | |||
|
135 | @@ -1,3 +1,3 @@ | |||
|
136 | line 1 | |||
|
137 | -line 2 | |||
|
138 | +-- line 2, with dashes | |||
|
139 | line 3 | |||
|
140 | ||||
|
141 | $ hg diff --root . --stat | |||
|
142 | file | 2 +- | |||
|
143 | 1 files changed, 1 insertions(+), 1 deletions(-) | |||
|
144 | ||||
|
145 | Lines changed starting with '--' should count as deletions | |||
|
146 | $ hg commit -m filev2 | |||
|
147 | $ cat > file << EOF | |||
|
148 | > line 1 | |||
|
149 | > -- line 2, with dashes, changed again | |||
|
150 | > line 3 | |||
|
151 | > EOF | |||
|
152 | ||||
|
153 | $ hg diff --root . | |||
|
154 | diff -r 160f7c034df6 file | |||
|
155 | --- a/file Thu Jan 01 00:00:00 1970 +0000 | |||
|
156 | +++ b/file * (glob) | |||
|
157 | @@ -1,3 +1,3 @@ | |||
|
158 | line 1 | |||
|
159 | --- line 2, with dashes | |||
|
160 | +-- line 2, with dashes, changed again | |||
|
161 | line 3 | |||
|
162 | ||||
|
163 | $ hg diff --root . --stat | |||
|
164 | file | 2 +- | |||
|
165 | 1 files changed, 1 insertions(+), 1 deletions(-) | |||
|
166 | ||||
|
167 | Lines changed starting with '--' should count as deletions | |||
|
168 | and starting with '++' should count as additions | |||
|
169 | $ cat > file << EOF | |||
|
170 | > line 1 | |||
|
171 | > ++ line 2, switched dashes to plusses | |||
|
172 | > line 3 | |||
|
173 | > EOF | |||
|
174 | ||||
|
175 | $ hg diff --root . | |||
|
176 | diff -r 160f7c034df6 file | |||
|
177 | --- a/file Thu Jan 01 00:00:00 1970 +0000 | |||
|
178 | +++ b/file * (glob) | |||
|
179 | @@ -1,3 +1,3 @@ | |||
|
180 | line 1 | |||
|
181 | --- line 2, with dashes | |||
|
182 | +++ line 2, switched dashes to plusses | |||
|
183 | line 3 | |||
|
184 | ||||
|
185 | $ hg diff --root . --stat | |||
|
186 | file | 2 +- | |||
|
187 | 1 files changed, 1 insertions(+), 1 deletions(-) |
General Comments 0
You need to be logged in to leave comments.
Login now