|
|
Mads Kiilerich
|
bf39a5c8d666
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
6c1a8d17b2b9
|
5 years ago
|
|
diffs: add test coverage of inline diff with other markup
Add trailing whitespaces ... but also whitespace before changes (which might seem trailing but isn't).
|
|
|
Mads Kiilerich
|
d35d14b05b82
|
5 years ago
|
|
diff: handle some escaped characters in Git diffs
There are some odd characters (like \r and \n) that the Kallithea UI doesn't allow in filenames in repos. Kallithea (through the routes module) will fail to generate URLs when browsing Files. That is a known limitation with minimal real-world impact, non-trivial to work around or fix.
There are very few relevant use cases for tracking files with odd filenames. \t is valid but is hard to render in a meaningful way in the UI. And ASCII characters like \ and " are not usable on Windows and should just be avoided.
Kallithea would parse Git diffs with odd characers incorrectly or fail, even before hitting the known limitation. With this change, Kallithea will parse diffs with odd filenames correctly (and then hit the limitation).
Git will quote odd filenames and escape the odd characters when emitting diffs. (Mercurial does by design not allow \r and \n , and Mercurial will thus never have to quote file names in diffs.)
Quotes are already handled (and ignored). With this change, Kallithea will handle \ unescaping of \\ and \", the usual letters like \r and \n and \t, and octal numbers like \033 (for ESC) .
Filenames with \ and " will work perfectly (when not on Windows).
Filenames with \t and ESC will work fine, but without helpful display in the UI.
Filenames with \r and \n will still make the UI fail when trying to generate URLs.
Thanks to stypr of Flatt Security for raising this.
|
|
|
Mads Kiilerich
|
fd61f678577f
|
5 years ago
|
|
diff: improved handling of Git diffs with " quoting
Kallithea would intentionally and explicitly fail with an ugly exception when trying to parse Git diffs with quoted filenames.
Improve this by parsing quotes ... and ignore them, as long as they are matching. The content inside the quotes might be \-escaped ... but that could potentially also be the case without quoting. We will fix that later.
Adding some test cases that before would have failed to parse and raised an exception.
Thanks to stypr of Flatt Security for raising this.
|
|
|
Mads Kiilerich
|
7b7afdbe57af
|
5 years ago
|
|
|
|
|
Thomas De Schampheleire
|
73ba6abe60db
|
5 years ago
|
|
lib/diffs: make sure that trailing tabs are indicated Backport of 53142fd5af4e - the problem also existed before f79c40759d6f. Eat trailing newline after trailing tab as we already do for trailing spaces. The change diff mainly shows re group numbers shifting.
|
|
|
Thomas De Schampheleire
|
53142fd5af4e
|
5 years ago
|
|
lib/diffs: make sure that trailing tabs are indicated Between the initial submission and final version of commit f79c40759d6f, changes were made that turn out to be incorrect. The changes assume that the later match on trailing tabs will 'win' from the plain 'tab' match. However, Python 're' documentation says: As the target string is scanned, REs separated by '|' are tried from left to right. When one pattern completely matches, that branch is accepted. This means that once A matches, B will not be tested further, even if it would produce a longer overall match. In other words, the '|' operator is never greedy. https://docs.python.org/3.8/library/re.htmlAs a result, a trailing tab is seen as a plain tab and not highlighted in a special way. Unify the tab handling to make it unambiguous how they should be parsed. The change diff mainly shows re group numbers shifting.
|
|
|
Mads Kiilerich
|
161cf7e3566f
|
5 years ago
|
|
diff: refactor to avoid complexity of passing unnecessary trailing newline around
_escaper tried to handle these optional newlines ... but did not always preserve them. Keep it simple.
In normal operations, all diff lines end with \n . We only saw un-terminated lines in a couple of old test cases.
|
|
|
Mads Kiilerich
|
32757d5e9d0b
|
5 years ago
|
|
diff: drop internal inconsistent use of '...' as context line numbers
as_html() did in some cases not check for '...' and would thus emit unnecessary html.
|
|
|
Mads Kiilerich
|
7172f3b0042b
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
e527cc2ce8dc
|
6 years ago
|
|
cleanup: get rid of most "import *"
Apply script generated with the following hack: ( hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(.*)' may be undefined, or defined from star imports.*/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.* undefined name '(.*)'$/sed -ri 's,\\\\<\2\\\\>([^=]|$),XXXX.\2\\\\1,g' \1/gp" | sort -u hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\\\\<XXXX\\\\.,\3.,g' \1/gp" | sort -u hg loc '*.py'|xargs pyflakes-2 | sed -rn "s/([^:]*):.*'(from .*)\.([^.]*) import \*' used.*/sed -ri 's,\2\\\\.\3 .*,\2 import \3,g' \1/gp" | sort -u ) | grep -v kallithea/bin/kallithea_cli_ishell.py > fix2.sh
|
|
|
Mads Kiilerich
|
7986422cacb3
|
6 years ago
|
|
tests: avoid unicode u'' repr in test_diff_markup output
It will go away with py3 anyway.
|
|
|
Mads Kiilerich
|
e2e5140704fc
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
0a277465fddf
|
6 years ago
|
|
|
|
|
domruf
|
ceaa65df5add
|
8 years ago
|
|
diff: use fontello icon-diff-* names in generated html
This way we need less style code ... but generate slightly bigger html.
Also move the style code to kallithea-diff.less and remove the now obsolete comment.
|
|
|
Mads Kiilerich
|
24a9bec8138c
|
8 years ago
|
|
diffs: inline prepare() into __init__ and make the result available as .parsed
Make it more clear what the DiffProcessor is: Something that works on a raw diff as input, mainly compute when initialized, and returns an object where the result is available in different ways.
|
|
|
Thomas De Schampheleire
|
8d98924c58b1
|
9 years ago
|
|
tests: add as little code as possible in __init__.py
kallithea/tests/__init__.py contained quite a lot of code, including the test base class TestController. This in itself may be considered bad practice.
Specifically, this poses a problem when using pytest 3.0+, in which asserts in some files are not automatically rewritten to give improved assert output. That problem can be fixed by explicitly registering such files for assertion rewriting, but that register call should be executed _before_ said files are imported. I.e. if the register call is in kallithea/tests/__init__.py, assert calls in __init__.py itself can not be rewritten.
Since the TestController base class does effectively contain asserts, and we do not want to execute the register call from somewhere outside the kallithea/tests directory, we need to move the TestController class to another file (kallithea/tests/base.py) so we can have a register call in __init__.py before loading base.py.
While not strictly necessary to fix the mentioned pytest problem, we take the opportunity to fully clean __init__.py and move everything to the new kallithea/tests/base.py. While doing so, unnecessary imports are removed, and imports are ordered alphabetically. Explicit imports of symbols from modules that were already imported as a whole, are removed in favor of fully qualifying the references (e.g. tempfile._RandomNameSequence).
|
|
|
Mads Kiilerich
|
6b723a49a9a1
|
9 years ago
|
|
diff: only highlight of difference between del and add line for one-liners
Comparing a single del line with the first of several add lines would often be quite arbitrary and misleading.
Note: the non-gitdiff code paths in diffs.py are incomplete and unused and unusable.
|
|
|
Thomas De Schampheleire
|
7f2aa3ec2931
|
10 years ago
|
|
pytest migration: rename TestControllerPytest back to TestController
The name TestControllerPytest was introduced to allow a temporary situation where nose/unittest and pytest-based tests could coexist. This situation is now over, so the base test class can be renamed again.
|
|
|
Thomas De Schampheleire
|
7483b3f3bea5
|
10 years ago
|
|
pytest migration: models: switch to standard assert statements Use unittest2pytest to replace unittest-style assert statements (e.g. assertEqual) with standard Python assert statements to benefit from pytest's improved reporting on assert failures. The conversion by unittest2pytest was correct except for: - 'import pytest' is not automatically added when needed - line wrapping in string formatting caused a syntax error in the transformed code. Reported upstream at https://github.com/pytest-dev/unittest2pytest/issues/3 . - in assertRaises with a lambda, the lambda needs to be removed
|
|
|
Thomas De Schampheleire
|
be1d20bfd2dd
|
10 years ago
|
|
pytest migration: model: convert all tests to TestControllerPytest
The model tests were based on BaseTestCase which does not exist currently for pytest-style tests. Nevertheless, there seems to be no advantage of directly subclassing BaseTestCase over subclassing TestControllerPytest. Thus, keep things simple and use TestControllerPytest.
|
|
|
Mads Kiilerich
|
eb072b2cfa18
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
2bf5e8731154
|
10 years ago
|
|
git: fix parsing of git mode change + rename diffs
Assume mode lines come first, like for hg diffs.
|
|
|
Søren Løvborg
|
431689d7f37d
|
10 years ago
|
|
remove vestiges of Python 2.5 support
We only support Python 2.6 and 2.7; hence we do not need to import with-statement support from __future__.
|
|
|
Mads Kiilerich
|
c417ef1f43b1
|
10 years ago
|
|
diffs: avoid conflicts between inline diff mechanism and special markup
It would sometimes emit markup like <pre><ins><u</ins> <ins>class</ins><ins>=</ins><ins>"cr</ins><ins>"></u></ins></pre> instead of <pre><ins><u class="cr"></u></ins></pre>
|
|
|
duanhongyi
|
2d2856fd1144
|
11 years ago
|
|
diff: handle GIT delta binary patches It seems like they only occur rarely; recent git versions do apparently not create them. Using a test case from https://secure.phabricator.com/T6157 .
|
|
|
Mads Kiilerich
|
fbb992c719aa
|
11 years ago
|
|
diff: don't split lines on bare CR as python splitlines do
The line count from the @@ lines and the actual count would get out of sync and an incomplete diff would be shown.
This is slower than native splitlines ... but that is what it takes to handle it correctly. (Except that we perhaps could use .split('\n') and patch the result ...)
|
|
|
Mads Kiilerich
|
11d6d1cec667
|
11 years ago
|
|
diff: fix diff of renamed files with whitespace in their names
Before, header parsing would fail.
|
|
|
Mads Kiilerich
|
9740ec3be07a
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
7b8cbcb927b2
|
11 years ago
|
|
|
|
|
Sean Farley
|
fbf75412c609
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
cd9bb3e07e68
|
11 years ago
|
|
diff: don't group diffs based on the kind of change
We do no longer show the content of deleted files so there is no longer any reason to put them at the end. Keeping all changes sorted by file name makes it easier to review.
|
|
|
Mads Kiilerich
|
99c914f5fd89
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
d1addaf7a91e
|
11 years ago
|
|
Second step in two-part process to rename directories. This is the actual directory rename.
|