4
#include "tag.h"
5
#include "refs.h"
6
#include "parse-options.h"
7
+#include "sha1-lookup.h"
8
9
#define CUTOFF_DATE_SLOP 86400 /* one day */
10
114
const char *ref_filter;
115
};
116
117
+static struct tip_table {
118
+ struct tip_table_entry {
119
+ unsigned char sha1[20];
120
+ const char *refname;
121
+ } *table;
122
+ int nr;
123
+ int alloc;
124
+ int sorted;
125
+} tip_table;
126
+
127
+static void add_to_tip_table(const unsigned char *sha1, const char *refname,
128
+ int shorten_unambiguous)
129
+{
130
+ refname = name_ref_abbrev(refname, shorten_unambiguous);
131
+
132
+ ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc);
133
+ hashcpy(tip_table.table[tip_table.nr].sha1, sha1);
134
+ tip_table.table[tip_table.nr].refname = xstrdup(refname);
135
+ tip_table.nr++;
136
+ tip_table.sorted = 0;
137
+}
138
+
139
+static int tipcmp(const void *a_, const void *b_)
140
+{
141
+ const struct tip_table_entry *a = a_, *b = b_;
142
+ return hashcmp(a->sha1, b->sha1);
143
+}
144
+
145
static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
146
{
147
struct object *o = parse_object(sha1);
164
}
165
}
166
167
+ add_to_tip_table(sha1, path, can_abbreviate_output);
168
+
169
while (o && o->type == OBJ_TAG) {
170
struct tag *t = (struct tag *) o;
171
if (!t->tagged)
182
return 0;
183
}
184
185
+static const unsigned char *nth_tip_table_ent(size_t ix, void *table_)
186
+{
187
+ struct tip_table_entry *table = table_;
188
+ return table[ix].sha1;
189
+}
190
+
191
+static const char *get_exact_ref_match(const struct object *o)
192
+{
193
+ int found;
194
+
195
+ if (!tip_table.table || !tip_table.nr)
196
+ return NULL;
197
+
198
+ if (!tip_table.sorted) {
199
+ qsort(tip_table.table, tip_table.nr, sizeof(*tip_table.table),
200
+ tipcmp);
201
+ tip_table.sorted = 1;
202
+ }
203
+
204
+ found = sha1_pos(o->sha1, tip_table.table, tip_table.nr,
205
+ nth_tip_table_ent);
206
+ if (0 <= found)
207
+ return tip_table.table[found].refname;
208
+ return NULL;
209
+}
210
+
211
/* returns a static buffer */
212
static const char *get_rev_name(const struct object *o)
213
{
216
struct commit *c;
217
218
if (o->type != OBJ_COMMIT)
162
- return NULL;
219
+ return get_exact_ref_match(o);
220
c = (struct commit *) o;
221
n = c->util;
222
if (!n)