contrib/builddeb
author Gregory Szorc <gregory.szorc@gmail.com>
Fri, 24 Mar 2017 19:19:00 -0700
changeset 31765 264baeef3588
parent 29093 c4f0e764b231
child 34625 f1c2552c2de7
permissions -rwxr-xr-x
show: new extension for displaying various repository data Currently, Mercurial has a number of commands to show information. And, there are features coming down the pipe that will introduce more commands for showing information. Currently, when introducing a new class of data or a view that we wish to expose to the user, the strategy is to introduce a new command or overload an existing command, sometimes both. For example, there is a desire to formalize the wip/smartlog/underway/mine functionality that many have devised. There is also a desire to introduce a "topics" concept. Others would like views of "the current stack." In the current model, we'd need a new command for wip/smartlog/etc (that behaves a lot like a pre-defined alias of `hg log`). For topics, we'd likely overload `hg topic[s]` to both display and manipulate topics. Adding new commands for every pre-defined query doesn't scale well and pollutes `hg help`. Overloading commands to perform read-only and write operations is arguably an UX anti-pattern: while having all functionality for a given concept in one command is nice, having a single command doing multiple discrete operations is not. Furthermore, a user may be surprised that a command they thought was read-only actually changes something. We discussed this at the Mercurial 4.0 Sprint in Paris and decided that having a single command where we could hang pre-defined views of various data would be a good idea. Having such a command would: * Help prevent an explosion of new query-related commands * Create a clear separation between read and write operations (mitigates footguns) * Avoids overloading the meaning of commands that manipulate data (bookmark, tag, branch, etc) (while we can't take away the existing behavior for BC reasons, we now won't introduce this behavior on new commands) * Allows users to discover informational views more easily by aggregating them in a single location * Lowers the barrier to creating the new views (since the barrier to creating a top-level command is relatively high) So, this commit introduces the `hg show` command via the "show" extension. This command accepts a positional argument of the "view" to show. New views can be registered with a decorator. To prove it works, we implement the "bookmarks" view, which shows a table of bookmarks and their associated nodes. We introduce a new style to hold everything used by `hg show`. For our initial bookmarks view, the output varies from `hg bookmarks`: * Padding is performed in the template itself as opposed to Python * Revision integers are not shown * shortest() is used to display a 5 character node by default (as opposed to static 12 characters) I chose to implement the "bookmarks" view first because it is simple and shouldn't invite too much bikeshedding that detracts from the evaluation of `hg show` itself. But there is an important point to consider: we now have 2 ways to show a list of bookmarks. I'm not a fan of introducing multiple ways to do very similar things. So it might be worth discussing how we wish to tackle this issue for bookmarks, tags, branches, MQ series, etc. I also made the choice of explicitly declaring the default show template not part of the standard BC guarantees. History has shown that we make mistakes and poor choices with output formatting but can't fix these mistakes later because random tools are parsing output and we don't want to break these tools. Optimizing for human consumption is one of my goals for `hg show`. So, by not covering the formatting as part of BC, the barrier to future change is much lower and humans benefit. There are some improvements that can be made to formatting. For example, we don't yet use label() in the templates. We obviously want this for color. But I'm not sure if we should reuse the existing log.* labels or invent new ones. I figure we can punt that to a follow-up. At the aforementioned Sprint, we discussed and discarded various alternatives to `hg show`. We considered making `hg log <view>` perform this behavior. The main reason we can't do this is because a positional argument to `hg log` can be a file path and if there is a conflict between a path name and a view name, behavior is ambiguous. We could have introduced `hg log --view` or similar, but we felt that required too much typing (we don't want to require a command flag to show a view) and wasn't very discoverable. Furthermore, `hg log` is optimized for showing changelog data and there are things that `hg display` could display that aren't changelog centric. There were concerns about using "show" as the command name. Some users already have a "show" alias that is similar to `hg export`. There were also concerns that Git users adapted to `git show` would be confused by `hg show`'s different behavior. The main difference here is `git show` prints an `hg export` like view of the current commit by default and `hg show` requires an argument. `git show` can also display any Git object. `git show` does not support displaying more complex views: just single objects. If we implemented `hg show <hash>` or `hg show <identifier>`, `hg show` would be a superset of `git show`. Although, I'm hesitant to do that at this time because I view `hg show` as a higher-level querying command and there are namespace collisions between valid identifiers and registered views. There is also a prefix collision with `hg showconfig`, which is an alias of `hg config`. We also considered `hg view`, but that is already used by the "hgk" extension. `hg display` was also proposed at one point. It has a prefix collision with `hg diff`. General consensus was "show" or "view" are the best verbs. And since "view" was taken, "show" was chosen. There are a number of inline TODOs in this patch. Some of these represent decisions yet to be made. Others represent features requiring non-trivial complexity. Rather than bloat the patch or invite additional bikeshedding, I figured I'd document future enhancements via TODO so we can get a minimal implmentation landed. Something is better than nothing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
#!/bin/sh -e
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
#
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
# Build a Mercurial debian package from the current repo
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
# Tested on Jessie (stable as of original script authoring.)
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents: 24971
diff changeset
     7
. $(dirname $0)/packagelib.sh
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents: 24971
diff changeset
     8
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
BUILD=1
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    10
CLEANUP=1
27212
ef9301ce6046 builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents: 27211
diff changeset
    11
DISTID=`(lsb_release -is 2> /dev/null | tr '[:upper:]' '[:lower:]') || echo debian`
ef9301ce6046 builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents: 27211
diff changeset
    12
CODENAME=`lsb_release -cs 2> /dev/null || echo unknown`
28994
8797f03db5b6 builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents: 28993
diff changeset
    13
DEBFLAGS=-b
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
while [ "$1" ]; do
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
    case "$1" in
27210
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27209
diff changeset
    16
    --distid )
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27209
diff changeset
    17
        shift
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27209
diff changeset
    18
        DISTID="$1"
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27209
diff changeset
    19
        shift
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27209
diff changeset
    20
        ;;
