annotate tests/printenv.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 7a7d4937272b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
1 # simple script to be used in hooks
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
2 # copy it to the current directory when the test starts:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
3 #
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
4 # cp "$TESTDIR"/printenv.py .
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
5 #
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
6 # put something like this in the repo .hg/hgrc:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
7 #
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
8 # [hooks]
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
9 # changegroup = python ../printenv.py <hookname> [exit] [output]
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
10 #
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
11 # - <hookname> is a mandatory argument (e.g. "changegroup")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
12 # - [exit] is the exit code of the hook (default: 0)
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
13 # - [output] is the name of the output file (default: use sys.stdout)
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
14 # the file will be opened in append mode.
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
15 #
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
16 import os
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
17 import sys
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
18
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
19 exitcode = 0
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
20 out = sys.stdout
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
21
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
22 name = sys.argv[1]
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
23 if len(sys.argv) > 2:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
24 exitcode = int(sys.argv[2])
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
25 if len(sys.argv) > 3:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
26 out = open(sys.argv[3], "ab")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
27
4643
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
28 # variables with empty values may not exist on all platforms, filter
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
29 # them now for portability sake.
4659
7a7d4937272b Kill trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4643
diff changeset
30 env = [k for k, v in os.environ.iteritems()
4643
a39cec1d5cb8 printenv: filter empty environment variables for portability.
Patrick Mezard <pmezard@gmail.com>
parents: 4285
diff changeset
31 if k.startswith("HG_") and v]
4285
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
32 env.sort()
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
33
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
34 # edit the variable part of the variable
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
35 url = os.environ.get("HG_URL", "")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
36 if url.startswith("file:"):
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
37 os.environ["HG_URL"] = "file:"
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
38 elif url.startswith("remote:http"):
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
39 os.environ["HG_URL"] = "remote:http"
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
40
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
41 out.write("%s hook: " % name)
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
42 for v in env:
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
43 out.write("%s=%s " % (v, os.environ[v]))
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
44 out.write("\n")
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
45 out.close()
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
46
4fd6f7e60894 Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
47 sys.exit(exitcode)