+ # Add -q so untracked files aren't listed.
+ if [ `$GCC_HG status -q | wc -l` -gt 0 ]; then
+ echo "Attempting to update a dirty hg tree!" >&2
+ echo "Commit or revert your changes first and retry." >&2
+ exit 1
+ fi
+
+ # Check for mq extension. mq patches must be popped so tip has
+ # been converted from the SVN tree.
+ if [ -d .hg/patches ] && [ `$GCC_HG qapplied | wc -l` -gt 0 ]; then
+ # FIXME: Perhaps pop queue instead? We could do that since we
+ # know the tree is clean.
+ echo "Attempting to update hg tree with mq patches applied!" >&2
+ echo "Pop your patches first and retry." >&2
+ exit 1
+ fi
+
+ # Update tree, but make sure to only pull the default branch.
+ # Otherwise all branches in the upstream repo are added, even if
+ # only a single one has been cloned.
+ $GCC_HG pull ${silent+-q} -r`$GCC_HG branch` ${1+"$@"}
+ if [ $? -ne 0 ]; then
+ (touch_files_reexec)
+ echo "hg pull of full tree failed." >&2
+ exit 1
+ fi
+
+ # Update tree. Needs to be done separately from pull so
+ # gcc_update -rREV works.
+ $GCC_HG update ${silent+-q} ${1+"$@"}
+ if [ $? -ne 0 ]; then
+ (touch_files_reexec)
+ echo "hg update of full tree failed." >&2
+ exit 1
+ fi
+
+ # Extract SVN revision corresponding to parents, as stored by
+ # hg convert. Before hg 1.4.3, there's no template keyword
+ # corresponding to the extra: tag, so need to use hg log --debug
+ # to extract the info.
+ parents=`$GCC_HG parents --template '{rev}'`
+ convert_revision=`$GCC_HG log --debug -r$parents | \
+ sed -ne "/^extra:.*convert_revision=svn:/ {
+ s%^[^/]*/%%
+ p
+ }"`
+ revision=`echo $convert_revision | sed -e 's/.*@//'`
+ branch=`echo $convert_revision | sed -e 's%branches/%%' -e 's/@.*//'`
+ ;;
+
+ svn)
+ chat "Updating SVN tree"
+
+ $GCC_SVN ${silent+-q} --non-interactive update ${1+"$@"}
+ if [ $? -ne 0 ]; then
+ (touch_files_reexec)
+ echo "SVN update of full tree failed." >&2
+ exit 1
+ fi
+
+ revision=`$GCC_SVN info | awk '/Revision:/ { print $2 }'`
+ branch=`$GCC_SVN info | sed -ne "/^URL:/ {
+ s,.*/trunk,trunk,
+ s,.*/branches/,,
+ s,.*/tags/,,
+ p
+ }"`
+ ;;
+esac
+
+rm -f LAST_UPDATED gcc/REVISION