On Thu, May 10, 2018 at 12:03:22PM -0400, Jeff King wrote:

> But some cases _don't_ issue an error. For example, try this:
> 
>   $ git log ..06faf
> 
> which returns an empty output! We return the single matching tree, even
> though the ".." triggers the commit hint. The revision machinery just
> queues the tree, and then later when we see we're not doing an --objects
> traversal, it just gets ignored. (That's a separate issue, but it shows
> that the hints are just that: hints. The code that runs after does not
> necessarily require a matching type).

I actually have a patch that generates a warning for this case (below).
I've been running with it for about a year, but it annoyingly produces
warnings for "git log --all":

  $ git log --all
  warning: ignoring blob object in traversal: refs/tags/junio-gpg-pub

I guess ideally it would distinguish between items added explicitly and
those added by a wildcard (or perhaps the wildcard adder should be more
careful about adding useless objects).

---
diff --git a/revision.c b/revision.c
index 1cff11833e..816d6b75ee 100644
--- a/revision.c
+++ b/revision.c
@@ -215,6 +215,16 @@ void add_pending_oid(struct rev_info *revs, const char 
*name,
        add_pending_object(revs, object, name);
 }
 
+static void warn_ignored_object(struct object *object, const char *name)
+{
+       if (object->flags & UNINTERESTING)
+               return;
+
+       warning(_("ignoring %s object in traversal: %s"),
+               type_name(object->type),
+               (name && *name) ? name : oid_to_hex(&object->oid));
+}
+
 static struct commit *handle_commit(struct rev_info *revs,
                                    struct object_array_entry *entry)
 {
@@ -272,8 +282,10 @@ static struct commit *handle_commit(struct rev_info *revs,
         */
        if (object->type == OBJ_TREE) {
                struct tree *tree = (struct tree *)object;
-               if (!revs->tree_objects)
+               if (!revs->tree_objects) {
+                       warn_ignored_object(object, name);
                        return NULL;
+               }
                if (flags & UNINTERESTING) {
                        mark_tree_contents_uninteresting(tree);
                        return NULL;
@@ -286,8 +298,10 @@ static struct commit *handle_commit(struct rev_info *revs,
         * Blob object? You know the drill by now..
         */
        if (object->type == OBJ_BLOB) {
-               if (!revs->blob_objects)
+               if (!revs->blob_objects) {
+                       warn_ignored_object(object, name);
                        return NULL;
+               }
                if (flags & UNINTERESTING)
                        return NULL;
                add_pending_object_with_path(revs, object, name, mode, path);

Reply via email to