Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/version.py @ 5192:33015dac5df5
convert: fix mercurial_sink.putcommit
Changeset 4ebc8693ce72 added some code to putcommit to avoid creating a
revision that touches no files, but this can break regular conversions
from some repositories:
- conceptually, since we're converting a repo, we should try to make
the new hg repo as similar as possible to the original repo - we
should create a new changeset, even if the original revision didn't
touch any files (maybe the commit message had some important bit);
- even if a "regular" revision that doesn't touch any file may seem
weird (and maybe even broken), it's completely legitimate for a merge
revision to not touch any file, and, if we just skip it, the
converted repo will end up with wrong history and possibly an extra
head.
As an example, say the crew and main hg repos are sync'ed. Somebody
sends an important patch to the mailing list. Matt quickly applies
and pushes it. But at the same time somebody also applies it to crew
and pushes it. Suppose the commit message ended up being a bit
different (say, there was a typo and somebody didn't fix it) or that
the date ended up being different (because of different patch-applying
scripts): the changeset hashes will be different, but the manifests
will be the same.
Since both changesets were pushed to public repos, it's hard to recall
them. If both are merged, the manifest from the resulting merge
revision will have the exact same contents as its parents - i.e. the
merge revision really doesn't touch any file at all.
To keep the file filtering stuff "working", the generic code was changed
to skip empty revisions if we're filtering the repo, fixing a bug in the
process (we want parents[0] instead of tip).
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Fri, 17 Aug 2007 20:18:05 -0300 |
parents | cff3e4b4a8de |
children |
rev | line source |
---|---|
2858 | 1 # Copyright (C) 2005, 2006 by Intevation GmbH |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
2 # Author(s): |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
3 # Thomas Arendsen Hein <thomas@intevation.de> |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
4 # |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
5 # This program is free software under the GNU GPL (>=v2) |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
6 # Read the file COPYING coming with the software for details. |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
7 |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
8 """ |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
9 Mercurial version |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
10 """ |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
11 |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
12 import os |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
13 import os.path |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
14 import re |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
15 import time |
461 | 16 import util |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
17 |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
18 unknown_version = 'unknown' |
425
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
19 remembered_version = False |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
20 |
4066
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
21 def get_version(doreload=False): |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
22 """Return version information if available.""" |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
23 try: |
4066
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
24 import mercurial.__version__ |
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
25 if doreload: |
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
26 reload(mercurial.__version__) |
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
27 version = mercurial.__version__.version |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
28 except ImportError: |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
29 version = unknown_version |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
30 return version |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
31 |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
32 def write_version(version): |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
33 """Overwrite version file.""" |
1977
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
34 if version == get_version(): |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
35 return |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
36 directory = os.path.dirname(__file__) |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
37 for suffix in ['py', 'pyc', 'pyo']: |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
38 try: |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
39 os.unlink(os.path.join(directory, '__version__.%s' % suffix)) |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
40 except OSError: |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
41 pass |
7eb694a1c1af
Don't forget version at the end of setup.py, write it only if changed.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
464
diff
changeset
|
42 f = open(os.path.join(directory, '__version__.py'), 'w') |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
43 f.write("# This file is auto-generated.\n") |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
44 f.write("version = %r\n" % version) |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
45 f.close() |
4066
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
46 # reload the file we've just written |
cff3e4b4a8de
setup.py: reload __version__.py after writing it.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2858
diff
changeset
|
47 get_version(True) |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
48 |
427
36e644d28edf
Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
425
diff
changeset
|
49 def remember_version(version=None): |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
50 """Store version information.""" |
425
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
51 global remembered_version |
427
36e644d28edf
Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
425
diff
changeset
|
52 if not version and os.path.isdir(".hg"): |
461 | 53 f = os.popen("hg identify 2> %s" % util.nulldev) # use real hg installation |
425
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
54 ident = f.read()[:-1] |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
55 if not f.close() and ident: |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
56 ids = ident.split(' ', 1) |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
57 version = ids.pop(0) |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
58 if version[-1] == '+': |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
59 version = version[:-1] |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
60 modified = True |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
61 else: |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
62 modified = False |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
63 if version.isalnum() and ids: |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
64 for tag in ids[0].split('/'): |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
65 # is a tag is suitable as a version number? |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
66 if re.match(r'^(\d+\.)+[\w.-]+$', tag): |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
67 version = tag |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
68 break |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
69 if modified: |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
70 version += time.strftime('+%Y%m%d') |
427
36e644d28edf
Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
425
diff
changeset
|
71 if version: |
36e644d28edf
Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
425
diff
changeset
|
72 remembered_version = True |
36e644d28edf
Make it possible to specify a version number in setup.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
425
diff
changeset
|
73 write_version(version) |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
74 |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
75 def forget_version(): |
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
76 """Remove version information.""" |
425
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
77 if remembered_version: |
719663b7f235
remember_version() only writes version if called in a Mercurial repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
423
diff
changeset
|
78 write_version(unknown_version) |
423
25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
79 |