]> git.proxmox.com Git - libgit2.git/blame - src/refspec.c
Add a remotes API
[libgit2.git] / src / refspec.c
CommitLineData
9c82357b
CMN
1/*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
5 *
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
14 *
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26#include "common.h"
27#include "refspec.h"
28
29int git_refspec_parse(git_refspec *refspec, const char *str)
30{
31 char *delim;
32
33 memset(refspec, 0x0, sizeof(git_refspec));
34
35 if (*str == '+') {
36 refspec->force = 1;
37 str++;
38 }
39
40 delim = strchr(str, ':');
41 if (delim == NULL)
42 return git__throw(GIT_EOBJCORRUPTED, "Failed to parse refspec. No ':'");
43
44 refspec->src = git__strndup(str, delim - str);
45 if (refspec->src == NULL)
46 return GIT_ENOMEM;
47
48 refspec->dst = git__strdup(delim + 1);
49 if (refspec->dst == NULL) {
50 free(refspec->src);
51 refspec->src = NULL;
52 return GIT_ENOMEM;
53 }
54
55 return GIT_SUCCESS;
56}
57
58const char *git_refspec_src(const git_refspec *refspec)
59{
60 return refspec->src;
61}
62
63const char *git_refspec_dst(const git_refspec *refspec)
64{
65 return refspec->dst;
66}