synchronize history patches with busybox git
[busybox-power] / debian / patches / git-backports / 0001-lineedit-fix-atomic-replace-of-history-file-hush-fix.patch
1 The following commit has been modified to fit BusyBox 1.19.2 instead of BusyBox git
2 --Dennis Groenen <tj.groenen@gmail.com> - 2011-09-10
3
4 From 4840ae8a06298e987374fa3cc6d7e4969fd19344 Mon Sep 17 00:00:00 2001
5 From: Denys Vlasenko <vda.linux@googlemail.com>
6 Date: Sun, 4 Sep 2011 15:28:03 +0200
7 Subject: [PATCH 1/3] lineedit: fix atomic replace of history file; hush: fix
8  $HISTFILE handling
9
10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
11 ---
12
13 --- a/libbb/lineedit.c
14 +++ b/libbb/lineedit.c
15 @@ -1475,7 +1475,7 @@ static void remember_in_history(char *st
16         /* i <= state->max_history */
17         state->cur_history = i;
18         state->cnt_history = i;
19 -# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
20 +# if ENABLE_FEATURE_EDITING_SAVEHISTORY
21         if ((state->flags & SAVE_HISTORY) && state->hist_file)
22                 save_history(str);
23  # endif
24 --- a/shell/ash.c
25 +++ b/shell/ash.c
26 @@ -13194,7 +13194,7 @@ int ash_main(int argc UNUSED_PARAM, char
27         }
28  
29         if (sflag || minusc == NULL) {
30 -#if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
31 +#if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
32                 if (iflag) {
33                         const char *hp = lookupvar("HISTFILE");
34                         if (hp)
35 --- a/shell/hush.c
36 +++ b/shell/hush.c
37 @@ -7816,27 +7816,7 @@ int hush_main(int argc, char **argv)
38          */
39  
40  #if ENABLE_FEATURE_EDITING
41 -       G.line_input_state = new_line_input_t(FOR_SHELL);
42 -# if MAX_HISTORY > 0 && ENABLE_HUSH_SAVEHISTORY
43 -       {
44 -               const char *hp = get_local_var_value("HISTFILE");
45 -               if (!hp) {
46 -                       hp = get_local_var_value("HOME");
47 -                       if (hp)
48 -                               hp = concat_path_file(hp, ".hush_history");
49 -               } else {
50 -                       hp = xstrdup(hp);
51 -               }
52 -               if (hp) {
53 -                       G.line_input_state->hist_file = hp;
54 -                       //set_local_var(xasprintf("HISTFILE=%s", ...));
55 -               }
56 -#  if ENABLE_FEATURE_SH_HISTFILESIZE
57 -               hp = get_local_var_value("HISTFILESIZE");
58 -               G.line_input_state->max_history = size_from_HISTFILESIZE(hp);
59 -#  endif
60 -       }
61 -# endif
62 +       G.line_input_state = new_line_input_t(FOR_SHELL & ~SAVE_HISTORY);
63  #endif
64  
65         /* Initialize some more globals to non-zero values */
66 @@ -8108,6 +8088,28 @@ int hush_main(int argc, char **argv)
67                 /* -1 is special - makes xfuncs longjmp, not exit
68                  * (we reset die_sleep = 0 whereever we [v]fork) */
69                 enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */
70 +
71 +# if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0
72 +               {
73 +                       const char *hp = get_local_var_value("HISTFILE");
74 +                       if (!hp) {
75 +                               hp = get_local_var_value("HOME");
76 +                               if (hp)
77 +                                       hp = concat_path_file(hp, ".hush_history");
78 +                       } else {
79 +                               hp = xstrdup(hp);
80 +                       }
81 +                       if (hp) {
82 +                               G.line_input_state->hist_file = hp;
83 +                               G.line_input_state->flags |= SAVE_HISTORY;
84 +                               //set_local_var(xasprintf("HISTFILE=%s", ...));
85 +                       }
86 +#  if ENABLE_FEATURE_SH_HISTFILESIZE
87 +                       hp = get_local_var_value("HISTFILESIZE");
88 +                       G.line_input_state->max_history = size_from_HISTFILESIZE(hp);
89 +#  endif
90 +               }
91 +# endif
92         } else {
93                 install_special_sighandlers();
94         }