diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-05-25 13:38:44 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-05-25 13:41:37 -0700 |
commit | b84c343c885b8168047b2773b5c597d04337d9bd (patch) | |
tree | a4ef0ee1fd0939d2a465d794ba0d88fc54234d28 /lockfile.c | |
parent | 0dbaa5bd514b9d234c07fd6b857888566abcf836 (diff) | |
parent | b50c8469cc9a336b22ef37b23711d4547a48bc2b (diff) | |
download | git-b84c343c885b8168047b2773b5c597d04337d9bd.tar.gz |
Merge branch 'db/clone-in-c'
* db/clone-in-c:
Add test for cloning with "--reference" repo being a subset of source repo
Add a test for another combination of --reference
Test that --reference actually suppresses fetching referenced objects
clone: fall back to copying if hardlinking fails
builtin-clone.c: Need to closedir() in copy_or_link_directory()
builtin-clone: fix initial checkout
Build in clone
Provide API access to init_db()
Add a function to set a non-default work tree
Allow for having for_each_ref() list extra refs
Have a constant extern refspec for "--tags"
Add a library function to add an alternate to the alternates file
Add a lockfile function to append to a file
Mark the list of refs to fetch as const
Conflicts:
cache.h
t/t5700-clone-reference.sh
Diffstat (limited to 'lockfile.c')
-rw-r--r-- | lockfile.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lockfile.c b/lockfile.c index b0118d0592..cfc7335347 100644 --- a/lockfile.c +++ b/lockfile.c @@ -160,6 +160,34 @@ int hold_lock_file_for_update(struct lock_file *lk, const char *path, int die_on return fd; } +int hold_lock_file_for_append(struct lock_file *lk, const char *path, int die_on_error) +{ + int fd, orig_fd; + + fd = lock_file(lk, path); + if (fd < 0) { + if (die_on_error) + die("unable to create '%s.lock': %s", path, strerror(errno)); + return fd; + } + + orig_fd = open(path, O_RDONLY); + if (orig_fd < 0) { + if (errno != ENOENT) { + if (die_on_error) + die("cannot open '%s' for copying", path); + close(fd); + return error("cannot open '%s' for copying", path); + } + } else if (copy_fd(orig_fd, fd)) { + if (die_on_error) + exit(128); + close(fd); + return -1; + } + return fd; +} + int close_lock_file(struct lock_file *lk) { int fd = lk->fd; |