27209
7fbab10f812f builddeb: rename --release option to --codename
Anton Shestakov <av6@dwimlabs.net>
parents: 26833
diff changeset
    21
    --codename )
26108
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26090
diff changeset
    22
        shift
27209
7fbab10f812f builddeb: rename --release option to --codename
Anton Shestakov <av6@dwimlabs.net>
parents: 26833
diff changeset
    23
        CODENAME="$1"
26108
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26090
diff changeset
    24
        shift
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26090
diff changeset
    25
        ;;
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    26
    --cleanup )
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
        shift
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
        BUILD=
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
        ;;
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    30
    --build )
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    31
        shift
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    32
        CLEANUP=
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    33
        ;;
28994
8797f03db5b6 builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents: 28993
diff changeset
    34
    --source-only )
8797f03db5b6 builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents: 28993
diff changeset
    35
        shift
8797f03db5b6 builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents: 28993
diff changeset
    36
        DEBFLAGS=-S
8797f03db5b6 builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents: 28993
diff changeset
    37
        ;;
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
    * )
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
        echo "Invalid parameter $1!" 1>&2
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
        exit 1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
        ;;
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
    esac
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
done
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    45
trap "if [ '$CLEANUP' ] ; then rm -r '$PWD/debian' ; fi" EXIT
26108
05306b9359d3 builddeb: rework how output dir and platform are specified
Augie Fackler <augie@google.com>
parents: 26090
diff changeset
    46
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
set -u
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
if [ ! -d .hg ]; then
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
    echo 'You are not inside a Mercurial repository!' 1>&2
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
    exit 1
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
fi
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
24972
56c64c91b429 packaging: extract packagelib for common code from builddeb and buildrpm
Augie Fackler <augie@google.com>
parents: 24971
diff changeset
    54
gethgversion
26833
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
    55
debver="$version"
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
    56
if [ -n "$type" ] ; then
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
    57
    debver="$debver~$type"
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
    58
fi
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
    59
if [ -n "$distance" ] ; then
29045
52f71214efce builddeb: use codename in version
Sean Farley <sean@farley.io>
parents: 28994
diff changeset
    60
    debver="$debver+$distance-$CODENAME-$node"
29093
c4f0e764b231 builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents: 29046
diff changeset
    61
elif [ "$DEBFLAGS" = "-S" ] ; then
c4f0e764b231 builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents: 29046
diff changeset
    62
    # for building a ppa (--source-only) for a release (distance == 0), we need
