This repository contains the code for UTango: Untangling Commits with Context-aware, Graph-based, Code Change Clustering Learning Model.
During software evolution, developers make several changes and commit them into the repositories. Unfortunately, many of them tangle different purposes, both hampering program comprehension and reducing separation of concerns. Automated approaches with deterministic solutions have been proposed to untangle commits. In this work, we present UTango, a machine learning (ML)- based approach that learns to untangle the changes in a commit.We develop a novel code change clustering learning model that learns to cluster the code changes, represented by the embeddings, into different groups with different concerns. We adapt the agglomerative clustering algorithm into a supervised-learning clustering model operating on the learned code change embeddings via trainable parameters and a loss function in comparing the predicted clusters and the correct ones during training. To facilitate our clustering learning model, we develop a context-aware, graph-based, code change representation learning model, leveraging Label, Graph-based Convolution Network to produce the contextualized embeddings for code changes, that integrates program dependencies and the surrounding contexts of the changes. The contexts and cloned code are also explicitly represented, helping UTango distinguish their concerns. Our empirical evaluation on a C# dataset with 1,612 tangled commits shows that it achieves the accuracy of 28.6%–462.5%, relatively higher than the state-of-the-art approaches in clustering the changed code. We evaluated UTango in a Java dataset with +14k tangled commits. The result shows that it achieves 13.3%–100.0% relatively higher accuracy than the state-of-the-art approaches.
We published our processed dataset at https://drive.google.com/file/d/1WdP9SI4T8H_8Tb-zAKIat_o70sQuUbTl/view?usp=sharing
Please create a folder named data under the root folder of UTango, download the dataset, unzip it and put all files in ./data folder.
If you want to use your own dataset, please prepare the data as follow:
-
The data are stored in
data_n.ptand ordered based on the tangled commit last modified time. -
Each
data_n.ptinclude a set ofDataobject fromtorch_geometricwith one extra element for the ground truth labels. EachDatarepresent a method in a tangled commit:1>
Data.x = Node_feature_vector2>
Data.y = Context_info3>
Data.edge_index = edge_list
Where Node_feature_vector is N*R sized torch tensors that represent the node features in the graph, N is the number of nodes on the graph and R is the representation vector length.
edge_list is the matrixs to represent the graph edges for each method. Please refer to torch_geometric package for more details.
Context_info is an array that has the same length as the node numbers on the graph. Each element inside represent one node. If it is not a code change node, the value for that position is 0. If it is the code change node, the element is an array that include all index for the context nodes.
Use Python 3.9.20. You can use pyenv to run different Python versions at the same time.
Install torch first with:
pip install torch==1.13.1Then, run following:
pip install -r requirements.txtPut your data into data folder. Then run following:
python -m UTango train <model_path> <dataset_folder> <num_data_files>python -m UTango demo