File: git-conflicts.bash

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (48 lines) | stat: -rwxr-xr-x 1,708 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env bash
##
## Copyright (C) by Argonne National Laboratory
##     See COPYRIGHT in top-level directory
##

max_abbrev=12
scale=10

total=`git rev-list --all | wc -l`

echo "Conflicts:"
echo "Format:   [abbrev length]: number of conflicts / total number of refs (percentage conflicts)"
for ((x = 1 ; x <= ${max_abbrev} ; x++)) ; do
    conflicts=`git rev-list --all --abbrev=$x --abbrev-commit | sort | uniq -D -w$x | wc -l`
    percent=`echo "scale=$scale ; 100 * $conflicts / $total" | bc | awk '{ printf("%1.2f\n", $0); }'`
    echo "    [$x]: $conflicts / $total ($percent %)"
    if test "$conflicts" = "0" ; then break ; fi
done

##
## probability calculation is based on this random link, that I found
## online:
## http://blog.cuviper.com/2013/11/10/how-short-can-git-abbreviate/
##
## I have not verified the accuracy of the calculation at that link,
## but if it is online, it must be true, of course. ;-)
##

min_abbrev=$x

echo
echo "Probability of collision on your next commit:"
echo "Format:   [abbrev length]: probability of collision"
for ((x = ${min_abbrev}; x <= ${max_abbrev} ; x++)) ; do
    percent=`echo "scale=$scale ; 100 * ($total) / (16 ^ $x)" | bc | awk '{ printf("%1.4f\n", $0); }'`
    echo "    [$x]: $percent %"
done

commits_last_year=`git rev-list --all --since="1 year ago" | wc -l`

echo
echo "Probability of collision in the next year (based on commits last year):"
echo "Format:   [abbrev length]: probability of collision"
for ((x = ${min_abbrev}; x <= ${max_abbrev} ; x++)) ; do
    percent=`echo "scale=$scale ; 100 * (1 - ((1 - ($total / (16 ^ $x))) ^ ${commits_last_year}))" | bc | awk '{ printf("%1.4f\n", $0); }'`
    echo "    [$x]: $percent %"
done