c4f0e764b231 builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents: 29046
diff changeset
    63
    # to version the distroseries so that we can upload to launchpad
c4f0e764b231 builddeb: add distroseries to tagged versions
Sean Farley <sean@farley.io>
parents: 29046
diff changeset
    64
    debver="$debver~${CODENAME}1"
26833
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
    65
fi
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    66
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    67
control=debian/control
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    68
changelog=debian/changelog
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    69
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    70
if [ "$BUILD" ]; then
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    71
    if [ -d debian ] ; then
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    72
        echo "Error! debian control directory already exists!"
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    73
        exit 1
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    74
    fi
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    75
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    76
    cp -r $PWD/contrib/debian debian
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    77
28988
4f1dac94b53f builddeb: use sed -i
Sean Farley <sean@farley.io>
parents: 27212
diff changeset
    78
    sed -i.tmp "s/__VERSION__/$debver/" $changelog
4f1dac94b53f builddeb: use sed -i
Sean Farley <sean@farley.io>
parents: 27212
diff changeset
    79
    sed -i.tmp "s/__DATE__/$(date --rfc-2822)/" $changelog
28989
a8256e3701be builddeb: use the os codename instead of 'unstable'
Sean Farley <sean@farley.io>
parents: 28988
diff changeset
    80
    sed -i.tmp "s/__CODENAME__/$CODENAME/" $changelog
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    81
    rm $changelog.tmp
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    82
28993
837119bf7f01 builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents: 28992
diff changeset
    83
    # remove the node from the version string
837119bf7f01 builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents: 28992
diff changeset
    84
    SRCFILE="mercurial_$(echo $debver | sed "s,-$node,,").orig.tar.gz"
837119bf7f01 builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents: 28992
diff changeset
    85
    "$PWD/hg" archive $SRCFILE
837119bf7f01 builddeb: create source archive for ubuntu
Sean Farley <sean@farley.io>
parents: 28992
diff changeset
    86
    mv $SRCFILE ..
28994
8797f03db5b6 builddeb: add flag for a source-only deb
Sean Farley <sean@farley.io>
parents: 28993
diff changeset
    87
    debuild -us -uc -i -I $DEBFLAGS
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    88
    if [ $? != 0 ]; then
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    89
        echo 'debuild failed!'
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    90
        exit 1
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    91
    fi
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    92
24971
ab75baaf81d5 builddeb: new script for building a deb package
Augie Fackler <augie@google.com>
parents:
diff changeset
    93
fi
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    94
if [ "$CLEANUP" ] ; then
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    95
    echo
27210
9b86d29867a5 builddeb: add --distid option to specify Distributor ID
Anton Shestakov <av6@dwimlabs.net>
parents: 27209
diff changeset
    96
    OUTPUTDIR=${OUTPUTDIR:=packages/$DISTID-$CODENAME}
27212
ef9301ce6046 builddeb: read default distribution and codename from lsb_release
Anton Shestakov <av6@dwimlabs.net>
parents: 27211
diff changeset
    97
    mkdir -p "$OUTPUTDIR"
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
    98
    find ../mercurial*.deb ../mercurial_*.build ../mercurial_*.changes \
28991
1967c6b714e6 builddeb: copy over .gz and .dsc files
Sean Farley <sean@farley.io>
parents: 28990
diff changeset
    99
          ../mercurial*.dsc ../mercurial*.gz \
28990
62c245c59433 builddeb: ignore errors about find not finding files
Sean Farley <sean@farley.io>
parents: 28989
diff changeset
   100
          -type f -newer $control -print0 2>/dev/null | \
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
   101
      xargs -Inarf -0 mv narf "$OUTPUTDIR"
26833
6474b64045fb packaging: rework version detection and declaration (issue4912)
Augie Fackler <augie@google.com>
parents: 26148
diff changeset
   102
    echo "Built packages for $debver:"
26148
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
   103
    find "$OUTPUTDIR" -type f -newer $control -name '*.deb'
7f49efcaa9b4 debian: switch to using debhelper and dh_python2 to build debs
Augie Fackler <augie@google.com>
parents: 26108
diff changeset
   104
fi