Undefine Zuul variables in Ansible when appropriate

When variables such as branch, tag, oldrev, and newrev are not
applicable, ensure that they are not defined at all as Ansible
variables.

Update the documentation to be more clear on oldrev and newrev.

Change-Id: I56d9a6496467de2f328eb9a43cc52c5f7ef73310
diff --git a/doc/source/user/jobs.rst b/doc/source/user/jobs.rst
index aad43d7..a367aa0 100644
--- a/doc/source/user/jobs.rst
+++ b/doc/source/user/jobs.rst
@@ -229,12 +229,12 @@
 **zuul.oldrev**
   If the item was enqueued as the result of a change merging or being
   pushed to the branch, the git sha of the old revision will be
-  included here.  Otherwise, this value will not be present.
+  included here.  Otherwise, this variable will be undefined.
 
 **zuul.newrev**
   If the item was enqueued as the result of a change merging or being
   pushed to the branch, the git sha of the new revision will be
-  included here.  Otherwise, this value will not be present.
+  included here.  Otherwise, this variable will be undefined.
 
 Tag Items
 +++++++++
@@ -247,14 +247,16 @@
   The name of the item's tag (without the `refs/tags/` prefix).
 
 **zuul.oldrev**
-  If the item was enqueued as the result of a tag being created or
-  deleted the git sha of the old revision will be included here.
-  Otherwise, this value will not be present.
+  If the item was enqueued as the result of a tag being deleted, the
+  previous git sha of the tag will be included here.  If the tag was
+  created, this will be set to the value
+  0000000000000000000000000000000000000000.
 
 **zuul.newrev**
-  If the item was enqueued as the result of a tag being created or
-  deleted the git sha of the new revision will be included here.
-  Otherwise, this value will not be present.
+  If the item was enqueued as the result of a tag being created, the
+  new git sha of the tag will be included here.  If the tag was
+  deleted, this will be set to the value
+  0000000000000000000000000000000000000000.
 
 Ref Items
 +++++++++
@@ -265,14 +267,16 @@
 available:
 
 **zuul.oldrev**
-  If the item was enqueued as the result of a ref being created,
-  deleted, or changed the git sha of the old revision will be included
-  here.  Otherwise, this value will not be present.
+  If the item was enqueued as the result of a ref being deleted, the
+  previous git sha of the ref will be included here.  If the ref was
+  created, this will be set to the value
+  0000000000000000000000000000000000000000.
 
 **zuul.newrev**
-  If the item was enqueued as the result of a ref being created,
-  deleted, or changed the git sha of the new revision will be included
-  here.  Otherwise, this value will not be present.
+  If the item was enqueued as the result of a ref being created, the
+  new git sha of the ref will be included here.  If the ref was
+  deleted, this will be set to the value
+  0000000000000000000000000000000000000000.
 
 Working Directory
 +++++++++++++++++
diff --git a/zuul/executor/client.py b/zuul/executor/client.py
index 52cc403..beb8964 100644
--- a/zuul/executor/client.py
+++ b/zuul/executor/client.py
@@ -171,9 +171,9 @@
             zuul_params['change'] = item.change.number
         if hasattr(item.change, 'patchset'):
             zuul_params['patchset'] = item.change.patchset
-        if hasattr(item.change, 'oldrev'):
+        if hasattr(item.change, 'oldrev') and item.change.oldrev:
             zuul_params['oldrev'] = item.change.oldrev
-        if hasattr(item.change, 'newrev'):
+        if hasattr(item.change, 'newrev') and item.change.newrev:
             zuul_params['newrev'] = item.change.newrev
         zuul_params['items'] = []
         for i in all_items: