Mercurial > hg
annotate contrib/fixpax.py @ 33453:f6b7617a85bb
phases: add a 'registernew' method to set new phases
This new function will be used by code that adds new changesets. It ajusts the
phase boundary to make sure added changesets are at least in their target
phase (they end up in an higher phase if their parents are in a higher phase).
Having a dedicated function also simplify the phases tracking. All the new
nodes are passed as argument, so we know that all of them needs to have their
new phase registered. We also know that no other nodes will be affected, so no
extra computation are needed.
This function differ from 'retractboundary' where some nodes might change
phase while some other might not. It can also affect nodes not passed as
parameters.
These simplification also apply to the computation itself. For now we use
'_retractboundary' there by convenience, but we may introduces simpler code
later.
While registering new revisions, we still need to check the actual phases of
the added node because it might be higher than the target phase (eg: target is
draft but parent is secret).
We will migrate users over the next changesets.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Tue, 11 Jul 2017 03:47:25 +0200 |
parents | 00f317788d33 |
children |
rev | line source |
---|---|
27495
58eb1c5bba58
contrib: add execute bit for fixpax.py
timeless <timeless@mozdev.org>
parents:
23940
diff
changeset
|
1 #!/usr/bin/env python |
23940
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
2 # fixpax - fix ownership in bdist_mpkg output |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
3 # |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
4 # Copyright 2015 Matt Mackall <mpm@selenic.com> |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
5 # |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
7 # MIT license (http://opensource.org/licenses/MIT) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
8 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
9 """Set file ownership to 0 in an Archive.pax.gz. |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
10 Suitable for fixing files bdist_mpkg output: |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
11 *.mpkg/Contents/Packages/*.pkg/Contents/Archive.pax.gz |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
12 """ |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
13 |
28354
00f317788d33
fixpax: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27495
diff
changeset
|
14 from __future__ import absolute_import, print_function |
00f317788d33
fixpax: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27495
diff
changeset
|
15 import gzip |
00f317788d33
fixpax: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27495
diff
changeset
|
16 import os |
00f317788d33
fixpax: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27495
diff
changeset
|
17 import sys |
23940
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
18 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
19 def fixpax(iname, oname): |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
20 i = gzip.GzipFile(iname) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
21 o = gzip.GzipFile(oname, "w") |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
22 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
23 while True: |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
24 magic = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
25 dev = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
26 ino = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
27 mode = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
28 i.read(6) # uid |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
29 i.read(6) # gid |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
30 nlink = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
31 rdev = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
32 mtime = i.read(11) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
33 namesize = i.read(6) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
34 filesize = i.read(11) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
35 name = i.read(int(namesize, 8)) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
36 data = i.read(int(filesize, 8)) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
37 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
38 o.write(magic) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
39 o.write(dev) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
40 o.write(ino) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
41 o.write(mode) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
42 o.write("000000") |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
43 o.write("000000") |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
44 o.write(nlink) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
45 o.write(rdev) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
46 o.write(mtime) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
47 o.write(namesize) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
48 o.write(filesize) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
49 o.write(name) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
50 o.write(data) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
51 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
52 if name.startswith("TRAILER!!!"): |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
53 o.write(i.read()) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
54 break |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
55 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
56 o.close() |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
57 i.close() |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
58 |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
59 if __name__ == '__main__': |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
60 for iname in sys.argv[1:]: |
28354
00f317788d33
fixpax: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27495
diff
changeset
|
61 print('fixing file ownership in %s' % iname) |
23940
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
62 oname = sys.argv[1] + '.tmp' |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
63 fixpax(iname, oname) |
d0ef40776999
osx: patch .pax.gz files in pkg bundles so they extract as root (issue4081)
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
64 os.rename(oname, iname) |