{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"button": false,
"new_sheet": false,
"run_control": {
"read_only": false
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Where the Bugs are\n",
"\n",
"Every time a bug is fixed, developers leave a trace – in the _version database_ when they commit the fix, or in the _bug database_ when they close the bug. In this chapter, we learn how to _mine these repositories_ for past changes and bugs, and how to _map_ them to individual modules and functions, highlighting those project components that have seen most changes and fixes over time."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-12T12:50:30.423855Z",
"iopub.status.busy": "2023-11-12T12:50:30.423754Z",
"iopub.status.idle": "2023-11-12T12:50:30.459454Z",
"shell.execute_reply": "2023-11-12T12:50:30.459150Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from bookutils import YouTubeVideo\n",
"YouTubeVideo(\"Aifq0JOc1Jc\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"new_sheet": false,
"run_control": {
"read_only": false
},
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"**Prerequisites**\n",
"\n",
"* You should have read [the chapter on tracking bugs](Tracking.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"button": false,
"execution": {
"iopub.execute_input": "2023-11-12T12:50:30.480464Z",
"iopub.status.busy": "2023-11-12T12:50:30.480286Z",
"iopub.status.idle": "2023-11-12T12:50:30.482376Z",
"shell.execute_reply": "2023-11-12T12:50:30.482124Z"
},
"new_sheet": false,
"run_control": {
"read_only": false
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import bookutils.setup"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-12T12:50:30.483886Z",
"iopub.status.busy": "2023-11-12T12:50:30.483781Z",
"iopub.status.idle": "2023-11-12T12:50:30.596538Z",
"shell.execute_reply": "2023-11-12T12:50:30.596246Z"
},
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"source": [
"import Tracking"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"## Synopsis\n",
"\n",
"\n",
"To [use the code provided in this chapter](Importing.ipynb), write\n",
"\n",
"```python\n",
">>> from debuggingbook.ChangeCounter import \n",
"```\n",
"\n",
"and then make use of the following features.\n",
"\n",
"\n",
"This chapter provides two classes `ChangeCounter` and `FineChangeCounter` that allow mining and visualizing the distribution of changes in a given `git` repository.\n",
"\n",
"`ChangeCounter` is initialized as\n",
"\n",
"```python\n",
"change_counter = ChangeCounter(repository)\n",
"```\n",
"where `repository` is either \n",
"\n",
"* a _directory_ containing a `git` clone (i.e., it contains a `.git` directory)\n",
"* the URL of a `git` repository.\n",
"\n",
"Additional arguments are being passed to the underlying `Repository` class from the [PyDriller](https://pydriller.readthedocs.io/) Python package. A `filter` keyword argument, if given, is a predicate that takes a modification (from PyDriller) and returns True if it should be included.\n",
"\n",
"In a change counter, all elements in the repository are represented as _nodes_ – tuples $(f_1, f_2, ..., f_n)$ that denote a _hierarchy_: Each $f_i$ is a directory holding $f_{i+1}$, with $f_n$ being the actual file.\n",
"\n",
"A `change_counter` provides a number of attributes. `changes` is a mapping of nodes to the number of changes in that node:\n",
"\n",
"```python\n",
">>> change_counter.changes.get(('README.md',), None)\n",
"17\n",
"```\n",
"The `messages` attribute holds all commit messages related to that node:\n",
"\n",
"```python\n",
">>> change_counter.messages.get(('README.md',), None)\n",
"['Doc update',\n",
" 'Doc update',\n",
" 'Doc update',\n",
" 'Doc update',\n",
" 'Doc update',\n",
" 'Doc update',\n",
" 'Fix: corrected rule for rendered notebooks (#24)\\nNew: strip out any