Skip to content

Commit 659cf20

Browse files
committed
Remove the signature from ref-modifying functions
The signature for the reflog is not something which changes dynamically. Almost all uses will be NULL, since we want for the repository's default identity to be used, making it noise. In order to allow for changing the identity, we instead provide git_repository_set_ident() and git_repository_ident() which allow a user to override the choice of signature.
1 parent 99b68a2 commit 659cf20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+581
-611
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ v0.22 + 1
1111
* Checkout can now handle an initial checkout of a repository, making
1212
`GIT_CHECKOUT_SAFE_CREATE` unnecessary for users of clone.
1313

14+
* The signature parameter in the ref-modifying functions has been
15+
removed. Use `git_repository_set_ident()` and
16+
`git_repository_ident()` to override the signature to be used.
17+
1418
### API additions
1519

1620
* Parsing and retrieving a configuration value as a path is exposed
1721
via `git_config_parse_path()` and `git_config_get_path()`
1822
respectively.
1923

24+
* `git_repository_set_ident()` and `git_repository_ident()` serve to
25+
set and query which identity will be used when writing to the
26+
reflog.
27+
2028
### API removals
2129

2230
### Breaking API changes

examples/network/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int fetch(git_repository *repo, int argc, char **argv)
156156
// right commits. This may be needed even if there was no packfile
157157
// to download, which can happen e.g. when the branches have been
158158
// changed but all the needed objects are available locally.
159-
if (git_remote_update_tips(remote, NULL, NULL) < 0)
159+
if (git_remote_update_tips(remote, NULL) < 0)
160160
return -1;
161161

162162
git_remote_free(remote);

include/git2/branch.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ GIT_BEGIN_DECL
4343
*
4444
* @param force Overwrite existing branch.
4545
*
46-
* @param signature The identity that will used to populate the reflog entry
47-
*
4846
* @param log_message The one line long message to be appended to the reflog.
4947
* If NULL, the default is "Branch: created"; if you want something more
5048
* useful, provide a message.
@@ -59,7 +57,6 @@ GIT_EXTERN(int) git_branch_create(
5957
const char *branch_name,
6058
const git_commit *target,
6159
int force,
62-
const git_signature *signature,
6360
const char *log_message);
6461

6562
/**
@@ -123,8 +120,6 @@ GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter);
123120
*
124121
* @param force Overwrite existing branch.
125122
*
126-
* @param signature The identity that will used to populate the reflog entry
127-
*
128123
* @param log_message The one line long message to be appended to the reflog
129124
*
130125
* @return 0 on success, GIT_EINVALIDSPEC or an error code.
@@ -134,7 +129,6 @@ GIT_EXTERN(int) git_branch_move(
134129
git_reference *branch,
135130
const char *new_branch_name,
136131
int force,
137-
const git_signature *signature,
138132
const char *log_message);
139133

140134
/**

include/git2/clone.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ typedef struct git_clone_options {
136136
*/
137137
const char* checkout_branch;
138138

139-
/**
140-
* The identity used when updating the reflog. NULL means to
141-
* use the default signature using the config.
142-
*/
143-
git_signature *signature;
144-
145139
/**
146140
* A callback used to create the new repository into which to
147141
* clone. If NULL, the 'bare' field will be used to determine

include/git2/rebase.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ GIT_EXTERN(int) git_rebase_init_options(
139139
* reachable commits
140140
* @param onto The branch to rebase onto, or NULL to rebase onto the given
141141
* upstream
142-
* @param signature The signature of the rebaser (optional)
143142
* @param opts Options to specify how rebase is performed
144143
* @return Zero on success; -1 on failure.
145144
*/
@@ -149,7 +148,6 @@ GIT_EXTERN(int) git_rebase_init(
149148
const git_annotated_commit *branch,
150149
const git_annotated_commit *upstream,
151150
const git_annotated_commit *onto,
152-
const git_signature *signature,
153151
const git_rebase_options *opts);
154152

