#!/bin/bash
# SPDX-License-Identifier: MIT
#
# Had an idea:
#
# 	"Sort files in a patch by lines changed in each touched file"
#
# This idea was offered as a response (alternate ways to sort files
# in review tools) to a USask study:
#
#	[2025-05-26]
#	Purpose and objective of the study: This survey aims to explore how the
#	ordering of files in a pull request impacts the code review process.
#	Currently, most code review tools display files in alphabetical order,
#	which may not be the most effective way to organize changes for review.
#	Research suggests that the current ordering can lead to uneven
#	attention across files, potentially affecting review quality. The
#	objective of this study is to understand developers' preferences,
#	challenges, and habits when reviewing multiple files, and to identify
#	alternative ordering strategies that could improve the efficiency and
#	effectiveness of code reviews. Your responses will help us propose
#	better file-ordering approaches and enhance the overall code review
#	experience.
# 	Researcher: Md Shamimur Rahman, Department of Computer Science,
# 	University of Saskatchewan, Canada <https://usask.ca>
# 	Supervisors: Dr. Chanchal Roy; Dr. Zadia Codabux
# 
COMMITID="$1"
exec git log -1 --stat -p -O<(\
	git log -1 -p "$COMMITID" | \
	diffstat -utp0 | \
	perl -lne 'print(($1+$2+$3)," ",$4) if m{^(\d+),(\d+),(\d+),"(.*)"}' | \
	sort -gk1 | \
	perl -pe 's{^\d+ }{}') "$COMMITID"
