96
return 0;
97
}
98
99
+static int note2mark_cb(const unsigned char *object_sha1,
100
+ const unsigned char *note_sha1, char *note_path,
101
+ void *cb_data)
102
+{
103
+ FILE *file = (FILE *)cb_data;
104
+ char *msg;
105
+ unsigned long msglen;
106
+ enum object_type type;
107
+ struct rev_note note;
108
+
109
+ if (!(msg = read_sha1_file(note_sha1, &type, &msglen)) ||
110
+ !msglen || type != OBJ_BLOB) {
111
+ free(msg);
112
+ return 1;
113
+ }
114
+ if (parse_rev_note(msg, ¬e))
115
+ return 2;
116
+ if (fprintf(file, ":%d %s\n", note.rev_nr, sha1_to_hex(object_sha1)) < 1)
117
+ return 3;
118
+ return 0;
119
+}
120
+
121
+static void regenerate_marks(void)
122
+{
123
+ int ret;
124
+ FILE *marksfile = fopen(marksfilename, "w+");
125
+
126
+ if (!marksfile)
127
+ die_errno("Couldn't create mark file %s.", marksfilename);
128
+ ret = for_each_note(NULL, 0, note2mark_cb, marksfile);
129
+ if (ret)
130
+ die("Regeneration of marks failed, returned %d.", ret);
131
+ fclose(marksfile);
132
+}
133
+
134
+static void check_or_regenerate_marks(int latestrev)
135
+{
136
+ FILE *marksfile;
137
+ struct strbuf sb = STRBUF_INIT;
138
+ struct strbuf line = STRBUF_INIT;
139
+ int found = 0;
140
+
141
+ if (latestrev < 1)
142
+ return;
143
+
144
+ init_notes(NULL, notes_ref, NULL, 0);
145
+ marksfile = fopen(marksfilename, "r");
146
+ if (!marksfile) {
147
+ regenerate_marks();
148
+ marksfile = fopen(marksfilename, "r");
149
+ if (!marksfile)
150
+ die_errno("cannot read marks file %s!", marksfilename);
151
+ fclose(marksfile);
152
+ } else {
153
+ strbuf_addf(&sb, ":%d ", latestrev);
154
+ while (strbuf_getline(&line, marksfile, '\n') != EOF) {
155
+ if (!prefixcmp(line.buf, sb.buf)) {
156
+ found++;
157
+ break;
158
+ }
159
+ }
160
+ fclose(marksfile);
161
+ if (!found)
162
+ regenerate_marks();
163
+ }
164
+ free_notes(NULL);
165
+ strbuf_release(&sb);
166
+ strbuf_release(&line);
167
+}
168
+
169
static int cmd_import(const char *line)
170
{
171
int code;
191
free(note_msg);
192
}
193
}
194
+ check_or_regenerate_marks(startrev - 1);
195
196
if (dump_from_file) {
197
dumpin_fd = open(url, O_RDONLY);