~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-security

« back to all changes in this revision

Viewing changes to send-pack.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-10-04 08:27:01 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20071004082701-rsd058ontoqz4i30
Tags: 1:1.5.3.4-1
new upstream point release (closes: #445188).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include "refs.h"
5
5
#include "pkt-line.h"
6
6
#include "run-command.h"
 
7
#include "remote.h"
7
8
 
8
9
static const char send_pack_usage[] =
9
10
"git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
176
177
        return ret;
177
178
}
178
179
 
179
 
static int send_pack(int in, int out, int nr_refspec, char **refspec)
 
180
static int send_pack(int in, int out, struct remote *remote, int nr_refspec, char **refspec)
180
181
{
181
182
        struct ref *ref;
182
183
        int new_refs;
213
214
        new_refs = 0;
214
215
        for (ref = remote_refs; ref; ref = ref->next) {
215
216
                char old_hex[60], *new_hex;
216
 
                int delete_ref;
 
217
                int will_delete_ref;
217
218
 
218
219
                if (!ref->peer_ref)
219
220
                        continue;
220
221
 
221
 
                delete_ref = is_null_sha1(ref->peer_ref->new_sha1);
222
 
                if (delete_ref && !allow_deleting_refs) {
 
222
 
 
223
                will_delete_ref = is_null_sha1(ref->peer_ref->new_sha1);
 
224
                if (will_delete_ref && !allow_deleting_refs) {
223
225
                        error("remote does not support deleting refs");
224
226
                        ret = -2;
225
227
                        continue;
226
228
                }
227
 
                if (!delete_ref &&
 
229
                if (!will_delete_ref &&
228
230
                    !hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
229
231
                        if (verbose)
230
232
                                fprintf(stderr, "'%s': up-to-date\n", ref->name);
251
253
                 */
252
254
 
253
255
                if (!force_update &&
254
 
                    !delete_ref &&
 
256
                    !will_delete_ref &&
255
257
                    !is_null_sha1(ref->old_sha1) &&
256
258
                    !ref->force) {
257
259
                        if (!has_sha1_file(ref->old_sha1) ||
275
277
                        }
276
278
                }
277
279
                hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
278
 
                if (!delete_ref)
 
280
                if (!will_delete_ref)
279
281
                        new_refs++;
280
282
                strcpy(old_hex, sha1_to_hex(ref->old_sha1));
281
283
                new_hex = sha1_to_hex(ref->new_sha1);
290
292
                else
291
293
                        packet_write(out, "%s %s %s",
292
294
                                     old_hex, new_hex, ref->name);
293
 
                if (delete_ref)
 
295
                if (will_delete_ref)
294
296
                        fprintf(stderr, "deleting '%s'\n", ref->name);
295
297
                else {
296
298
                        fprintf(stderr, "updating '%s'", ref->name);
300
302
                        fprintf(stderr, "\n  from %s\n  to   %s\n",
301
303
                                old_hex, new_hex);
302
304
                }
 
305
                if (remote) {
 
306
                        struct refspec rs;
 
307
                        rs.src = ref->name;
 
308
                        rs.dst = NULL;
 
309
                        if (!remote_find_tracking(remote, &rs)) {
 
310
                                struct ref_lock *lock;
 
311
                                fprintf(stderr, " Also local %s\n", rs.dst);
 
312
                                if (will_delete_ref) {
 
313
                                        if (delete_ref(rs.dst, NULL)) {
 
314
                                                error("Failed to delete");
 
315
                                        }
 
316
                                } else {
 
317
                                        lock = lock_any_ref_for_update(rs.dst, NULL, 0);
 
318
                                        if (!lock)
 
319
                                                error("Failed to lock");
 
320
                                        else
 
321
                                                write_ref_sha1(lock, ref->new_sha1,
 
322
                                                               "update by push");
 
323
                                }
 
324
                                free(rs.dst);
 
325
                        }
 
326
                }
303
327
        }
304
328
 
305
329
        packet_flush(out);
330
354
                case -2: /* ok but a single level -- that is fine for
331
355
                          * a match pattern.
332
356
                          */
 
357
                case -3: /* ok but ends with a pattern-match character */
333
358
                        continue;
334
359
                }
335
360
                die("remote part of refspec is not a valid name in %s",
344
369
        char **heads = NULL;
345
370
        int fd[2], ret;
346
371
        pid_t pid;
 
372
        char *remote_name = NULL;
 
373
        struct remote *remote = NULL;
347
374
 
348
375
        setup_git_directory();
349
376
        git_config(git_default_config);
361
388
                                receivepack = arg + 7;
362
389
                                continue;
363
390
                        }
 
391
                        if (!prefixcmp(arg, "--remote=")) {
 
392
                                remote_name = arg + 9;
 
393
                                continue;
 
394
                        }
364
395
                        if (!strcmp(arg, "--all")) {
365
396
                                send_all = 1;
366
397
                                continue;
393
424
                usage(send_pack_usage);
394
425
        verify_remote_names(nr_heads, heads);
395
426
 
396
 
        pid = git_connect(fd, dest, receivepack);
 
427
        if (remote_name) {
 
428
                remote = remote_get(remote_name);
 
429
                if (!remote_has_uri(remote, dest)) {
 
430
                        die("Destination %s is not a uri for %s",
 
431
                            dest, remote_name);
 
432
                }
 
433
        }
 
434
 
 
435
        pid = git_connect(fd, dest, receivepack, verbose ? CONNECT_VERBOSE : 0);
397
436
        if (pid < 0)
398
437
                return 1;
399
 
        ret = send_pack(fd[0], fd[1], nr_heads, heads);
 
438
        ret = send_pack(fd[0], fd[1], remote, nr_heads, heads);
400
439
        close(fd[0]);
401
440
        close(fd[1]);
402
441
        ret |= finish_connect(pid);