git-remote: exit with non-zero status after detecting error in "rm".
[gitweb.git] / builtin-name-rev.c
index a639e2feda26b658446719981ac22d6e3adbd3ac..03083e94776234b280316978cd3f638262f41398 100644 (file)
@@ -4,19 +4,24 @@
 #include "tag.h"
 #include "refs.h"
 
+#define CUTOFF_DATE_SLOP 86400 /* one day */
+
 static const char name_rev_usage[] =
        "git-name-rev [--tags | --refs=<pattern>] ( --all | --stdin | committish [committish...] )\n";
 
 typedef struct rev_name {
        const char *tip_name;
-       int merge_traversals;
        int generation;
+       int distance;
 } rev_name;
 
 static long cutoff = LONG_MAX;
 
+/* How many generations are maximally preferred over _one_ merge traversal? */
+#define MERGE_TRAVERSAL_WEIGHT 65535
+
 static void name_rev(struct commit *commit,
-               const char *tip_name, int merge_traversals, int generation,
+               const char *tip_name, int generation, int distance,
                int deref)
 {
        struct rev_name *name = (struct rev_name *)commit->util;
@@ -43,13 +48,11 @@ static void name_rev(struct commit *commit,
                name = xmalloc(sizeof(rev_name));
                commit->util = name;
                goto copy_data;
-       } else if (name->merge_traversals > merge_traversals ||
-                       (name->merge_traversals == merge_traversals &&
-                        name->generation > generation)) {
+       } else if (name->distance > distance) {
 copy_data:
                name->tip_name = tip_name;
-               name->merge_traversals = merge_traversals;
                name->generation = generation;
+               name->distance = distance;
        } else
                return;
 
@@ -72,11 +75,11 @@ static void name_rev(struct commit *commit,
                                sprintf(new_name, "%.*s^%d", len, tip_name,
                                                parent_number);
 
-                       name_rev(parents->item, new_name,
-                               merge_traversals + 1 , 0, 0);
+                       name_rev(parents->item, new_name, 0,
+                               distance + MERGE_TRAVERSAL_WEIGHT, 0);
                } else {
-                       name_rev(parents->item, tip_name, merge_traversals,
-                               generation + 1, 0);
+                       name_rev(parents->item, tip_name, generation + 1,
+                               distance + 1, 0);
                }
        }
 }
@@ -216,6 +219,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
                add_object_array((struct object *)commit, *argv, &revs);
        }
 
+       if (cutoff)
+               cutoff = cutoff - CUTOFF_DATE_SLOP;
        for_each_ref(name_ref, &data);
 
        if (transform_stdin) {
@@ -286,4 +291,3 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 
        return 0;
 }
-