shallow: add setup_temporary_shallow()
This function is like setup_alternate_shallow() except that it does not lock $GIT_DIR/shallow. It is supposed to be used when a program generates temporary shallow for use by another program, then throw the shallow file away. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									6a3bbb4db4
								
							
						
					
					
						commit
						08ea65ad13
					
				
							
								
								
									
										1
									
								
								commit.h
								
								
								
								
							
							
						
						
									
										1
									
								
								commit.h
								
								
								
								
							|  | @ -201,6 +201,7 @@ extern void set_alternate_shallow_file(const char *path); | ||||||
| extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol); | extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol); | ||||||
| extern void setup_alternate_shallow(struct lock_file *shallow_lock, | extern void setup_alternate_shallow(struct lock_file *shallow_lock, | ||||||
| 				    const char **alternate_shallow_file); | 				    const char **alternate_shallow_file); | ||||||
|  | extern char *setup_temporary_shallow(void); | ||||||
|  |  | ||||||
| int is_descendant_of(struct commit *, struct commit_list *); | int is_descendant_of(struct commit *, struct commit_list *); | ||||||
| int in_merge_bases(struct commit *, struct commit *); | int in_merge_bases(struct commit *, struct commit *); | ||||||
|  |  | ||||||
							
								
								
									
										23
									
								
								shallow.c
								
								
								
								
							
							
						
						
									
										23
									
								
								shallow.c
								
								
								
								
							|  | @ -175,6 +175,29 @@ int write_shallow_commits(struct strbuf *out, int use_pack_protocol) | ||||||
| 	return data.count; | 	return data.count; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | char *setup_temporary_shallow(void) | ||||||
|  | { | ||||||
|  | 	struct strbuf sb = STRBUF_INIT; | ||||||
|  | 	int fd; | ||||||
|  |  | ||||||
|  | 	if (write_shallow_commits(&sb, 0)) { | ||||||
|  | 		struct strbuf path = STRBUF_INIT; | ||||||
|  | 		strbuf_addstr(&path, git_path("shallow_XXXXXX")); | ||||||
|  | 		fd = xmkstemp(path.buf); | ||||||
|  | 		if (write_in_full(fd, sb.buf, sb.len) != sb.len) | ||||||
|  | 			die_errno("failed to write to %s", | ||||||
|  | 				  path.buf); | ||||||
|  | 		close(fd); | ||||||
|  | 		strbuf_release(&sb); | ||||||
|  | 		return strbuf_detach(&path, NULL); | ||||||
|  | 	} | ||||||
|  | 	/* | ||||||
|  | 	 * is_repository_shallow() sees empty string as "no shallow | ||||||
|  | 	 * file". | ||||||
|  | 	 */ | ||||||
|  | 	return xstrdup(""); | ||||||
|  | } | ||||||
|  |  | ||||||
| void setup_alternate_shallow(struct lock_file *shallow_lock, | void setup_alternate_shallow(struct lock_file *shallow_lock, | ||||||
| 			     const char **alternate_shallow_file) | 			     const char **alternate_shallow_file) | ||||||
| { | { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Nguyễn Thái Ngọc Duy
						Nguyễn Thái Ngọc Duy