2016-12-17 02:19:23 +03:00
|
|
|
Setup. SCM_SAMPLING_FILEPATH needs to be cleared as some environments may
|
|
|
|
have it set.
|
2016-06-03 02:19:05 +03:00
|
|
|
|
2016-12-17 02:19:23 +03:00
|
|
|
$ unset SCM_SAMPLING_FILEPATH
|
2016-06-03 02:19:05 +03:00
|
|
|
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
|
|
|
|
$ export PYTHONPATH
|
|
|
|
|
|
|
|
$ mkcommit() {
|
|
|
|
> echo "$1" > "$1"
|
|
|
|
> hg add "$1"
|
|
|
|
> echo "add $1" > msg
|
|
|
|
> echo "" >> msg
|
|
|
|
> hg ci -l msg
|
|
|
|
> }
|
|
|
|
Init the repo
|
|
|
|
$ hg init testrepo
|
|
|
|
$ cd testrepo
|
|
|
|
$ mkcommit a
|
|
|
|
Create an extension that logs every commit and also call repo.revs twice
|
|
|
|
|
|
|
|
Create an extension that logs the call to commit
|
|
|
|
$ cat > $TESTTMP/logcommit.py << EOF
|
|
|
|
> from mercurial import extensions, localrepo
|
|
|
|
> def cb(sample):
|
|
|
|
> return len(sample)
|
|
|
|
> def _commit(orig, repo, *args, **kwargs):
|
2016-06-07 20:24:56 +03:00
|
|
|
> repo.ui.log("commit", "match filter", k=1, a={"hi":"ho"})
|
|
|
|
> repo.ui.log("foo", "does not match filter", k=1, a={"hi":"ho"})
|
2016-06-25 02:18:34 +03:00
|
|
|
> repo.ui.log("commit", "message %s", "string", k=1, a={"hi":"ho"})
|
2016-06-03 02:19:05 +03:00
|
|
|
> return orig(repo, *args, **kwargs)
|
|
|
|
> def extsetup(ui):
|
|
|
|
> extensions.wrapfunction(localrepo.localrepository, 'commit', _commit)
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
|
|
|
|
Set up the extension and set a log file
|
2016-06-07 20:24:56 +03:00
|
|
|
We whitelist only the 'commit' key, only the events with that key will be
|
|
|
|
logged
|
2016-06-03 02:19:05 +03:00
|
|
|
$ cat >> $HGRCPATH << EOF
|
2016-06-07 20:24:56 +03:00
|
|
|
> [sampling]
|
|
|
|
> key.commit=commit_table
|
2016-06-03 02:19:05 +03:00
|
|
|
> [extensions]
|
2018-01-09 14:06:09 +03:00
|
|
|
> sampling=
|
2016-06-03 02:19:05 +03:00
|
|
|
> EOF
|
|
|
|
$ LOGDIR=`pwd`/logs
|
|
|
|
$ mkdir $LOGDIR
|
|
|
|
$ echo "logcommit=$TESTTMP/logcommit.py" >> $HGRCPATH
|
|
|
|
$ echo "[sampling]" >> $HGRCPATH
|
|
|
|
$ echo "filepath = $LOGDIR/samplingpath.txt" >> $HGRCPATH
|
|
|
|
|
2016-06-25 02:18:34 +03:00
|
|
|
Do a couple of commits. We expect to log two messages per call to repo.commit.
|
2016-06-03 02:19:05 +03:00
|
|
|
|
|
|
|
$ mkcommit b
|
|
|
|
$ mkcommit c
|
|
|
|
>>> import json
|
|
|
|
>>> with open("$LOGDIR/samplingpath.txt") as f:
|
|
|
|
... data = f.read()
|
|
|
|
>>> for record in data.strip("\0").split("\0"):
|
|
|
|
... parsedrecord = json.loads(record)
|
2016-07-08 15:15:42 +03:00
|
|
|
... print(' '.join([parsedrecord["data"]["msg"], parsedrecord["category"]]))
|
2016-06-22 03:07:55 +03:00
|
|
|
... assert len(parsedrecord["data"]) == 4
|
2016-06-25 02:18:34 +03:00
|
|
|
match filter commit_table
|
|
|
|
message string commit_table
|
|
|
|
match filter commit_table
|
|
|
|
message string commit_table
|