Skip to content

Commit 5148d90

Browse files
committed
fix bisection debugging
1 parent 7ea7536 commit 5148d90

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
lines changed

doc/source/8_debugging.rst

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ debugger commands that is enough to get started.
400400
`the pdb documentation <debugger-commands>`__. The part before the brackets
401401
is an abbreviated command which saves typing.
402402
:width: 100%
403-
:widths: 15, 60, 25
403+
:widths: 17, 59, 24
404404
:escape: '
405405
:name: debug-commands
406406

@@ -565,7 +565,7 @@ Most of the exercises presented here are examples of test-driven
565565
development: the tests are written to the problem specification, and you then
566566
write code implementing the specification which you test using the tests.
567567

568-
Test-driven development is not only a good way of knowing when you have coded
568+
Test-driven development is not just a good way of knowing when you have coded
569569
correctly. The process of creating the tests is also a very good way of
570570
establishing whether you understand the problem, and that specification is
571571
well-posed.
@@ -622,28 +622,28 @@ at least now have a much smaller piece of code to ask for help with.
622622
Bisection debugging
623623
...................
624624

625-
We are already familiar with git as a mechanism for accessing and saving
626-
code. However, revision control offers a lot more to the programmer than a
627-
place to keep code. In particular, one of the key benefits is the ability to go
628-
back to a previous version. This is particularly helpful in debugging
625+
We are already familiar with git as a mechanism for accessing and saving code.
626+
However, revision control offers a lot more to the programmer than a place to
627+
keep code. In particular, one of the key benefits is the ability to go back to
628+
a previous version. This is particularly helpful in debugging
629629
:term:`regressions <regression>`: things that used to work but no longer do. Of
630630
course in a perfect world where we have full test suite coverage of all
631631
functionality, and the test suite is run on every commit, this situation will
632632
never occur. However the reality is that test coverage is never complete, and
633633
there will always be untested functionality in any non-trivial piece of
634-
software. Regressions are a particularly vexing form of bug: there is little
635-
more frustrating to be coming up to a deadline and to discover that something
636-
that used to work no longer does.
634+
software. Regressions are a particularly vexing form of bug: there are few
635+
things more frustrating than to be coming up to a deadline and to discover that
636+
something that used to work no longer does.
637637

638638
If revision control has been used well over the course of a coding project, it
639639
offers a mechanism for debugging regressions. We just have to roll back the
640640
repository to previous versions until we find one in which the bug does not
641-
occur. In fact, we can think of this process mathematically. We can think of
642-
our repository as a function defined on the ordered set of commits which takes
643-
a positive value at commits without the bug in question, and negative values at
644-
commits which exhibit the bug. Our task is to find the zero of this function.
645-
In other words, to find a pair of adjacent commits such that the bug is absent
646-
in the first commit, but present in the second commit. Once we have established
641+
occur. In fact, we can think of this process mathematically. Our repository
642+
induces function defined on the ordered set of commits which takes a positive
643+
value at commits without the bug in question, and negative values at commits
644+
which exhibit the bug. Our task is to find the zero of this function. In other
645+
words, we must find a pair of adjacent commits such that the bug is absent in
646+
the first commit, but present in the second commit. Once we have established
647647
this, then we know that the bug is caused by one of the (hopefully small) set
648648
of changes introduced in that commit.
649649

@@ -709,18 +709,19 @@ in order to check if the bug is present there. The command to do that is:
709709

710710
.. code-block:: console
711711
712-
$ git reset --hard 66a10d5d374de796827ac3152f0c507a46b73d60
712+
$ git checkout a7426bd8533f2c819f7f164df9c197e277d058c3
713713
714714
Obviously you replace the commit ID with the commit you wish to roll back to.
715+
Git will print a warning that you are now in "detached HEAD" state. This is
716+
fine because we only want to run the code at this state, we don't want to make
717+
new commits from here.
718+
715719
We can see what we've done by checking the status of the repository:
716720

