##// END OF EJS Templates
wireprotov2: implement commands as a generator of objects...
wireprotov2: implement commands as a generator of objects Previously, wire protocol version 2 inherited version 1's model of having separate types to represent the results of different wire protocol commands. As I implemented more powerful commands in future commits, I found I was using a common pattern of returning a special type to hold a generator. This meant the command function required a closure to do most of the work. That made logic flow more difficult to follow. I also noticed that many commands were effectively a sequence of objects to be CBOR encoded. I think it makes sense to define version 2 commands as generators. This way, commands can simply emit the data structures they wish to send to the client. This eliminates the need for a closure in command functions and removes encoding from the bodies of commands. As part of this commit, the handling of response objects has been moved into the serverreactor class. This puts the reactor in the driver's seat with regards to CBOR encoding and error handling. Having error handling in the function that emits frames is particularly important because exceptions in that function can lead to things getting in a bad state: I'm fairly certain that uncaught exceptions in the frame generator were causing deadlocks. I also introduced a dedicated error type for explicit error reporting in command handlers. This will be used in subsequent commits. There's still a bit of work to be done here, especially around formalizing the error handling "protocol." I've added yet another TODO to track this so we don't forget. Test output changed because we're using generators and no longer know we are at the end of the data until we hit the end of the generator. This means we can't emit the end-of-stream flag until we've exhausted the generator. Hence the introduction of 0-sized end-of-stream frames. Differential Revision: https://phab.mercurial-scm.org/D4472

File last commit:

r37950:faa41fd2 default
r39595:07b58266 default
Show More
test-extdata.t
103 lines | 2.3 KiB | text/troff | Tads3Lexer
Yuya Nishihara
revset: add experimental support for extdata...
r34458 $ hg init repo
$ cd repo
Yuya Nishihara
extdata: ignore ambiguous identifier as well
r34460 $ for n in 0 1 2 3 4 5 6 7 8 9 10 11; do
Yuya Nishihara
revset: add experimental support for extdata...
r34458 > echo $n > $n
> hg ci -qAm $n
> done
test revset support
$ cat <<'EOF' >> .hg/hgrc
> [extdata]
> filedata = file:extdata.txt
Yuya Nishihara
templater: add experimental support for extdata...
r34459 > notes = notes.txt
Yuya Nishihara
revset: add experimental support for extdata...
r34458 > shelldata = shell:cat extdata.txt | grep 2
Yuya Nishihara
extdata: show debug message if external command exits with non-zero status...
r34543 > emptygrep = shell:cat extdata.txt | grep empty
Yuya Nishihara
revset: add experimental support for extdata...
r34458 > EOF
$ cat <<'EOF' > extdata.txt
Yuya Nishihara
templater: add experimental support for extdata...
r34459 > 2 another comment on 2
Yuya Nishihara
revset: add experimental support for extdata...
r34458 > 3
> EOF
Yuya Nishihara
templater: add experimental support for extdata...
r34459 $ cat <<'EOF' > notes.txt
> f6ed this change is great!
> e834 this is buggy :(
> 0625 first post
> bogusnode gives no error
Yuya Nishihara
extdata: ignore ambiguous identifier as well
r34460 > a ambiguous node gives no error
Yuya Nishihara
templater: add experimental support for extdata...
r34459 > EOF
Yuya Nishihara
revset: add experimental support for extdata...
r34458
$ hg log -qr "extdata(filedata)"
2:f6ed99a58333
3:9de260b1e88e
$ hg log -qr "extdata(shelldata)"
2:f6ed99a58333
test weight of extdata() revset
$ hg debugrevspec -p optimized "extdata(filedata) & 3"
* optimized:
(andsmally
(func
(symbol 'extdata')
(symbol 'filedata'))
(symbol '3'))
3
Yuya Nishihara
extdata: show debug message if external command exits with non-zero status...
r34543 test non-zero exit of shell command
$ hg log -qr "extdata(emptygrep)"
Yuya Nishihara
extdata: abort if external command exits with non-zero status (BC)...
r35413 abort: extdata command 'cat extdata.txt | grep empty' failed: exited with status 1
[255]
Yuya Nishihara
extdata: show debug message if external command exits with non-zero status...
r34543
Yuya Nishihara
revset: add experimental support for extdata...
r34458 test bad extdata() revset source
$ hg log -qr "extdata()"
hg: parse error: extdata takes at least 1 string argument
[255]
$ hg log -qr "extdata(unknown)"
abort: unknown extdata source 'unknown'
[255]
Yuya Nishihara
templater: add experimental support for extdata...
r34459 test template support:
$ hg log -r:3 -T "{node|short}{if(extdata('notes'), ' # {extdata('notes')}')}\n"
06254b906311 # first post
e8342c9a2ed1 # this is buggy :(
f6ed99a58333 # this change is great!
9de260b1e88e
test template cache:
$ hg log -r:3 -T '{rev} "{extdata("notes")}" "{extdata("shelldata")}"\n'
0 "first post" ""
1 "this is buggy :(" ""
2 "this change is great!" "another comment on 2"
3 "" ""
test bad extdata() template source
$ hg log -T "{extdata()}\n"
hg: parse error: extdata expects one argument
[255]
$ hg log -T "{extdata('unknown')}\n"
abort: unknown extdata source 'unknown'
[255]
Yuya Nishihara
templatefuncs: show hint if extdata source is evaluated to empty (issue5843)
r37950 $ hg log -T "{extdata(unknown)}\n"
hg: parse error: empty data source specified
(did you mean extdata('unknown')?)
[255]
$ hg log -T "{extdata('{unknown}')}\n"
hg: parse error: empty data source specified
[255]
Yuya Nishihara
templater: add experimental support for extdata...
r34459
Yuya Nishihara
revset: add experimental support for extdata...
r34458 we don't fix up relative file URLs, but we do run shell commands in repo root
$ mkdir sub
$ cd sub
$ hg log -qr "extdata(filedata)"
Matt Harbison
tests: add a substitution for ENOENT/ERROR_FILE_NOT_FOUND messages...
r35230 abort: error: $ENOENT$
Yuya Nishihara
revset: add experimental support for extdata...
r34458 [255]
$ hg log -qr "extdata(shelldata)"
2:f6ed99a58333
$ cd ..