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
e3dcaca5
Commit
e3dcaca5
authored
Mar 17, 2018
by
Nika Layzell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mailmap: Integrate mailmaps with blame and signatures
parent
b05fbba3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
117 additions
and
4 deletions
+117
-4
include/git2/blame.h
+10
-0
include/git2/commit.h
+28
-0
include/git2/signature.h
+13
-0
include/git2/types.h
+3
-0
src/blame.c
+10
-4
src/blame.h
+2
-0
src/commit.c
+12
-0
src/signature.c
+39
-0
No files found.
include/git2/blame.h
View file @
e3dcaca5
...
...
@@ -43,6 +43,10 @@ typedef enum {
/** Restrict the search of commits to those reachable following only the
* first parents. */
GIT_BLAME_FIRST_PARENT
=
(
1
<<
4
),
/** Use mailmap file to map author and committer names and email addresses
* to canonical real names and email addresses. The mailmap will be read
* from the working directory, or HEAD in a bare repository. */
GIT_BLAME_USE_MAILMAP
=
(
1
<<
5
),
}
git_blame_flag_t
;
/**
...
...
@@ -108,6 +112,9 @@ GIT_EXTERN(int) git_blame_init_options(
* changed.
* - `final_start_line_number` is the 1-based line number where this hunk
* begins, in the final version of the file
* - `final_signature` is the author of `final_commit_id`. If
* `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
* real name and email address.
* - `orig_commit_id` is the OID of the commit where this hunk was found. This
* will usually be the same as `final_commit_id`, except when
* `GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES` has been specified.
...
...
@@ -116,6 +123,9 @@ GIT_EXTERN(int) git_blame_init_options(
* - `orig_start_line_number` is the 1-based line number where this hunk begins
* in the file named by `orig_path` in the commit specified by
* `orig_commit_id`.
* - `orig_signature` is the author of `orig_commit_id`. If
* `GIT_BLAME_USE_MAILMAP` has been specified, it will contain the canonical
* real name and email address.
* - `boundary` is 1 iff the hunk has been tracked to a boundary commit (the
* root, or the commit specified in git_blame_options.oldest_commit)
*/
...
...
include/git2/commit.h
View file @
e3dcaca5
...
...
@@ -173,6 +173,34 @@ GIT_EXTERN(const git_signature *) git_commit_committer(const git_commit *commit)
GIT_EXTERN
(
const
git_signature
*
)
git_commit_author
(
const
git_commit
*
commit
);
/**
* Get the committer of a commit, using the mailmap to map names and email
* addresses to canonical real names and email addresses.
*
* Call `git_signature_free` to free the signature.
*
* @param out a pointer to store the resolved signature.
* @param commit a previously loaded commit.
* @param mailmap the mailmap to resolve with. (may be NULL)
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_commit_committer_with_mailmap
(
git_signature
**
out
,
const
git_commit
*
commit
,
const
git_mailmap
*
mailmap
);
/**
* Get the author of a commit, using the mailmap to map names and email
* addresses to canonical real names and email addresses.
*
* Call `git_signature_free` to free the signature.
*
* @param out a pointer to store the resolved signature.
* @param commit a previously loaded commit.
* @param mailmap the mailmap to resolve with. (may be NULL)
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_commit_author_with_mailmap
(
git_signature
**
out
,
const
git_commit
*
commit
,
const
git_mailmap
*
mailmap
);
/**
* Get the full raw text of the commit header.
*
* @param commit a previously loaded commit
...
...
include/git2/signature.h
View file @
e3dcaca5
...
...
@@ -76,6 +76,19 @@ GIT_EXTERN(int) git_signature_default(git_signature **out, git_repository *repo)
GIT_EXTERN
(
int
)
git_signature_from_buffer
(
git_signature
**
out
,
const
char
*
buf
);
/**
* Create a signature with names updated respecting the mailmap.
*
* Call `git_signature_free()` to free the data.
*
* @param out new signature
* @param sig signature to resolve
* @param mailmap mailmap to resolve with
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_signature_with_mailmap
(
git_signature
**
out
,
const
git_signature
*
sig
,
const
git_mailmap
*
mailmap
);
/**
* Create a copy of an existing signature. All internal strings are also
* duplicated.
*
...
...
include/git2/types.h
View file @
e3dcaca5
...
...
@@ -434,6 +434,9 @@ struct git_writestream {
void
(
*
free
)(
git_writestream
*
stream
);
};
/** A parsed representation of a .mailmap file. */
typedef
struct
git_mailmap
git_mailmap
;
/** @} */
GIT_END_DECL
...
...
src/blame.c
View file @
e3dcaca5
...
...
@@ -132,6 +132,9 @@ git_blame* git_blame__alloc(
return
NULL
;
}
if
(
opts
.
flags
&
GIT_BLAME_USE_MAILMAP
)
git_mailmap_from_repo
(
&
gbr
->
mailmap
,
repo
);
return
gbr
;
}
...
...
@@ -150,6 +153,8 @@ void git_blame_free(git_blame *blame)
git_array_clear
(
blame
->
line_index
);
git_mailmap_free
(
blame
->
mailmap
);
git__free
(
blame
->
path
);
git_blob_free
(
blame
->
final_blob
);
git__free
(
blame
);
...
...
@@ -279,7 +284,7 @@ static int index_blob_lines(git_blame *blame)
return
blame
->
num_lines
;
}
static
git_blame_hunk
*
hunk_from_entry
(
git_blame__entry
*
e
)
static
git_blame_hunk
*
hunk_from_entry
(
git_blame__entry
*
e
,
git_blame
*
blame
)
{
git_blame_hunk
*
h
=
new_hunk
(
e
->
lno
+
1
,
e
->
num_lines
,
e
->
s_lno
+
1
,
e
->
suspect
->
path
);
...
...
@@ -289,8 +294,9 @@ static git_blame_hunk* hunk_from_entry(git_blame__entry *e)
git_oid_cpy
(
&
h
->
final_commit_id
,
git_commit_id
(
e
->
suspect
->
commit
));
git_oid_cpy
(
&
h
->
orig_commit_id
,
git_commit_id
(
e
->
suspect
->
commit
));
git_signature_dup
(
&
h
->
final_signature
,
git_commit_author
(
e
->
suspect
->
commit
));
git_signature_dup
(
&
h
->
orig_signature
,
git_commit_author
(
e
->
suspect
->
commit
));
git_commit_author_with_mailmap
(
&
h
->
final_signature
,
e
->
suspect
->
commit
,
blame
->
mailmap
);
git_signature_dup
(
&
h
->
orig_signature
,
h
->
final_signature
);
h
->
boundary
=
e
->
is_boundary
?
1
:
0
;
return
h
;
}
...
...
@@ -341,7 +347,7 @@ static int blame_internal(git_blame *blame)
cleanup:
for
(
ent
=
blame
->
ent
;
ent
;
)
{
git_blame__entry
*
e
=
ent
->
next
;
git_blame_hunk
*
h
=
hunk_from_entry
(
ent
);
git_blame_hunk
*
h
=
hunk_from_entry
(
ent
,
blame
);
git_vector_insert
(
&
blame
->
hunks
,
h
);
...
...
src/blame.h
View file @
e3dcaca5
...
...
@@ -84,6 +84,8 @@ struct git_blame {
int
num_lines
;
const
char
*
final_buf
;
git_off_t
final_buf_size
;
git_mailmap
*
mailmap
;
};
git_blame
*
git_blame__alloc
(
...
...
src/commit.c
View file @
e3dcaca5
...
...
@@ -889,3 +889,15 @@ cleanup:
git_buf_dispose
(
&
commit
);
return
error
;
}
int
git_commit_committer_with_mailmap
(
git_signature
**
out
,
const
git_commit
*
commit
,
const
git_mailmap
*
mailmap
)
{
return
git_signature_with_mailmap
(
out
,
commit
->
committer
,
mailmap
);
}
int
git_commit_author_with_mailmap
(
git_signature
**
out
,
const
git_commit
*
commit
,
const
git_mailmap
*
mailmap
)
{
return
git_signature_with_mailmap
(
out
,
commit
->
author
,
mailmap
);
}
src/signature.c
View file @
e3dcaca5
...
...
@@ -9,6 +9,7 @@
#include "repository.h"
#include "git2/common.h"
#include "git2/mailmap.h"
#include "posix.h"
void
git_signature_free
(
git_signature
*
sig
)
...
...
@@ -121,6 +122,44 @@ int git_signature_dup(git_signature **dest, const git_signature *source)
return
0
;
}
int
git_signature_with_mailmap
(
git_signature
**
dest
,
const
git_signature
*
source
,
const
git_mailmap
*
mailmap
)
{
git_signature
*
signature
=
NULL
;
const
char
*
name
=
NULL
;
const
char
*
email
=
NULL
;
if
(
source
==
NULL
)
goto
on_error
;
git_mailmap_resolve
(
&
name
,
&
email
,
mailmap
,
source
->
name
,
source
->
email
);
signature
=
git__calloc
(
1
,
sizeof
(
git_signature
));
if
(
!
signature
)
goto
on_error
;
signature
->
name
=
git__strdup
(
name
);
if
(
!
signature
->
name
)
goto
on_error
;
signature
->
email
=
git__strdup
(
email
);
if
(
!
signature
->
email
)
goto
on_error
;
signature
->
when
.
time
=
source
->
when
.
time
;
signature
->
when
.
offset
=
source
->
when
.
offset
;
signature
->
when
.
sign
=
source
->
when
.
sign
;
*
dest
=
signature
;
return
0
;
on_error:
git_signature_free
(
signature
);
return
-
1
;
}
int
git_signature__pdup
(
git_signature
**
dest
,
const
git_signature
*
source
,
git_pool
*
pool
)
{
git_signature
*
signature
;
...
...
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