717721
.. code-block:: console
718722
719723
$ git status
720-
On branch main
721-
Your branch is behind 'origin/main' by 7 commits, and can be fast-forwarded.
722-
(use "git pull" to update your local branch)
723-
724+
HEAD detached at a7426bd8
724725
nothing to commit, working tree clean
725726
726727
We could, for example, run our test to check if the bug is present:
@@ -735,14 +736,14 @@ the repository with:
735736
.. code-block:: console
736737
737738
$ git rev-parse HEAD
738-
66a10d5d374de796827ac3152f0c507a46b73d60
739+
9e29934847407ea1d3ca3aba8062ce6fcbb7aff3
739740
740-
If we want to take the repository back to the newest commit then we do as the
741-
status message told us, and pull:
741+
If we want to take the repository back to the newest commit then we simply
742+
check out the branch name we started from. For example:
742743

743744
.. code-block:: console
744745
745-
$ git pull
746+
$ git checkout main
746747
747748
If we now check the status of our repository, we find we're at the head of our
748749
branch with a clean working tree:
@@ -768,25 +769,39 @@ set up the bisection we run:
768769

769770
.. code-block:: console
770771
771-
$ git bisect start HEAD 66a10d5d374de796827ac3152f0c507a46b73d60 --
772+
$ git bisect start HEAD 9e29934847407ea1d3ca3aba8062ce6fcbb7aff3 --
772773
773-
Obviously you replace the commit ID with your starting point. ``HEAD`` is a git
774-
shorthand for the current state of the repository, so it's a suitable end point
775-
in most cases. You can also substitute an explicit commit ID there. The final
776-
``--`` is required and acts to distinguish the commit IDs we are providing from
777-
any file names that we might be passing to the command (we won't be covering
778-
that case). Next we run the actual bisection:
774+
Obviously you replace the commit ID with your starting point. ``HEAD`` is a
775+
suitable end point in most cases. You can also substitute an explicit commit ID
776+
or a branch name there. The final ``--`` is required and acts to distinguish
777+
the commit IDs we are providing from any file names that we might be passing to
778+
the command (we won't be covering that case). Next we run the actual bisection:
779779

780780
.. code-block:: console
781781
782782
$ git bisect run python -m pytest ../bug_test.py
783783
784-
When the bisection terminates, the current state of the repository will be on
785-
the first commit that exhibits the bug. We can check the difference between
786-
that commit and the previous one using:
784+
When the bisection terminates, git prints out the commit ID of the first commit
785+
that exhibited the bug. Git also creates a log of all the commits that were
786+
tested during the bisection, and we can also retrieve the first bad commit from
787+
there. If we run:
788+
789+
.. code-block:: console
790+
791+
$ git bisect log
792+
793+
Then the last line of the output is:
794+
795+
.. code-block:: console
796+
797+
# first bad commit: [f03fcc09a24cabf0f2c76d850371c2c1f1396b6c]
798+
Enforce q\d notation be default (#60)
799+
800+
We can check the difference between that commit and the previous one using:
787801

788802
.. code-block:: console
789803
804+
$ git checkout f03fcc09a24cabf0f2c76d850371c2c1f1396b6c
790805
$ git diff HEAD~1
791806
792807
Here ``HEAD~1`` refers to the previous commit. Indeed, if we thought that the
@@ -915,7 +930,9 @@ Exercises
915930
.. code-block:: python3
916931
917932
import ufl
918-
argyris = ufl.FiniteElement("Argyris", degree=6, cell=ufl.triangle)
933+
r = ufl.FiniteElement("R", cell=ufl.triangle)
934+
assert r.sobolev_space() is ufl.L2
935+
919936
920937
Use `git bisect` to identify the first commit at which this code failed,
921938
and the last commit at which it worked, and answer the following questions.

0 commit comments

Comments
 (0)