git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] [Outreachy] ident: introduce set_fallback_ident() function

From
SDSlavica Djukic <slavicadj.ip2018@gmail.com>
Date
Nov 1, 2018, 12:00 UTC
Message-ID
<20181101120029.13992-1-slawica92@hotmail.com>
In-Reply-To
<20181101115546.13516-1-slawica92@hotmail.com>

Usually, when creating a commit, ident is needed to record the author and commiter. But, when there is commit not intended to published, e.g. when stashing changes, valid ident is not necessary. To allow creating commits in such scenario, let's introduce helper function "set_fallback_ident(), which will pre-load the ident.

In following commit, set_fallback_ident() function will be called in stash.
Signed-off-by: Slavica Djukic <slawica92@hotmail.com>
---
 cache.h |  1 +
 ident.c | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
diff --git a/cache.h b/cache.h
index 681307f716..6b5b559a05 100644
--- a/cache.h
+++ b/cache.h
@@ -1470,6 +1470,7 @@ extern const char *git_sequence_editor(void);
 extern const char *git_pager(int stdout_is_tty);
 extern int is_terminal_dumb(void);
 extern int git_ident_config(const char *, const char *, void *);
+void set_fallback_ident(const char *name, const char *email);
 extern void reset_ident_date(void);
 
 struct ident_split {
diff --git a/ident.c b/ident.c
index 33bcf40644..410bd495e9 100644
--- a/ident.c
+++ b/ident.c
@@ -505,6 +505,23 @@ int git_ident_config(const char *var, const char *value, void *data)
 	return 0;
 }
 
+void set_fallback_ident(const char *name, const char *email)
+{
+	if (!git_default_name.len) {
+		strbuf_addstr(&git_default_name, name);
+		committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
+		author_ident_explicitly_given |= IDENT_NAME_GIVEN;
+		ident_config_given |= IDENT_NAME_GIVEN;
+	}
+
+	if (!git_default_email.len) {
+		strbuf_addstr(&git_default_email, email);
+		committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+		author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
+		ident_config_given |= IDENT_MAIL_GIVEN;
+	}
+}
+
 static int buf_cmp(const char *a_begin, const char *a_end,
 		   const char *b_begin, const char *b_end)
 {
-- 
2.19.1.windows.1
Previous: Junio C HamanoNext: Junio C Hamano
Message 23 of 41 in “[Outreachy] t3903-stash: test without configured user name”
  1. 1/3 [Outreachy] t3903-stash: test without configured user nameSlavica, Oct 23, 2018
  2. Christian CouderOct 23, 2018
  3. SlavicaOct 24, 2018
  4. Junio C HamanoOct 25, 2018
  5. Eric SunshineOct 23, 2018
  6. Junio C HamanoOct 24, 2018
  7. Johannes SchindelinOct 24, 2018
  8. Junio C HamanoOct 24, 2018
  9. Johannes SchindelinOct 24, 2018
  10. Junio C HamanoOct 25, 2018
  11. 1/3 [Outreachy] t3903-stash: test without configured user nameSlavica Djukic, Oct 24, 2018
  12. 1/3 [Outreachy] t3903-stash: test without configured user nameSlavica Djukic, Oct 24, 2018
  13. Eric SunshineOct 24, 2018
  14. Junio C HamanoOct 25, 2018
  15. 1/3 [Outreachy] t3903-stash: test without configured user nameSlavica Djukic, Oct 25, 2018
  16. 1/3 [Outreachy] t3903-stash: test without configured user nameSlavica Djukic, Oct 25, 2018
  17. Junio C HamanoOct 26, 2018
  18. Slavica DjukicOct 30, 2018
  19. 0/3 [Outreachy] make stash work if user.name and user.email are not configuredSlavica Djukic, Nov 1, 2018
  20. 1/3 [Outreachy] t3903-stash: test without configured user.name and user.emailSlavica Djukic, Nov 1, 2018
  21. Christian CouderNov 1, 2018
  22. 3/3 stash: tolerate missing user identityJunio C Hamano, Nov 2, 2018
  23. 2/3 [Outreachy] ident: introduce set_fallback_ident() functionSlavica Djukic, Nov 1, 2018
  24. Junio C HamanoNov 2, 2018
  25. Junio C HamanoNov 2, 2018
  26. Junio C HamanoNov 2, 2018
  27. 3/3 [Outreachy] stash: use set_fallback_ident() functionSlavica Djukic, Nov 1, 2018
  28. 0/2 [Outreachy] make stash work if user.name and user.email are not configuredSlavica Djukic, Nov 14, 2018
  29. 1/2 [Outreachy] t3903-stash: test without configured user.name and user.emailSlavica Djukic, Nov 14, 2018
  30. Johannes SchindelinNov 15, 2018
  31. Junio C HamanoNov 16, 2018
  32. Junio C HamanoNov 16, 2018
  33. Junio C HamanoNov 16, 2018
  34. Slavica DjukicNov 16, 2018
  35. Junio C HamanoNov 16, 2018
  36. Slavica DjukicNov 17, 2018
  37. Junio C HamanoNov 18, 2018
  38. 2/2 [Outreachy] stash: tolerate missing user identitySlavica Djukic, Nov 14, 2018
  39. Junio C HamanoNov 16, 2018
  40. 0/1 make stash work if user.name and user.email are not configuredSlavica Djukic, Nov 18, 2018
  41. 1/1 stash: tolerate missing user identitySlavica Djukic, Nov 18, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.