another undo patch: a feature request and implementation, should it be of interest

Joel K. Pettersson joelkpettersson at gmail.com
Fri Mar 27 17:13:28 PDT 2009


>    The 0-9 handling needs some help.  A lot of help.  It's just too messy.
I'm not too surprised.

>    I think it needs to be handled either by giving it its own option
>    (instead of trying to parse 0-9 in getopt), or by integrating the index
>    selection with -t by detecting that the TID values are not in 0x form.
I guess trying to use immediate number options with multiple
characters is simply not possible to get clean as opposed to merely
working when getopt is used for options. While slightly more verbose
in usage, the code for using a standard option with argument is rather
much nicer, yes.

>    My preference is to simply make -t accept non 0x form transaction ids
>    as indices instead of transaction ids.
>
>                                        -Matt
Should I send such a patch? Alternatively, if you copy the main()
function from before the feature patch, move the initiation of the
"flags" variable to before the option-reading loop, then such code can
simply be inserted for case 't'.

With a simple test for index numbers, though it may be a bit
quick-and-dirty, here's such code:
               case 't':
                       if (ts1.tid == 0 &&
                           !(flags & UNDO_FLAG_SETTID1)) {
                               ts1.tid = parse_delta_time(optarg);
                               if (optarg[0] >= '0' && optarg[0] <= '9' &&
                                   optarg[1] != 'x')
                                       flags |= UNDO_FLAG_SETTID1;
                       } else if (ts2.tid == 0 &&
                                  !(flags & UNDO_FLAG_SETTID2)) {
                               ts2.tid = parse_delta_time(optarg);
                               if (optarg[0] >= '0' && optarg[0] <= '9' &&
                                   optarg[1] != 'x')
                                       flags |= UNDO_FLAG_SETTID2;
                       } else
                               usage();
                       break;

Where the code for detecting non-TIDs may be replaced, if needed.

--
 -  Joel K. Pettersson





More information about the Submit mailing list