summaryrefslogtreecommitdiff
path: root/update-common
blob: 49efd37c2ba6651dc4713b76bfd3583407c6490f (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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
#
# This script will update all the modules listed below so that
# common points to master in the common module.
#
# If you have many of the GStreamer modules checked out in a particular
# directory, it's best to run this script from that directory.  For
# example, I check everything out in ~/gst, so this file is
# ~/gst/common/update-common.  To do an update, I do
# 'cd ~/gst ; ./common/update-common'.  This will automatically use
# the refs in your existing checkout when cloning the temporary
# checkout.  Alternatively, you can use the reference variable below.
#
# Options:
#
#   --dry-run : pass --dry-run to git push, don't actually push the changes
#   --keep    : keep temporary checkouts around instead of deleting them

# Set this variable to point to any directory containing existing
# git # checkouts, and git will pull objects from there, decreasing
# network usage.
BRANCH=master
reference=~/gst
PUSHURL=git@gitlab.freedesktop.org:gstreamer
DRY_RUN=
KEEP=no
COMMON_COMMIT=

set -e
set -x

modules="gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad \
	gst-plugins-ugly gst-libav gst-omx gstreamer-vaapi \
	gst-rtsp-server gst-editing-services"

topdir=`pwd`
dir=`mktemp -d $topdir/common-update-XXXXXX`

# process command line arguments
set +x
for arg in $@
do
  case $arg in
    --dry-run)
      DRY_RUN="--dry-run";
      ;;
    --keep)
      KEEP="yes";
      ;;
    --commit=*)
      COMMON_COMMIT="${arg#*=}";
      DRY_RUN="--dry-run";
      KEEP="yes";
      ;;
    --help)
      echo
      echo "update-common supported command line options:"
      echo
      echo " --dry-run   Don't actually push changes to the repository, use git push --dry-run"
      echo
      echo " --keep      Don't delete temporary git checkout used for update operation, keep it around"
      echo
      echo " --commit=REF  Update common to commit reference REF (for local testing, implies --dry-run --keep)"
      echo
      exit 0;
      ;;
    *)
      echo "Unknown command line argument $arg"
      echo "Supported: --dry-run, --keep"
      exit 1;
      ;;
  esac
done
set -x

# create temporary checkouts of the modules
for module in $modules
do
  cd $dir
  if test -e $reference/$module/.git ; then
    git clone --reference $reference/$module/.git --shared git@gitlab.freedesktop.org:gstreamer/$module.git
  elif test -e $topdir/$module/.git ; then
    git clone --reference $topdir/$module/.git --shared $PUSHURL/$module.git
  else
    git clone $PUSHURL/$module.git
  fi
  cd $dir/$module

  # ignore modules that don't have such a branch
  if ! git show-ref origin/$BRANCH >/dev/null; then
    continue;
  fi

  if test $BRANCH = 'master'; then
    git checkout $BRANCH
  else
    git checkout -b $BRANCH origin/$BRANCH
  fi

  git submodule init

  # avoid downloading common submodule by re-using existing common checkout
  if test -e $reference/common/.git ; then
    git submodule update --reference $reference/common -- common
  elif test -e $topdir/common/.git ; then
    git submodule update --reference $topdir/common -- common
  else
    git submodule update
  fi

  # avoid downloading libav submodule by re-using existing checkout
  if test "$module" = "gst-libav"; then
    if test -e $reference/gst-libav/gst-libs/ext/libav/.git ; then
      git submodule update --reference $reference/gst-libav/gst-libs/ext/libav -- gst-libs/ext/libav
    elif test -e $topdir/gst-libav/gst-libs/ext/libav/.git ; then
      git submodule update --reference $topdir/gst-libav/gst-libs/ext/libav/ -- gst-libs/ext/libav
    else
      git submodule update
    fi
  fi

  # for good measure in case there are any other submodules anywhere
  git submodule update

  cd $dir/$module/common
  ref_from=`git log --pretty=format:%h -n 1 HEAD`
  if test $BRANCH = 'master'; then
    git checkout $BRANCH
  else
    git checkout -b $BRANCH origin/$BRANCH
  fi
  git pull origin
  if [ -n "$COMMON_COMMIT" ] ; then
    echo "Forcing common to commit $COMMON_COMMIT";
    git reset --hard $COMMON_COMMIT || {
      echo "Failed to git reset to $COMMON_COMMIT";
      exit 1;
    }
  fi
  ref_to=`git log --pretty=format:%h -n 1 HEAD`
  echo updating common from $ref_from to $ref_to
  if [ "$ref_from" != "$ref_to" ] ; then
    cd $dir/$module
    # update autogen.sh for selected modules
    case $module in
      gstreamer|gst-plugins-base|gst-plugins-good|gst-plugins-ugly|gst-plugins-bad|gst-libav|gst-editing-services|gst-rtsp-server|gst-omx )
        ./common/update-autogen
        git add autogen.sh
        ;;
      *)
        ;;
    esac
    # update README and MAINTAINERS for selected modules
    case $module in
      gstreamer|gst-plugins-base|gst-plugins-good|gst-plugins-ugly|gst-plugins-bad )
        ./common/update-readmes --run-git-add
        ;;
      *)
        ;;
    esac
    # and finally update the common submodule
    git add common
    git commit -m "Automatic update of common submodule

From $ref_from to $ref_to"
  fi
  cd $dir
done

for module in $modules
do
  cd $dir/$module
  if git show-ref origin/$BRANCH >/dev/null; then
    git push $DRY_RUN origin $BRANCH
  fi
done

# delete temporary checkouts again
if test "x$KEEP" != "xyes"; then
  rm -rf $dir
fi