Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
bf63cd0b
Commit
bf63cd0b
authored
Apr 12, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #625 from carlosmn/valgrind
Plug a few leaks
parents
1de77cd3
a1515693
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
14 deletions
+33
-14
src/branch.c
+32
-14
src/transports/local.c
+1
-0
No files found.
src/branch.c
View file @
bf63cd0b
...
@@ -114,28 +114,30 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
...
@@ -114,28 +114,30 @@ int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_
assert
((
branch_type
==
GIT_BRANCH_LOCAL
)
||
(
branch_type
==
GIT_BRANCH_REMOTE
));
assert
((
branch_type
==
GIT_BRANCH_LOCAL
)
||
(
branch_type
==
GIT_BRANCH_REMOTE
));
if
((
error
=
retrieve_branch_reference
(
&
branch
,
repo
,
branch_name
,
branch_type
==
GIT_BRANCH_REMOTE
))
<
0
)
if
((
error
=
retrieve_branch_reference
(
&
branch
,
repo
,
branch_name
,
branch_type
==
GIT_BRANCH_REMOTE
))
<
0
)
goto
cleanup
;
goto
on_error
;
if
(
git_reference_lookup
(
&
head
,
repo
,
GIT_HEAD_FILE
)
<
0
)
{
if
(
git_reference_lookup
(
&
head
,
repo
,
GIT_HEAD_FILE
)
<
0
)
{
giterr_set
(
GITERR_REFERENCE
,
"Cannot locate HEAD."
);
giterr_set
(
GITERR_REFERENCE
,
"Cannot locate HEAD."
);
error
=
-
1
;
goto
on_error
;
goto
cleanup
;
}
}
if
((
git_reference_type
(
head
)
==
GIT_REF_SYMBOLIC
)
if
((
git_reference_type
(
head
)
==
GIT_REF_SYMBOLIC
)
&&
(
strcmp
(
git_reference_target
(
head
),
git_reference_name
(
branch
))
==
0
))
{
&&
(
strcmp
(
git_reference_target
(
head
),
git_reference_name
(
branch
))
==
0
))
{
giterr_set
(
GITERR_REFERENCE
,
giterr_set
(
GITERR_REFERENCE
,
"Cannot delete branch '%s' as it is the current HEAD of the repository."
,
branch_name
);
"Cannot delete branch '%s' as it is the current HEAD of the repository."
,
branch_name
);
error
=
-
1
;
goto
on_error
;
goto
cleanup
;
}
}
return
git_reference_delete
(
branch
);
if
(
git_reference_delete
(
branch
)
<
0
)
goto
on_error
;
cleanup:
git_reference_free
(
head
);
return
0
;
on_error:
git_reference_free
(
head
);
git_reference_free
(
head
);
git_reference_free
(
branch
);
git_reference_free
(
branch
);
return
error
;
return
-
1
;
}
}
typedef
struct
{
typedef
struct
{
...
@@ -181,18 +183,34 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i
...
@@ -181,18 +183,34 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i
int
git_branch_move
(
git_repository
*
repo
,
const
char
*
old_branch_name
,
const
char
*
new_branch_name
,
int
force
)
int
git_branch_move
(
git_repository
*
repo
,
const
char
*
old_branch_name
,
const
char
*
new_branch_name
,
int
force
)
{
{
git_reference
*
reference
;
git_reference
*
reference
=
NULL
;
git_buf
old_reference_name
=
GIT_BUF_INIT
,
new_reference_name
=
GIT_BUF_INIT
;
git_buf
old_reference_name
=
GIT_BUF_INIT
,
new_reference_name
=
GIT_BUF_INIT
;
int
error
;
int
error
;
if
(
git_buf_joinpath
(
&
old_reference_name
,
GIT_REFS_HEADS_DIR
,
old_branch_name
)
<
0
)
if
(
git_buf_joinpath
(
&
old_reference_name
,
GIT_REFS_HEADS_DIR
,
old_branch_name
)
<
0
)
return
-
1
;
goto
on_error
;
/* We need to be able to return GIT_ENOTFOUND */
if
((
error
=
git_reference_lookup
(
&
reference
,
repo
,
git_buf_cstr
(
&
old_reference_name
)))
<
0
)
{
git_buf_free
(
&
old_reference_name
);
return
error
;
}
if
(
git_buf_joinpath
(
&
new_reference_name
,
GIT_REFS_HEADS_DIR
,
new_branch_name
)
<
0
)
if
(
git_buf_joinpath
(
&
new_reference_name
,
GIT_REFS_HEADS_DIR
,
new_branch_name
)
<
0
)
return
-
1
;
goto
on_error
;
if
(
(
error
=
git_reference_lookup
(
&
reference
,
repo
,
git_buf_cstr
(
&
old_reference_name
))
)
<
0
)
if
(
git_reference_rename
(
reference
,
git_buf_cstr
(
&
new_reference_name
),
force
)
<
0
)
return
error
;
goto
on_
error
;
return
git_reference_rename
(
reference
,
git_buf_cstr
(
&
new_reference_name
),
force
);
git_reference_free
(
reference
);
git_buf_free
(
&
old_reference_name
);
git_buf_free
(
&
new_reference_name
);
return
0
;
on_error:
git_reference_free
(
reference
);
git_buf_free
(
&
old_reference_name
);
git_buf_free
(
&
new_reference_name
);
return
-
1
;
}
}
src/transports/local.c
View file @
bf63cd0b
...
@@ -118,6 +118,7 @@ static int store_refs(transport_local *t)
...
@@ -118,6 +118,7 @@ static int store_refs(transport_local *t)
goto
on_error
;
goto
on_error
;
}
}
git_strarray_free
(
&
ref_names
);
return
0
;
return
0
;
on_error:
on_error:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment