Merge ~cjwatson/launchpad:restore-db-upgrade-outside-vcs into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 275c3fa6e0f0a5fbf2186a5fac65bb540c98061a
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:restore-db-upgrade-outside-vcs
Merge into: launchpad:master
Diff against target: 34 lines (+14/-10)
1 file modified
database/schema/upgrade.py (+14/-10)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+428983@code.launchpad.net

Commit message

Restore support for upgrade.py outside VCS branch

Description of the change

`database/schema/upgrade.py` used to support running outside a VCS branch, in which case it would record the `branch_nick` and `revid` columns of new `LaunchpadDatabaseRevision` columns as NULL. I accidentally dropped this support when removing bzr support from this script in commit 8651d7420e9254733234e84e84933c806521a4fc, but it's still useful to have: in particular, Launchpad trees deployed via charms don't currently have a `.git` directory, but it's handy to be able to run `upgrade.py` from them anyway.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/upgrade.py b/database/schema/upgrade.py
2index 7c139cc..ee21fb1 100755
3--- a/database/schema/upgrade.py
4+++ b/database/schema/upgrade.py
5@@ -286,16 +286,20 @@ def get_vcs_details():
6 """
7 global _vcs_details_cache
8 if _vcs_details_cache is None:
9- branch_nick = subprocess.check_output(
10- ["git", "rev-parse", "--abbrev-ref", "HEAD"],
11- cwd=SCHEMA_DIR,
12- universal_newlines=True,
13- ).rstrip("\n")
14- revision_id = subprocess.check_output(
15- ["git", "rev-parse", "HEAD"],
16- cwd=SCHEMA_DIR,
17- universal_newlines=True,
18- ).rstrip("\n")
19+ top = os.path.dirname(os.path.dirname(SCHEMA_DIR))
20+ if os.path.exists(os.path.join(top, ".git")):
21+ branch_nick = subprocess.check_output(
22+ ["git", "rev-parse", "--abbrev-ref", "HEAD"],
23+ cwd=SCHEMA_DIR,
24+ universal_newlines=True,
25+ ).rstrip("\n")
26+ revision_id = subprocess.check_output(
27+ ["git", "rev-parse", "HEAD"],
28+ cwd=SCHEMA_DIR,
29+ universal_newlines=True,
30+ ).rstrip("\n")
31+ else:
32+ branch_nick, revision_id = None, None
33 _vcs_details_cache = (branch_nick, revision_id)
34 return _vcs_details_cache
35

Subscribers

People subscribed via source and target branches

to status/vote changes: