annotate hgweb.cgi @ 22022:2ea6d906cf9b

merge: use no-minimal for premerge too ecc1387138ba disabled minimal for `internal:merge` but forgot to also disabled it for premerge. This is now done. This gives me an occasion to shamelessly includes my explanation of why this minimisation feature must disappear: [this is why it's pointless to reject patches with misspellings in the description - mpm] Detailled explanation ===================== The ``simplemerge`` code use in ``internal:merge`` has a feature called "minimization". It reprocess conflicting chunks to find common changes inside them and excludes such common sections from the marker. This approach seems a significant win at first glance but produces very confusing results in some other cases. Simple example -------------- A simple example is enough to show the benefit of this feature. In this merge, both sides change all numbers from letters to digits, but one side is also changing some values. $ cat << EOF > base > Small Mathematical Series. > One > Two > Three > Four > Five > Hop we are done. > EOF $ cat << EOF > local > Small Mathematical Series. > 1 > 2 > 3 > 4 > 5 > Hop we are done. > EOF $ cat << EOF > other > Small Mathematical Series. > 1 > 2 > 3 > 6 > 8 > Hop we are done. > EOF In the minimalists case, the markers focus on the disagreement between the two sides. $ $TESTDIR/../contrib/simplemerge --print local base other Small Mathematical Series. 1 2 3 <<<<<<< local 4 5 ======= 6 8 >>>>>>> other Hop we are done. warning: conflicts during merge. [1] In the non minimalist case, the whole chunk is included in the conflict marker. Making it harder spot actual differences. $ $TESTDIR/../contrib/simplemerge --print --no-minimal local base other Small Mathematical Series. <<<<<<< local 1 2 3 4 5 ======= 1 2 3 6 8 >>>>>>> other Hop we are done. warning: conflicts during merge. [1] Practical Advantages of minimalisation: merge of grafted change --------------------------------------------------------------- This feature can be very useful when a change have been grafted in another branch and then some change have been made to the grafted code. $ cat << EOF > base > # empty file > EOF $ cat << EOF > local > def somefunction(one, two): > some = one > stuff = two > are(happening) > here() > EOF $ cat << EOF > other > def somefunction(one, two): > some = one > change = two > are(happening) > here() > EOF The minimalist case recognises the grafted content as similar and highlight the actual change. $ $TESTDIR/../contrib/simplemerge --print local base other def somefunction(one, two): some = one <<<<<<< local stuff = two ======= change = two >>>>>>> other are(happening) here() warning: conflicts during merge. [1] Again, the non-minimalist case produces a larger conflict. Making it harder to spot the actual conflict. $ $TESTDIR/../contrib/simplemerge --print --no-minimal local base other <<<<<<< local def somefunction(one, two): some = one stuff = two are(happening) here() ======= def somefunction(one, two): some = one change = two are(happening) here() >>>>>>> other warning: conflicts during merge. [1] Practical disadvantage: multiple functions on each side --------------------------------------------------------------- So, if this "minimalist" help so much, why introduce a setting to disable it? The issue is that this minimisation will grab any common lines for breaking chunks. This may result in partial context when solving a merge. The most simple example is a merge where both side added some (different) functions separated by blank lines. The "minimalist" approach will recognise the blank line as "common" and over slice the chunks, turning a simple conflict case into multiple pairs of conflicting functions. $ cat << EOF > base > # empty file > EOF $ cat << EOF > local > def function1(): > bla() > bla() > bla() > > def function2(): > ble() > ble() > ble() > EOF $ cat << EOF > other > def function3(): > bli() > bli() > bli() > > def function4(): > blo() > blo() > blo() > EOF The minimal case presents each function as a separated context. $ $TESTDIR/../contrib/simplemerge --print local base other <<<<<<< local def function1(): bla() bla() bla() ======= def function3(): bli() bli() bli() >>>>>>> other <<<<<<< local def function2(): ble() ble() ble() ======= def function4(): blo() blo() blo() >>>>>>> other warning: conflicts during merge. [1] The non-minimalist approach produces a simpler version with more context in each block. Solving such conflicts is usually as simple as dropping the 3 lines dedicated to markers. $ $TESTDIR/../contrib/simplemerge --prin --no-minimal local base other <<<<<<< local def function1(): bla() bla() bla() def function2(): ble() ble() ble() ======= def function3(): bli() bli() bli() def function4(): blo() blo() blo() >>>>>>> other warning: conflicts during merge. [1] Practical disaster: programing language have a lot of common line ================================================================= If only blank lines between function where the only frequent content of a code file. But programming language tend to repeat them self much more often. In that case, the minimalist approach turns a simple conflict into a massive mess. Consider this example where two unrelated functions are added on each side. Those function shares common programming constructs by chance. $ cat << EOF > base > # empty file > EOF $ cat << EOF > local > def longfunction(): > if bla: > foo > else: > bar > try: > ret = some stuff > except Exception: > ret = None > if ret is not None: > return ret > return 0 > > def shortfunction(foo): > goo() > ret = foo + 5 > return ret > EOF $ cat << EOF > other > def otherlongfunction(): > for x in xxx: > if coin: > break > tutu > else: > bar() > baz() > ret = week() > try: > groumpf = tutu > fool() > except Exception: > zoo() > pool() > if cond: > return ret > > # some big block > ret ** 6 > koin() > return ret > EOF The minimalist approach will hash the whole conflict into small chunks that does not match any meaningful semantic and are impossible to solve. $ $TESTDIR/../contrib/simplemerge --print local base other <<<<<<< local def longfunction(): if bla: foo ======= def otherlongfunction(): for x in xxx: if coin: break tutu >>>>>>> other else: <<<<<<< local bar ======= bar() baz() ret = week() >>>>>>> other try: <<<<<<< local ret = some stuff ======= groumpf = tutu fool() >>>>>>> other except Exception: <<<<<<< local ret = None if ret is not None: ======= zoo() pool() if cond: >>>>>>> other return ret <<<<<<< local return 0 ======= >>>>>>> other <<<<<<< local def shortfunction(foo): goo() ret = foo + 5 ======= # some big block ret ** 6 koin() >>>>>>> other return ret warning: conflicts during merge. [1] The non minimalist approach will properly produce a single set of conflict markers. Highlighting that the two chunk are unrelated. Such conflict from unrelated content added at the same place is usually solved by dropping the marker an keeping both content. Something impossible with minimised markers. $ $TESTDIR/../contrib/simplemerge --prin --no-minimal local base other <<<<<<< local def longfunction(): if bla: foo else: bar try: ret = some stuff except Exception: ret = None if ret is not None: return ret return 0 def shortfunction(foo): goo() ret = foo + 5 return ret ======= def otherlongfunction(): for x in xxx: if coin: break tutu else: bar() baz() ret = week() try: groumpf = tutu fool() except Exception: zoo() pool() if cond: return ret # some big block ret ** 6 koin() return ret >>>>>>> other warning: conflicts during merge. [1]
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 29 Jul 2014 11:55:01 -0700
parents 85cba926cb59
children 4b0fc75f9403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
202
e875a0cf7f3a Call python via env in hgweb.cgi
mpm@selenic.com
parents: 159
diff changeset
1 #!/usr/bin/env python
159
f9d8620ef469 Add example CGI script
mpm@selenic.com
parents:
diff changeset
2 #
11000
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
3 # An example hgweb CGI script, edit as necessary
11503
227b9f13db13 hgweb: add link to wiki
Martin Geisler <mg@lazybytes.net>
parents: 11000
diff changeset
4 # See also http://mercurial.selenic.com/wiki/PublishingRepositories
159
f9d8620ef469 Add example CGI script
mpm@selenic.com
parents:
diff changeset
5
11000
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
6 # Path to repo or hgweb config to serve (see 'hg help hgweb')
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
7 config = "/path/to/repo/or/config"
5244
79279b5583c6 cgi: sys.path.insert should be before importing mercurial
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 5197
diff changeset
8
15475
85cba926cb59 hgweb: add hint about finding library path with debuginstall
Matt Mackall <mpm@selenic.com>
parents: 11503
diff changeset
9 # Uncomment and adjust if Mercurial is not installed system-wide
85cba926cb59 hgweb: add hint about finding library path with debuginstall
Matt Mackall <mpm@selenic.com>
parents: 11503
diff changeset
10 # (consult "installed modules" path from 'hg debuginstall'):
11000
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
11 #import sys; sys.path.insert(0, "/path/to/python/lib")
5197
55860a45bbf2 Enable demandimport only in scripts, not in importable modules (issue605)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3868
diff changeset
12
6080
4baad19c4801 hgweb: disable cgitb by default
Maxim Dounin <mdounin@mdounin.ru>
parents: 5995
diff changeset
13 # Uncomment to send python tracebacks to the browser if an error occurs:
11000
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
14 #import cgitb; cgitb.enable()
391
5f65a108a559 hgweb: pull cgitb into CGI script example, where it can easily be disabled
mpm@selenic.com
parents: 202
diff changeset
15
11000
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
16 from mercurial import demandimport; demandimport.enable()
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
17 from mercurial.hgweb import hgweb, wsgicgi
338167735124 hgweb: simplify hgweb.cgi, add help pointer
Matt Mackall <mpm@selenic.com>
parents: 6142
diff changeset
18 application = hgweb(config)
6141
90e5c82a3859 Backed out changeset b913d3aacddc (see issue971/msg5317)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5995
diff changeset
19 wsgicgi.launch(application)