mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 10:33:00 +00:00 
			
		
		
		
	Add a name to a remote created from the API
Make it a bit more resilient. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
This commit is contained in:
		
							parent
							
								
									95057b8503
								
							
						
					
					
						commit
						617bfdf47f
					
				@ -28,16 +28,18 @@ GIT_BEGIN_DECL
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Create a new unnamed remote
 | 
			
		||||
 * Create a remote in memory
 | 
			
		||||
 *
 | 
			
		||||
 * Useful when you don't want to store the remote
 | 
			
		||||
 * Create a remote with the default refspecs in memory. You can use
 | 
			
		||||
 * this when you have a URL instead of a remote's name.
 | 
			
		||||
 *
 | 
			
		||||
 * @param out pointer to the new remote object
 | 
			
		||||
 * @param repo the associtated repository
 | 
			
		||||
 * @param url the remote repository's URL
 | 
			
		||||
 * @param name the remote's name
 | 
			
		||||
 * @return GIT_SUCCESS or an error code
 | 
			
		||||
 */
 | 
			
		||||
int git_remote_new(git_remote **out, git_repository *repo, const char *url);
 | 
			
		||||
int git_remote_new(git_remote **out, git_repository *repo, const char *url, const char *name);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the information for a particular remote
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								src/remote.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/remote.c
									
									
									
									
									
								
							@ -56,22 +56,34 @@ static int parse_remote_refspec(git_config *cfg, git_refspec *refspec, const cha
 | 
			
		||||
	return refspec_parse(refspec, val);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int git_remote_new(git_remote **out, git_repository *repo, const char *url)
 | 
			
		||||
int git_remote_new(git_remote **out, git_repository *repo, const char *url, const char *name)
 | 
			
		||||
{
 | 
			
		||||
	git_remote *remote;
 | 
			
		||||
 | 
			
		||||
	if (url == NULL)
 | 
			
		||||
		return git__throw(GIT_EINVALIDARGS, "No URL was given");
 | 
			
		||||
 | 
			
		||||
	remote = git__malloc(sizeof(git_remote));
 | 
			
		||||
	if (remote == NULL)
 | 
			
		||||
		return GIT_ENOMEM;
 | 
			
		||||
 | 
			
		||||
	memset(remote, 0x0, sizeof(git_remote));
 | 
			
		||||
	remote->repo = repo;
 | 
			
		||||
 | 
			
		||||
	remote->url = git__strdup(url);
 | 
			
		||||
	if (remote->url == NULL) {
 | 
			
		||||
		git__free(remote);
 | 
			
		||||
		return GIT_ENOMEM;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (name != NULL) {
 | 
			
		||||
		remote->name = git__strdup(name);
 | 
			
		||||
		if (remote->name == NULL) {
 | 
			
		||||
			git__free(remote);
 | 
			
		||||
			return GIT_ENOMEM;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	*out = remote;
 | 
			
		||||
	return GIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user