aboutsummaryrefslogtreecommitdiff
path: root/libexec/find-base-commits.sh
blob: 3e162271c302be0e155eb09c94591d1b8e2343dc (plain)
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
#!/bin/bash

extend_bases () {
  shas="$1"
  new="$2"
  for sha in $shas ; do
    [ "$sha" = "$new" ] && continue
    ${DELI_GIT_IS_ANCESTOR_CMD:-git merge-base --is-ancestor} "$sha" "$new"
    res=$?
    case $res in
    0) ;;
    1) echo "$sha" ;;
    *) echo "$0: ancestor finding failed" >&2
       exit 1 ;;
    esac
  done
  old=no
  for sha in $shas ; do
    [ "$sha" = "$new" ] && continue
    ${DELI_GIT_IS_ANCESTOR_CMD:-git merge-base --is-ancestor} "$new" "$sha"
    res=$?
    case $res in
    0) old=yes ; break ;;
    1) ;;
    *) echo "$0: ancestor finding failed" >&2
       exit 1 ;;
    esac
  done
  [ $old = no ] && echo "$new"
}

bases=""

while read sha ; do
  bases=$( extend_bases "$bases" "$sha" )
done

for sha in $bases ; do
  echo "$sha"
done