155153
/**
@@ -241,13 +239,10 @@ GIT_EXTERN(int) git_rebase_commit(
241239
* and working directory to their state before rebase began.
242240
*
243241
* @param rebase The rebase that is in-progress
244-
* @param signature The identity that is aborting the rebase
245242
* @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
246243
* -1 on other errors.
247244
*/
248-
GIT_EXTERN(int) git_rebase_abort(
249-
git_rebase *rebase,
250-
const git_signature *signature);
245+
GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
251246

252247
/**
253248
* Finishes a rebase that is currently in progress once all patches have

include/git2/refs.h

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
8989
* This function will return an error if a reference already exists with the
9090
* given name unless `force` is true, in which case it will be overwritten.
9191
*
92-
* The signature and message for the reflog will be ignored if the
93-
* reference does not belong in the standard set (HEAD, branches and
94-
* remote-tracking branches) and it does not have a reflog.
92+
* The message for the reflog will be ignored if the reference does
93+
* not belong in the standard set (HEAD, branches and remote-tracking
94+
* branches) and it does not have a reflog.
9595
*
9696
* It will return GIT_EMODIFIED if the reference's value at the time
9797
* of updating does not match the one passed through `current_value`
@@ -103,11 +103,10 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
103103
* @param target The target of the reference
104104
* @param force Overwrite existing references
105105
* @param current_value The expected value of the reference when updating
106-
* @param signature The identity that will used to populate the reflog entry
107106
* @param log_message The one line long message to be appended to the reflog
108107
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC, GIT_EMODIFIED or an error code
109108
*/
110-
GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const git_signature *signature, const char *log_message);
109+
GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const char *log_message);
111110

112111
/**
113112
* Create a new symbolic reference.
@@ -131,20 +130,19 @@ GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_
131130
* This function will return an error if a reference already exists with the
132131
* given name unless `force` is true, in which case it will be overwritten.
133132
*
134-
* The signature and message for the reflog will be ignored if the
135-
* reference does not belong in the standard set (HEAD, branches and
136-
* remote-tracking branches) and it does not have a reflog.
133+
* The message for the reflog will be ignored if the reference does
134+
* not belong in the standard set (HEAD, branches and remote-tracking
135+
* branches) and it does not have a reflog.
137136
*
138137
* @param out Pointer to the newly created reference
139138
* @param repo Repository where that reference will live
140139
* @param name The name of the reference
141140
* @param target The target of the reference
142141
* @param force Overwrite existing references
143-
* @param signature The identity that will used to populate the reflog entry
144142
* @param log_message The one line long message to be appended to the reflog
145143
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
146144
*/
147-
GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const git_signature *signature, const char *log_message);
145+
GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *log_message);
148146

149147
/**
150148
* Create a new direct reference.
@@ -169,20 +167,19 @@ GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repositor
169167
* This function will return an error if a reference already exists with the
170168
* given name unless `force` is true, in which case it will be overwritten.
171169
*
172-
* The signature and message for the reflog will be ignored if the
173-
* reference does not belong in the standard set (HEAD, branches and
174-
* remote-tracking branches) and and it does not have a reflog.
170+
* The message for the reflog will be ignored if the reference does
171+
* not belong in the standard set (HEAD, branches and remote-tracking
172+
* branches) and and it does not have a reflog.
175173
*
176174
* @param out Pointer to the newly created reference
177175
* @param repo Repository where that reference will live
178176
* @param name The name of the reference
179177
* @param id The object id pointed to by the reference.
180178
* @param force Overwrite existing references
181-
* @param signature The identity that will used to populate the reflog entry
182179
* @param log_message The one line long message to be appended to the reflog
183180
* @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
184181
*/
185-
GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message);
182+
GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const char *log_message);
186183

