Mercurial > hg
annotate contrib/debugcmdserver.py @ 25308:036c26b08b71
revset: add helper to build balanced addsets from chained 'or' operations
This function will be used by revset.orset() and scmutil.revrange() to reduce
the stack depth from O(n) to O(log(n)).
We've bikeshed the interface of this function, but we couldn't come to an
agreement. So we decided to attempt to make it move forward.
marmoute:
- new factory function isn't necessary for balanced addsets
- addset.__init__ can just recurse, should handle "len(subsets) == 2+"
yuja:
- want to write all "len(subsets) == 0, 1, 2, 3+" cases in the same function
- no recursion in __init__ for cosmetic reason: can't return, can't call
__init__ directly
I've changed it to a private function so that nobody would be tempted to
utilize it.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 24 May 2015 14:10:52 +0900 |
parents | e34106fa0dc3 |
children | cd03fbd5ab57 |
rev | line source |
---|---|
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
2 # |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 # Dumps output generated by Mercurial's command server in a formatted style to a |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 # given file or stderr if '-' is specified. Output is also written in its raw |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 # format to stdout. |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 # |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 # $ ./hg serve --cmds pipe | ./contrib/debugcmdserver.py - |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 # o, 52 -> 'capabilities: getencoding runcommand\nencoding: UTF-8' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
10 import sys, struct |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
11 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
12 if len(sys.argv) != 2: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 print 'usage: debugcmdserver.py FILE' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 sys.exit(1) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
15 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 outputfmt = '>cI' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 outputfmtsize = struct.calcsize(outputfmt) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 if sys.argv[1] == '-': |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 log = sys.stderr |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 else: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 log = open(sys.argv[1], 'a') |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 def read(size): |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 data = sys.stdin.read(size) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 if not data: |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
15259
diff
changeset
|
27 raise EOFError |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 sys.stdout.write(data) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
29 sys.stdout.flush() |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 return data |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
31 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 try: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 while True: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 header = read(outputfmtsize) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 channel, length = struct.unpack(outputfmt, header) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
36 log.write('%s, %-4d' % (channel, length)) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 if channel in 'IL': |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 log.write(' -> waiting for input\n') |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 else: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 data = read(length) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
41 log.write(' -> %r\n' % data) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 log.flush() |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 except EOFError: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 pass |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 finally: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 if log != sys.stderr: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 log.close() |