bug 466149 - pushlog hook should check that database schema actually exists
authorTed Mielczarek <ted.mielczarek@gmail.com>
Fri, 21 Nov 2008 07:36:00 -0500
changeset 359103 2948ef619de035473d47514dba81f15148a6f988
parent 359102 4968e9e946720e5f0363ad3dcd14dbfc4492a6af
child 359104 1ca9d5febb5a533975a5beb6b2470b06ef80b291
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
bugs466149
bug 466149 - pushlog hook should check that database schema actually exists
hghooks/mozhghooks/pushlog.py
hghooks/test-hook.sh
--- a/hghooks/mozhghooks/pushlog.py
+++ b/hghooks/mozhghooks/pushlog.py
@@ -23,22 +23,27 @@ def createpushdb(conn):
     conn.execute("CREATE TABLE IF NOT EXISTS changesets (pushid INTEGER, rev INTEGER, node text)")
     conn.execute("CREATE TABLE IF NOT EXISTS pushlog (id INTEGER PRIMARY KEY AUTOINCREMENT, user TEXT, date INTEGER)")
     conn.execute("CREATE UNIQUE INDEX IF NOT EXISTS changeset_node ON changesets (node)")
     conn.execute("CREATE UNIQUE INDEX IF NOT EXISTS changeset_rev ON changesets (rev)")
     conn.execute("CREATE INDEX IF NOT EXISTS pushlog_date ON pushlog (date)")
     conn.execute("CREATE INDEX IF NOT EXISTS pushlog_user ON pushlog (user)")
     conn.commit()
 
+def schemaexists(conn):
+    return 1 == conn.execute("SELECT COUNT(*) FROM SQLITE_MASTER WHERE name='pushlog'").fetchone()[0]
+
 def log(ui, repo, node, **kwargs):
     pushdb = os.path.join(repo.path, 'pushlog2.db')
     createdb = False
     if not os.path.exists(pushdb):
         createdb = True
     conn = sqlite.connect(pushdb)
+    if not createdb and not schemaexists(conn):
+        createdb = True
     if createdb:
         createpushdb(conn)
         st = os.stat(pushdb)
         os.chmod(pushdb, st.st_mode | stat.S_IWGRP)
     t = int(time.time())
     res = conn.execute("INSERT INTO pushlog (user, date) values(?,?)",
                        (os.environ['USER'], t))
     pushid = res.lastrowid
--- a/hghooks/test-hook.sh
+++ b/hghooks/test-hook.sh
@@ -69,9 +69,22 @@ fi
 
 if [[ `stat -f %Sp $REPO/.hg/pushlog2.db | sed -e "s/^....\(..\).*$/\1/"` != "rw" ]]; then
     echo "FAIL: pushlog db is not group writeable!"
     exit 1;
 else
     echo "PASS: pushlog db is group writeable!"
 fi
 
+# Test that an empty db file doesn't break the hook - bug 466149
+rm $REPO/.hg/pushlog2.db
+touch $REPO/.hg/pushlog2.db
+
+echo "another checkin" >> $CLONE/testfile
+hg ci -R $CLONE -m "another checkin"
+if hg push -R $CLONE $REPO; then
+    echo "PASS: push to empty db succeeded"
+else
+    echo "FAIL: failed to push to repo with empty db"
+    exit 1;
+fi
+
 echo "Passed all tests!"