187184
/**
188185
* Conditionally create new direct reference
@@ -207,9 +204,9 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
207204
* This function will return an error if a reference already exists with the
208205
* given name unless `force` is true, in which case it will be overwritten.
209206
*
210-
* The signature and message for the reflog will be ignored if the
211-
* reference does not belong in the standard set (HEAD, branches and
212-
* remote-tracking branches) and and it does not have a reflog.
207+
* The message for the reflog will be ignored if the reference does
208+
* not belong in the standard set (HEAD, branches and remote-tracking
209+
* branches) and and it does not have a reflog.
213210
*
214211
* It will return GIT_EMODIFIED if the reference's value at the time
215212
* of updating does not match the one passed through `current_id`
@@ -221,12 +218,11 @@ GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo,
221218
* @param id The object id pointed to by the reference.
222219
* @param force Overwrite existing references
223220
* @param current_id The expected value of the reference at the time of update
224-
* @param signature The identity that will used to populate the reflog entry
225221
* @param log_message The one line long message to be appended to the reflog
226222
* @return 0 on success, GIT_EMODIFIED if the value of the reference
227223
* has changed, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
228224
*/
229-
GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const git_signature *signature, const char *log_message);
225+
GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const char *log_message);
230226

231227
/**
232228
* Get the OID pointed to by a direct reference.
@@ -320,22 +316,20 @@ GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
320316
* The target name will be checked for validity.
321317
* See `git_reference_symbolic_create()` for rules about valid names.
322318
*
323-
* The signature and message for the reflog will be ignored if the
324-
* reference does not belong in the standard set (HEAD, branches and
325-
* remote-tracking branches) and and it does not have a reflog.
319+
* The message for the reflog will be ignored if the reference does
320+
* not belong in the standard set (HEAD, branches and remote-tracking
321+
* branches) and and it does not have a reflog.
326322
*
327323
* @param out Pointer to the newly created reference
328324
* @param ref The reference
329325
* @param target The new target for the reference
330-
* @param signature The identity that will used to populate the reflog entry
331326
* @param log_message The one line long message to be appended to the reflog
332327
* @return 0 on success, GIT_EINVALIDSPEC or an error code
333328
*/
334329
GIT_EXTERN(int) git_reference_symbolic_set_target(
335330
git_reference **out,
336331
git_reference *ref,
337332
const char *target,
338-
const git_signature *signature,
339333
const char *log_message);
340334

341335
/**
@@ -348,7 +342,6 @@ GIT_EXTERN(int) git_reference_symbolic_set_target(
348342
* @param out Pointer to the newly created reference
349343
* @param ref The reference
350344
* @param id The new target OID for the reference
351-
* @param signature The identity that will used to populate the reflog entry
352345
* @param log_message The one line long message to be appended to the reflog
353346
* @return 0 on success, GIT_EMODIFIED if the value of the reference
354347
* has changed since it was read, or an error code
@@ -357,7 +350,6 @@ GIT_EXTERN(int) git_reference_set_target(
357350
git_reference **out,
358351
git_reference *ref,
359352
const git_oid *id,
360-
const git_signature *signature,
361353
const char *log_message);
362354

363355
/**
@@ -379,7 +371,6 @@ GIT_EXTERN(int) git_reference_set_target(
379371
* @param ref The reference to rename
380372
* @param new_name The new name for the reference
381373
* @param force Overwrite an existing reference
382-
* @param signature The identity that will used to populate the reflog entry
383374
* @param log_message The one line long message to be appended to the reflog
384375
* @return 0 on success, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
385376
*
@@ -389,7 +380,6 @@ GIT_EXTERN(int) git_reference_rename(
389380
git_reference *ref,
390381
const char *new_name,
391382
int force,
392-
const git_signature *signature,
393383
const char *log_message);
394384

395385
/**

include/git2/remote.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,13 @@ GIT_EXTERN(void) git_remote_free(git_remote *remote);
376376
* Update the tips to the new state
377377
*
378378
* @param remote the remote to update
379-
* @param signature The identity to use when updating reflogs
380379
* @param reflog_message The message to insert into the reflogs. If NULL, the
381380
* default is "fetch <name>", where <name> is the name of
382381
* the remote (or its url, for in-memory remotes).
383382
* @return 0 or an error code
384383
*/
385384
GIT_EXTERN(int) git_remote_update_tips(
386385
git_remote *remote,
387-
const git_signature *signature,
388386
const char *reflog_message);
389387

