📄 writingchangelogs.txt
字号:
This is an essay by Jim Blandy <jimb@redhat.com> on maintainingChangeLog entries. Although Subversion generates its ChangeLogs from cvs log data,instead of keeping independent ChangeLog files, most of the advicebelow is as applicable to cvs log messages as to ChangeLog entries.Maintaining the ChangeLog=========================A project's ChangeLog provides a history of development. Comments inthe code should explain the code's present state, but ChangeLogentries should explain how and when it got that way. The ChangeLogmust show:* the relative order in which changes entered the code, so you can see the context in which a change was made, and* the date at which the change entered the code, so you can relate the change to outside events, like branch cuts, code freezes, and releases.In the case of CVS, these refer to when the change was committed,because that is the context in which other developers will see thechange.Every change to the sources should have a ChangeLog entry. The valueof the ChangeLog becomes much less if developers cannot rely on itscompleteness. Even if you've only changed comments, write an entrythat says, "Doc fix." The only changes you needn't log are smallchanges that have no effect on the source, like formatting tweaks.In order to keep the ChangeLog a manageable size, at the beginning ofeach year, the ChangeLog should be renamed to "ChangeLog-YYYY", and afresh ChangeLog file started.How to write ChangeLog entries------------------------------ChangeLog entries should be full sentences, not sentence fragments.Fragments are more often ambiguous, and it takes only a few moreseconds to write out what you mean. Fragments like `New file' or `Newfunction' are acceptable, because they are standard idioms, and allfurther details should appear in the source code.The log entry should mention every file changed. It should alsomention by name every function, variable, macro, makefile target,grammar rule, etc. you changed. However, there are common-senseexceptions:* If you have made a change which requires trivial changes throughout the rest of the program (e.g., renaming a variable), you needn't name all the functions affected.* If you have rewritten a file completely, the reader understands that everything in it has changed, so your log entry may simply give the file name, and say "Rewritten".In general, there is a tension between making entries easy to find bysearching for identifiers, and wasting time or producing unreadableentries by being exhaustive. Use your best judgement --- and beconsiderate of your fellow developers.Group ChangeLog entries into "paragraphs", separated by blank lines.Each paragraph should be a set of changes that accomplish a singlegoal. Independent changes should be in separate paragraphs. Forexample: 1999-03-24 Stan Shebs <shebs@andros.cygnus.com> * configure.host (mips-dec-mach3*): Use mipsm3, not mach3. Attempt to sort out SCO-related configs. * configure.host (i[3456]86-*-sysv4.2*): Use this instead of i[3456]86-*-sysv4.2MP and i[3456]86-*-sysv4.2uw2*. (i[3456]86-*-sysv5*): Recognize this. * configure.tgt (i[3456]86-*-sco3.2v5*, i[3456]86-*-sco3.2v4*): Recognize these.Even though this entry describes two changes to `configure.host',they're in separate paragraphs, because they're unrelated changes.The second change to `configure.host' is grouped with another changeto `configure.tgt', because they both serve the same purpose.Also note that the author has kindly recorded his overall motivationfor the paragraph, so we don't have to glean it from the individualchanges.The header line for the ChangeLog entry should have the format shownabove. If you are using an old version of Emacs (before 20.1) thatgenerates entries with more verbose dates, consider using`etc/add-log.el', from the GDB source tree. If you are using vi,consider using the macro in `etc/add-log.vi'. Both of these generateentries in the newer, terser format.One should never need the ChangeLog to understand the current code.If you find yourself writing a significant explanation in theChangeLog, you should consider carefully whether your text doesn'tactually belong in a comment, alongside the code it explains. Here'san example of doing it right: 1999-02-23 Tom Tromey <tromey@cygnus.com> * cplus-dem.c (consume_count): If `count' is unreasonable, return 0 and don't advance input pointer.And then, in `consume_count' in `cplus-dem.c': while (isdigit ((unsigned char)**type)) { count *= 10; count += **type - '0'; /* A sanity check. Otherwise a symbol like `_Utf390_1__1_9223372036854775807__9223372036854775' can cause this function to return a negative value. In this case we just consume until the end of the string. */ if (count > strlen (*type)) { *type = save; return 0; }This is why a new function, for example, needs only a log entry saying"New Function" --- all the details should be in the source.Avoid the temptation to abbreviate filenames or function names, as inthis example (mostly real, but slightly exaggerated): * gdbarch.[ch] (gdbarch_tdep, gdbarch_bfd_arch_info, gdbarch_byte_order, {set,}gdbarch_long_bit, {set,}gdbarch_long_long_bit, {set,}gdbarch_ptr_bit): Corresponding functions.This makes it difficult for others to search the ChangeLog for changesto the file or function they are interested in. For example, if yousearched for `set_gdbarch_long_bit', you would not find the aboveentry, because the writer used CSH-style globbing to abbreviate thelist of functions. If you gave up, and made a second pass looking forgdbarch.c, you wouldn't find that either. Consider your poor readers,and write out the names.ChangeLogs and the CVS log--------------------------CVS maintains its own logs, which you can access using the `cvs log'command. This duplicates the information present in the ChangeLog,but binds each entry to a specific revision, which can be helpful attimes.However, the CVS log is no substitute for the ChangeLog files.* CVS provides no easy way to see the changes made to a set of files in chronological order. They're sorted first by filename, not by date.* Unless you put full ChangeLog paragraphs in your CVS log entries, it's difficult to pull together changes that cross several files.* CVS doesn't segregate log entries for branches from those for the trunk in any useful way.In some circumstances, though, the CVS log is more useful than theChangeLog, so we maintain both. When you commit a change, you shouldprovide appropriate text in both the ChangeLog and the CVS log.It is not necessary to provide CVS log entries for ChangeLog changes,since it would simply duplicate the contents of the file itself. Writing ChangeLog entries for merges------------------------------------Revision management software like CVS can introduce some confusionwhen writing ChangeLog entries. For example, one might write a changeon a branch, and then merge it into the trunk months later. In thatcase, what position and date should the developer use for theChangeLog entry --- that of the original change, or the date of themerge?The principles described at the top need to hold for both the originalchange and the merged change. That is:* On the branch (or trunk) where the change is first committed, the ChangeLog entry should be written as normal, inserted at the top of the ChangeLog and reflecting the date the change was committed to the branch (or trunk).* When the change is then merged (to the trunk, or to another branch), the ChangeLog entry should have the following form: 1999-03-26 Jim Blandy <jimb@zwingli.cygnus.com> Merged change from foobar_20010401_branch: 1999-03-16 Keith Seitz <keiths@cygnus.com> [...] In this case, "Jim Blandy" is doing the merge on March 26; "Keith Seitz" is the original author of the change, who committed it to `foobar_20010401_branch' on March 16. As shown here, the entry for the merge should be like any other change --- inserted at the top of the ChangeLog, and stamped with the date the merge was committed. It should indicate the origin of the change, and provide the full text of the original entry, indented to avoid being confused with a true log entry. Remember that people looking for the merge will search for the original changelog text, so it's important to preserve it unchanged. For the merge entry, we use the merge date, and not the original date, because this is when the change appears on the trunk or branch this ChangeLog documents. Its impact on these sources is independent of when or where it originated.This approach preserves the structure of the ChangeLog (entries appearin order, and dates reflect when they appeared), but also providesfull information about changes' origins.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -