move duplicated ref_newer() to remote.c
ref_newer() appears to have been copied from builtin-send-pack.c to http-push.c via cut and paste. This patch moves the function and its helper unmark_and_free() to remote.c. There was a slight difference between the two implementations, one used TMP_MARK for the mark, the other used 1. Per Jeff King, I went with TMP_MARK as more correct. This is in preparation for being able to call it from builtin-remote.c Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jay Soffian committed
Feb 25, 2009 at 03:32 UTC
ec8452d5a797fca865666f761b785b04212426fc
4 files changed
+50
-99
builtin-send-pack.c
-50
@@ -1,6 +1,5 @@
1
#include "cache.h"
2
#include "commit.h"
3
-#include "tag.h"
3
#include "refs.h"
4
#include "pkt-line.h"
5
#include "run-command.h"
@@ -84,55 +83,6 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
83
return 0;
84
}
85
87
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
88
-{
89
- while (list) {
90
- struct commit_list *temp = list;
91
- temp->item->object.flags &= ~mark;
92
- list = temp->next;
93
- free(temp);
94
- }
95
-}
96
-
97
-static int ref_newer(const unsigned char *new_sha1,
98
- const unsigned char *old_sha1)
99
-{
100
- struct object *o;
101
- struct commit *old, *new;
102
- struct commit_list *list, *used;
103
- int found = 0;
104
-
105
- /* Both new and old must be commit-ish and new is descendant of
106
- * old. Otherwise we require --force.
107
- */
108
- o = deref_tag(parse_object(old_sha1), NULL, 0);
109
- if (!o || o->type != OBJ_COMMIT)
110
- return 0;
111
- old = (struct commit *) o;
112
-
113
- o = deref_tag(parse_object(new_sha1), NULL, 0);
114
- if (!o || o->type != OBJ_COMMIT)
115
- return 0;
116
- new = (struct commit *) o;
117
-
118
- if (parse_commit(new) < 0)
119
- return 0;
120
-
121
- used = list = NULL;
122
- commit_list_insert(new, &list);
123
- while (list) {
124
- new = pop_most_recent_commit(&list, 1);
125
- commit_list_insert(new, &used);
126
- if (new == old) {
127
- found = 1;
128
- break;
129
- }
130
- }
131
- unmark_and_free(list, 1);
132
- unmark_and_free(used, 1);
133
- return found;
134
-}
135
-
86
static struct ref *remote_refs, **remote_tail;
87
88
static int receive_status(int in, struct ref *refs)
http-push.c
-49
@@ -1843,55 +1843,6 @@ static int is_zero_sha1(const unsigned char *sha1)
1843
return 1;
1844
}
1845
1846
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
1847
-{
1848
- while (list) {
1849
- struct commit_list *temp = list;
1850
- temp->item->object.flags &= ~mark;
1851
- list = temp->next;
1852
- free(temp);
1853
- }
1854
-}
1855
-
1856
-static int ref_newer(const unsigned char *new_sha1,
1857
- const unsigned char *old_sha1)
1858
-{
1859
- struct object *o;
1860
- struct commit *old, *new;
1861
- struct commit_list *list, *used;
1862
- int found = 0;
1863
-
1864
- /* Both new and old must be commit-ish and new is descendant of
1865
- * old. Otherwise we require --force.
1866
- */
1867
- o = deref_tag(parse_object(old_sha1), NULL, 0);
1868
- if (!o || o->type != OBJ_COMMIT)
1869
- return 0;
1870
- old = (struct commit *) o;
1871
-
1872
- o = deref_tag(parse_object(new_sha1), NULL, 0);
1873
- if (!o || o->type != OBJ_COMMIT)
1874
- return 0;
1875
- new = (struct commit *) o;
1876
-
1877
- if (parse_commit(new) < 0)
1878
- return 0;
1879
-
1880
- used = list = NULL;
1881
- commit_list_insert(new, &list);
1882
- while (list) {
1883
- new = pop_most_recent_commit(&list, TMP_MARK);
1884
- commit_list_insert(new, &used);
1885
- if (new == old) {
1886
- found = 1;
1887
- break;
1888
- }
1889
- }
1890
- unmark_and_free(list, TMP_MARK);
1891
- unmark_and_free(used, TMP_MARK);
1892
- return found;
1893
-}
1894
-
1846
static void add_remote_info_ref(struct remote_ls_ctx *ls)
1847
{
1848
struct strbuf *buf = (struct strbuf *)ls->userData;
remote.c
+49
@@ -5,6 +5,7 @@
5
#include "diff.h"
6
#include "revision.h"
7
#include "dir.h"
8
+#include "tag.h"
9
10
static struct refspec s_tag_refspec = {
11
0,
@@ -1269,6 +1270,54 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
1270
return 1;
1271
}
1272
1273
+static void unmark_and_free(struct commit_list *list, unsigned int mark)
1274
+{
1275
+ while (list) {
1276
+ struct commit_list *temp = list;
1277
+ temp->item->object.flags &= ~mark;
1278
+ list = temp->next;
1279
+ free(temp);
1280
+ }
1281
+}
1282
+
1283
+int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
1284
+{
1285
+ struct object *o;
1286
+ struct commit *old, *new;
1287
+ struct commit_list *list, *used;
1288
+ int found = 0;
1289
+
1290
+ /* Both new and old must be commit-ish and new is descendant of
1291
+ * old. Otherwise we require --force.
1292
+ */
1293
+ o = deref_tag(parse_object(old_sha1), NULL, 0);
1294
+ if (!o || o->type != OBJ_COMMIT)
1295
+ return 0;
1296
+ old = (struct commit *) o;
1297
+
1298
+ o = deref_tag(parse_object(new_sha1), NULL, 0);
1299
+ if (!o || o->type != OBJ_COMMIT)
1300
+ return 0;
1301
+ new = (struct commit *) o;
1302
+
1303
+ if (parse_commit(new) < 0)
1304
+ return 0;
1305
+
1306
+ used = list = NULL;
1307
+ commit_list_insert(new, &list);
1308
+ while (list) {
1309
+ new = pop_most_recent_commit(&list, TMP_MARK);
1310
+ commit_list_insert(new, &used);
1311
+ if (new == old) {
1312
+ found = 1;
1313
+ break;
1314
+ }
1315
+ }
1316
+ unmark_and_free(list, TMP_MARK);
1317
+ unmark_and_free(used, TMP_MARK);
1318
+ return found;
1319
+}
1320
+
1321
/*
1322
* Return true if there is anything to report, otherwise false.
1323
*/
remote.h
+1
@@ -74,6 +74,7 @@ int check_ref_type(const struct ref *ref, int flags);
74
void free_refs(struct ref *ref);
75
76
int resolve_remote_symref(struct ref *ref, struct ref *list);
77
+int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
78
79
/*
80
* Removes and frees any duplicate refs in the map.