move setup_alternate_shallow and write_shallow_commits to shallow.c
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Aug 16, 2013 at 16:52 UTC
3125fe528b65c1e4a4f5f934d056af342ab5472d
3 files changed
+58
-52
commit.h
+3
@@ -198,6 +198,9 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
198
int depth, int shallow_flag, int not_shallow_flag);
199
extern void check_shallow_file_for_update(void);
200
extern void set_alternate_shallow_file(const char *path);
201
+extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
202
+extern void setup_alternate_shallow(struct lock_file *shallow_lock,
203
+ const char **alternate_shallow_file);
204
205
int is_descendant_of(struct commit *, struct commit_list *);
206
int in_merge_bases(struct commit *, struct commit *);
fetch-pack.c
+1
-52
@@ -184,36 +184,6 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
184
}
185
}
186
187
-struct write_shallow_data {
188
- struct strbuf *out;
189
- int use_pack_protocol;
190
- int count;
191
-};
192
-
193
-static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
194
-{
195
- struct write_shallow_data *data = cb_data;
196
- const char *hex = sha1_to_hex(graft->sha1);
197
- data->count++;
198
- if (data->use_pack_protocol)
199
- packet_buf_write(data->out, "shallow %s", hex);
200
- else {
201
- strbuf_addstr(data->out, hex);
202
- strbuf_addch(data->out, '\n');
203
- }
204
- return 0;
205
-}
206
-
207
-static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
208
-{
209
- struct write_shallow_data data;
210
- data.out = out;
211
- data.use_pack_protocol = use_pack_protocol;
212
- data.count = 0;
213
- for_each_commit_graft(write_one_shallow, &data);
214
- return data.count;
215
-}
216
-
187
static enum ack_type get_ack(int fd, unsigned char *result_sha1)
188
{
189
int len;
@@ -795,27 +765,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
765
return strcmp(a->name, b->name);
766
}
767
798
-static void setup_alternate_shallow(void)
799
-{
800
- struct strbuf sb = STRBUF_INIT;
801
- int fd;
802
-
803
- check_shallow_file_for_update();
804
- fd = hold_lock_file_for_update(&shallow_lock, git_path("shallow"),
805
- LOCK_DIE_ON_ERROR);
806
- if (write_shallow_commits(&sb, 0)) {
807
- if (write_in_full(fd, sb.buf, sb.len) != sb.len)
808
- die_errno("failed to write to %s", shallow_lock.filename);
809
- alternate_shallow_file = shallow_lock.filename;
810
- } else
811
- /*
812
- * is_repository_shallow() sees empty string as "no
813
- * shallow file".
814
- */
815
- alternate_shallow_file = "";
816
- strbuf_release(&sb);
817
-}
818
-
768
static struct ref *do_fetch_pack(struct fetch_pack_args *args,
769
int fd[2],
770
const struct ref *orig_ref,
@@ -896,7 +845,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
845
if (args->stateless_rpc)
846
packet_flush(fd[1]);
847
if (args->depth > 0)
899
- setup_alternate_shallow();
848
+ setup_alternate_shallow(&shallow_lock, &alternate_shallow_file);
849
if (get_pack(args, fd, pack_lockfile))
850
die("git fetch-pack: fetch failed.");
851
shallow.c
+54
@@ -1,6 +1,7 @@
1
#include "cache.h"
2
#include "commit.h"
3
#include "tag.h"
4
+#include "pkt-line.h"
5
6
static int is_shallow = -1;
7
static struct stat shallow_stat;
@@ -141,3 +142,56 @@ void check_shallow_file_for_update(void)
142
)
143
die("shallow file was changed during fetch");
144
}
145
+
146
+struct write_shallow_data {
147
+ struct strbuf *out;
148
+ int use_pack_protocol;
149
+ int count;
150
+};
151
+
152
+static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
153
+{
154
+ struct write_shallow_data *data = cb_data;
155
+ const char *hex = sha1_to_hex(graft->sha1);
156
+ data->count++;
157
+ if (data->use_pack_protocol)
158
+ packet_buf_write(data->out, "shallow %s", hex);
159
+ else {
160
+ strbuf_addstr(data->out, hex);
161
+ strbuf_addch(data->out, '\n');
162
+ }
163
+ return 0;
164
+}
165
+
166
+int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
167
+{
168
+ struct write_shallow_data data;
169
+ data.out = out;
170
+ data.use_pack_protocol = use_pack_protocol;
171
+ data.count = 0;
172
+ for_each_commit_graft(write_one_shallow, &data);
173
+ return data.count;
174
+}
175
+
176
+void setup_alternate_shallow(struct lock_file *shallow_lock,
177
+ const char **alternate_shallow_file)
178
+{
179
+ struct strbuf sb = STRBUF_INIT;
180
+ int fd;
181
+
182
+ check_shallow_file_for_update();
183
+ fd = hold_lock_file_for_update(shallow_lock, git_path("shallow"),
184
+ LOCK_DIE_ON_ERROR);
185
+ if (write_shallow_commits(&sb, 0)) {
186
+ if (write_in_full(fd, sb.buf, sb.len) != sb.len)
187
+ die_errno("failed to write to %s",
188
+ shallow_lock->filename);
189
+ *alternate_shallow_file = shallow_lock->filename;
190
+ } else
191
+ /*
192
+ * is_repository_shallow() sees empty string as "no
193
+ * shallow file".
194
+ */
195
+ *alternate_shallow_file = "";
196
+ strbuf_release(&sb);
197
+}