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
bab0b9f2
Commit
bab0b9f2
authored
Nov 22, 2013
by
Edward Thomson
Committed by
Edward Thomson
Dec 02, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up state metadata more consistently
parent
300d192f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
81 deletions
+62
-81
include/git2/repository.h
+3
-3
src/merge.c
+12
-34
src/repository.c
+36
-0
src/repository.h
+2
-0
src/reset.c
+1
-1
src/revert.c
+8
-29
src/revert.h
+0
-14
No files found.
include/git2/repository.h
View file @
bab0b9f2
...
...
@@ -488,13 +488,13 @@ GIT_EXTERN(int) git_repository_message(char *out, size_t len, git_repository *re
GIT_EXTERN
(
int
)
git_repository_message_remove
(
git_repository
*
repo
);
/**
* Remove all the metadata associated with an ongoing
git merge, including
* MERGE_HEAD, MERGE_MSG, etc.
* Remove all the metadata associated with an ongoing
command like merge,
*
revert, cherry-pick, etc. For example:
MERGE_HEAD, MERGE_MSG, etc.
*
* @param repo A repository object
* @return 0 on success, or error
*/
GIT_EXTERN
(
int
)
git_repository_
merg
e_cleanup
(
git_repository
*
repo
);
GIT_EXTERN
(
int
)
git_repository_
stat
e_cleanup
(
git_repository
*
repo
);
typedef
int
(
*
git_repository_fetchhead_foreach_cb
)(
const
char
*
ref_name
,
const
char
*
remote_url
,
...
...
src/merge.c
View file @
bab0b9f2
...
...
@@ -2362,6 +2362,17 @@ done:
return
error
;
}
static
int
merge_state_cleanup
(
git_repository
*
repo
)
{
const
char
*
state_files
[]
=
{
GIT_MERGE_HEAD_FILE
,
GIT_MERGE_MODE_FILE
,
GIT_MERGE_MSG_FILE
,
};
return
git_repository__cleanup_files
(
repo
,
state_files
,
ARRAY_SIZE
(
state_files
));
}
int
git_merge
(
git_merge_result
**
out
,
git_repository
*
repo
,
...
...
@@ -2453,7 +2464,7 @@ int git_merge(
goto
done
;
on_error
:
git_repository_merg
e_cleanup
(
repo
);
merge_stat
e_cleanup
(
repo
);
git_index_free
(
index_new
);
git__free
(
result
);
...
...
@@ -2497,39 +2508,6 @@ int git_merge__setup(
return
error
;
}
int
git_repository_merge_cleanup
(
git_repository
*
repo
)
{
int
error
=
0
;
git_buf
merge_head_path
=
GIT_BUF_INIT
,
merge_mode_path
=
GIT_BUF_INIT
,
merge_msg_path
=
GIT_BUF_INIT
;
assert
(
repo
);
if
(
git_buf_joinpath
(
&
merge_head_path
,
repo
->
path_repository
,
GIT_MERGE_HEAD_FILE
)
<
0
||
git_buf_joinpath
(
&
merge_mode_path
,
repo
->
path_repository
,
GIT_MERGE_MODE_FILE
)
<
0
||
git_buf_joinpath
(
&
merge_msg_path
,
repo
->
path_repository
,
GIT_MERGE_MSG_FILE
)
<
0
)
return
-
1
;
if
(
git_path_isfile
(
merge_head_path
.
ptr
))
{
if
((
error
=
p_unlink
(
merge_head_path
.
ptr
))
<
0
)
goto
cleanup
;
}
if
(
git_path_isfile
(
merge_mode_path
.
ptr
))
(
void
)
p_unlink
(
merge_mode_path
.
ptr
);
if
(
git_path_isfile
(
merge_msg_path
.
ptr
))
(
void
)
p_unlink
(
merge_msg_path
.
ptr
);
cleanup
:
git_buf_free
(
&
merge_msg_path
);
git_buf_free
(
&
merge_mode_path
);
git_buf_free
(
&
merge_head_path
);
return
error
;
}
/* Merge result data */
int
git_merge_result_is_uptodate
(
git_merge_result
*
merge_result
)
...
...
src/repository.c
View file @
bab0b9f2
...
...
@@ -1965,6 +1965,42 @@ int git_repository_state(git_repository *repo)
return
state
;
}
int
git_repository__cleanup_files
(
git_repository
*
repo
,
const
char
*
files
[],
size_t
files_len
)
{
git_buf
path
=
GIT_BUF_INIT
;
size_t
i
;
int
error
=
0
;
for
(
i
=
0
;
i
<
files_len
;
++
i
)
{
git_buf_clear
(
&
path
);
if
((
error
=
git_buf_joinpath
(
&
path
,
repo
->
path_repository
,
files
[
i
]))
<
0
||
(
git_path_isfile
(
git_buf_cstr
(
&
path
))
&&
(
error
=
p_unlink
(
git_buf_cstr
(
&
path
)))
<
0
))
goto
done
;
}
done:
git_buf_free
(
&
path
);
return
error
;
}
static
const
char
*
state_files
[]
=
{
GIT_MERGE_HEAD_FILE
,
GIT_MERGE_MODE_FILE
,
GIT_MERGE_MSG_FILE
,
GIT_REVERT_HEAD_FILE
,
GIT_CHERRY_PICK_HEAD_FILE
,
};
int
git_repository_state_cleanup
(
git_repository
*
repo
)
{
assert
(
repo
);
return
git_repository__cleanup_files
(
repo
,
state_files
,
ARRAY_SIZE
(
state_files
));
}
int
git_repository_is_shallow
(
git_repository
*
repo
)
{
git_buf
path
=
GIT_BUF_INIT
;
...
...
src/repository.h
View file @
bab0b9f2
...
...
@@ -169,4 +169,6 @@ GIT_INLINE(int) git_repository__ensure_not_bare(
return
GIT_EBAREREPO
;
}
int
git_repository__cleanup_files
(
git_repository
*
repo
,
const
char
*
files
[],
size_t
files_len
);
#endif
src/reset.c
View file @
bab0b9f2
...
...
@@ -149,7 +149,7 @@ int git_reset(
(
error
=
git_index_write
(
index
))
<
0
)
goto
cleanup
;
if
((
error
=
git_repository_
merg
e_cleanup
(
repo
))
<
0
)
{
if
((
error
=
git_repository_
stat
e_cleanup
(
repo
))
<
0
)
{
giterr_set
(
GITERR_INDEX
,
"%s - failed to clean up merge data"
,
ERROR_MSG
);
goto
cleanup
;
}
...
...
src/revert.c
View file @
bab0b9f2
...
...
@@ -9,7 +9,6 @@
#include "repository.h"
#include "filebuf.h"
#include "merge.h"
#include "revert.h"
#include "git2/types.h"
#include "git2/merge.h"
...
...
@@ -103,6 +102,13 @@ static int revert_normalize_opts(
return
error
;
}
static
int
revert_state_cleanup
(
git_repository
*
repo
)
{
const
char
*
state_files
[]
=
{
GIT_REVERT_HEAD_FILE
,
GIT_MERGE_MSG_FILE
};
return
git_repository__cleanup_files
(
repo
,
state_files
,
ARRAY_SIZE
(
state_files
));
}
int
git_revert
(
git_repository
*
repo
,
git_commit
*
commit
,
...
...
@@ -175,7 +181,7 @@ int git_revert(
goto
done
;
on_error:
git_revert_
_cleanup
(
repo
);
revert_state
_cleanup
(
repo
);
done:
git_index_free
(
index_new
);
...
...
@@ -188,30 +194,3 @@ done:
return
error
;
}
int
git_revert__cleanup
(
git_repository
*
repo
)
{
int
error
=
0
;
git_buf
revert_head_path
=
GIT_BUF_INIT
,
merge_msg_path
=
GIT_BUF_INIT
;
assert
(
repo
);
if
(
git_buf_joinpath
(
&
revert_head_path
,
repo
->
path_repository
,
GIT_REVERT_HEAD_FILE
)
<
0
||
git_buf_joinpath
(
&
merge_msg_path
,
repo
->
path_repository
,
GIT_MERGE_MSG_FILE
)
<
0
)
return
-
1
;
if
(
git_path_isfile
(
revert_head_path
.
ptr
))
{
if
((
error
=
p_unlink
(
revert_head_path
.
ptr
))
<
0
)
goto
cleanup
;
}
if
(
git_path_isfile
(
merge_msg_path
.
ptr
))
(
void
)
p_unlink
(
merge_msg_path
.
ptr
);
cleanup:
git_buf_free
(
&
merge_msg_path
);
git_buf_free
(
&
revert_head_path
);
return
error
;
}
src/revert.h
deleted
100644 → 0
View file @
300d192f
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_revert_h__
#define INCLUDE_revert_h__
#include "git2/repository.h"
int
git_revert__cleanup
(
git_repository
*
repo
);
#endif
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