390388
/**
@@ -404,15 +402,13 @@ GIT_EXTERN(int) git_remote_prune(git_remote *remote);
404402
* @param remote the remote to fetch from
405403
* @param refspecs the refspecs to use for this fetch. Pass NULL or an
406404
* empty array to use the base refspecs.
407-
* @param signature The identity to use when updating reflogs
408405
* @param reflog_message The message to insert into the reflogs. If NULL, the
409406
* default is "fetch"
410407
* @return 0 or an error code
411408
*/
412409
GIT_EXTERN(int) git_remote_fetch(
413410
git_remote *remote,
414411
const git_strarray *refspecs,
415-
const git_signature *signature,
416412
const char *reflog_message);
417413

418414
/**
@@ -424,13 +420,12 @@ GIT_EXTERN(int) git_remote_fetch(
424420
* @param refspecs the refspecs to use for pushing. If none are
425421
* passed, the configured refspecs will be used
426422
* @param opts the options
427-
* @param signature signature to use for the reflog of updated references
428423
* @param reflog_message message to use for the reflog of upated references
429424
*/
430425
GIT_EXTERN(int) git_remote_push(git_remote *remote,
431426
const git_strarray *refspecs,
432427
const git_push_options *opts,
433-
const git_signature *signature, const char *reflog_message);
428+
const char *reflog_message);
434429

435430
/**
436431
* Get a list of the configured remotes for a repo

include/git2/repository.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,14 +603,12 @@ GIT_EXTERN(int) git_repository_hashfile(
603603
*
604604
* @param repo Repository pointer
605605
* @param refname Canonical name of the reference the HEAD should point at
606-
* @param signature The identity that will used to populate the reflog entry
607606
* @param log_message The one line long message to be appended to the reflog
608607
* @return 0 on success, or an error code
609608
*/
610609
GIT_EXTERN(int) git_repository_set_head(
611610
git_repository* repo,
612611
const char* refname,
613-
const git_signature *signature,
614612
const char *log_message);
615613

616614
/**
@@ -627,14 +625,12 @@ GIT_EXTERN(int) git_repository_set_head(
627625
*
628626
* @param repo Repository pointer
629627
* @param commitish Object id of the Commit the HEAD should point to
630-
* @param signature The identity that will used to populate the reflog entry
631628
* @param log_message The one line long message to be appended to the reflog
632629
* @return 0 on success, or an error code
633630
*/
634631
GIT_EXTERN(int) git_repository_set_head_detached(
635632
git_repository* repo,
636633
const git_oid* commitish,
637-
const git_signature *signature,
638634
const char *log_message);
639635

640636
/**
@@ -651,14 +647,12 @@ GIT_EXTERN(int) git_repository_set_head_detached(
651647
* Otherwise, the HEAD will be detached and point to the peeled Commit.
652648
*
653649
* @param repo Repository pointer
654-
* @param signature The identity that will used to populate the reflog entry
655650
* @param reflog_message The one line long message to be appended to the reflog
656651
* @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing
657652
* branch or an error code
658653
*/
659654
GIT_EXTERN(int) git_repository_detach_head(
660655
git_repository* repo,
661-
const git_signature *signature,
662656
const char *reflog_message);
663657

664658
/**
@@ -720,6 +714,31 @@ GIT_EXTERN(const char *) git_repository_get_namespace(git_repository *repo);
720714
*/
721715
GIT_EXTERN(int) git_repository_is_shallow(git_repository *repo);
722716

717+
/**
718+
* Retrieve the configured identity to use for reflogs
719+
*
720+
* The memory is owned by the repository and must not be freed by the
721+
* user.
722+
*
723+
* @param name where to store the pointer to the name
724+
* @param email where to store the pointer to the email
725+
* @param repo the repository
726+
*/
727+
GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, const git_repository *repo);
728+
729+
/**
730+
* Set the identity to be used for writing reflogs
731+
*
732+
* If both are set, this name and email will be used to write to the
733+
* reflog. Pass NULL to unset. When unset, the identity will be taken
734+
* from the repository's configuration.
735+
*
736+
* @param repo the repository to configure
737+
* @param name the name to use for the reflog entries
738+
* @param name the email to use for the reflog entries
739+
*/
740+
GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email);
741+
723742
/** @} */
724743
GIT_END_DECL
725744
#endif

0 commit comments

Comments
 (0)