about summary refs log tree commit diff
path: root/xpkgdiff
blob: 9072b34fa1147a2e6dcae11132493a815f15da02 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# xpkgdiff [-r] [-f|-x [-t]|-S|-c FILE|-p PROP[,...]] PKG - compare PKG between remote to local repositories

usage() {
	echo "Usage: xpkgdiff [-r] [-f|-x [-t]|-S|-c FILE|-p PROP[,...]] PKG"
	exit 1
}

: ${DIFF:="diff -u --color"}

# by default, don't sort
SORT='cat'

TMPDIR=$(mktemp --tmpdir -d "xpkgdiff.XXXXX")

while getopts Sc:fhp:rtx flag; do
	case $flag in
		S) QUERY='--show' ;;
		c) QUERY="--cat=$OPTARG" ;;
		f) QUERY='--files'; SORT='sort' ;;
		p) QUERY="--property $OPTARG" ;;
		r) REVERSE=1 ;;
		t) FULLTREE=1 ;;
		x) QUERY='--deps'; SORT='sort' ;;
		h|?) usage ;;
	esac
done

shift $(($OPTIND - 1))

[ "$#" -eq 0 ] && usage
[ -z "$QUERY" ] && usage

if [ "$QUERY" = '--deps' ] && [ -n "$FULLTREE" ]; then
	QUERY='--fulldeptree --deps'
fi

BRANCH=$(git symbolic-ref -q --short HEAD 2>/dev/null)
if [ -n "$XBPS_HOSTDIR" ]; then
	XBPS_BINPKGS="$XBPS_HOSTDIR/binpkgs"
else
	XBPS_DISTDIR="$(xdistdir 2>/dev/null)" || XBPS_DISTDIR=.
	XBPS_BINPKGS="$XBPS_DISTDIR/hostdir/binpkgs"
fi
REPO="
	--repository=$XBPS_BINPKGS/$BRANCH
	--repository=$XBPS_BINPKGS/$BRANCH/nonfree
	--repository=$XBPS_BINPKGS/$BRANCH/multilib
	--repository=$XBPS_BINPKGS/$BRANCH/multilib/nonfree
	--repository=$XBPS_BINPKGS/$BRANCH/debug
	--repository=$XBPS_BINPKGS
	--repository=$XBPS_BINPKGS/nonfree
	--repository=$XBPS_BINPKGS/multilib
	--repository=$XBPS_BINPKGS/multilib/nonfree
	--repository=$XBPS_BINPKGS/debug
"

pkg="$1"

if xbps-query -MR $pkg >/dev/null; then
	xbps-query -MR $QUERY $pkg | $SORT > "$TMPDIR/${pkg}.repo"
else
	echo "Package '$pkg' not found in repositories" > "$TMPDIR/${pkg}.repo"
fi
# ignore-conf-repos here and not in the actual query
# because --fulldeptree will probably fail without
# being able to read from other repos
if xbps-query --ignore-conf-repos $REPO $pkg >/dev/null; then
	xbps-query $REPO $QUERY $pkg | $SORT > "$TMPDIR/${pkg}.local"
else
	echo "Package '$pkg' not found in local repositories" > "$TMPDIR/${pkg}.local"
fi

if [ -z "$REVERSE" ]; then
	FILE1="${pkg}.repo"
	FILE2="${pkg}.local"
else
	FILE1="${pkg}.local"
	FILE2="${pkg}.repo"
fi

$DIFF $TMPDIR/$FILE1 $TMPDIR/$FILE2

rm -rf $TMPDIR